183 lines · plain
1; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan 2>&1 | FileCheck %s "--check-prefixes=CHECK,INLINE"2; RUN: opt < %s -msan-check-access-address=0 -msan-poison-stack-with-call=1 -S -passes=msan 2>&1 | FileCheck %s "--check-prefixes=CHECK,CALL"3; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S -passes=msan 2>&1 | FileCheck %s "--check-prefixes=CHECK,ORIGIN"4; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=2 -S -passes=msan 2>&1 | FileCheck %s "--check-prefixes=CHECK,ORIGIN"5; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=2 -msan-print-stack-names=false -S -passes=msan 2>&1 | FileCheck %s "--check-prefixes=CHECK,ORIGIN-LEAN"6; RUN: opt < %s -S -passes="msan<kernel>" 2>&1 | FileCheck %s "--check-prefixes=CHECK,KMSAN"7; RUN: opt < %s -msan-kernel=1 -S -passes=msan 2>&1 | FileCheck %s "--check-prefixes=CHECK,KMSAN"8 9target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"10target triple = "x86_64-unknown-linux-gnu"11 12; ORIGIN: [[IDPTR:@[0-9]+]] = private global i32 013; ORIGIN-LEAN: [[IDPTR:@[0-9]+]] = private global i32 014; ORIGIN: [[DESCR:@[0-9]+]] = private constant [9 x i8] c"unique_x\00"15 16define void @static() sanitize_memory {17entry:18 %unique_x = alloca i32, align 419 ret void20}21 22; CHECK-LABEL: define void @static(23; INLINE: call void @llvm.memset.p0.i64(ptr align 4 {{.*}}, i8 -1, i64 4, i1 false)24; CALL: call void @__msan_poison_stack(ptr {{.*}}, i64 4)25; ORIGIN: call void @__msan_set_alloca_origin_with_descr(ptr %unique_x, i64 4, ptr [[IDPTR]], ptr [[DESCR]])26; ORIGIN-LEAN: call void @__msan_set_alloca_origin_no_descr(ptr %unique_x, i64 4, ptr [[IDPTR]])27; KMSAN: call void @__msan_poison_alloca(ptr {{.*}}, i64 4,28; CHECK: ret void29 30 31define void @dynamic() sanitize_memory {32entry:33 br label %l34l:35 %x = alloca i32, align 436 ret void37}38 39; CHECK-LABEL: define void @dynamic(40; INLINE: call void @llvm.memset.p0.i64(ptr align 4 {{.*}}, i8 -1, i64 4, i1 false)41; CALL: call void @__msan_poison_stack(ptr {{.*}}, i64 4)42; ORIGIN: call void @__msan_set_alloca_origin_with_descr(ptr {{.*}}, i64 4,43; ORIGIN-LEAN: call void @__msan_set_alloca_origin_no_descr(ptr {{.*}}, i64 4,44; KMSAN: call void @__msan_poison_alloca(ptr {{.*}}, i64 4,45; CHECK: ret void46 47define void @array() sanitize_memory {48entry:49 %x = alloca i32, i64 5, align 450 ret void51}52 53; CHECK-LABEL: define void @array(54; INLINE: call void @llvm.memset.p0.i64(ptr align 4 {{.*}}, i8 -1, i64 20, i1 false)55; CALL: call void @__msan_poison_stack(ptr {{.*}}, i64 20)56; ORIGIN: call void @__msan_set_alloca_origin_with_descr(ptr {{.*}}, i64 20,57; ORIGIN-LEAN: call void @__msan_set_alloca_origin_no_descr(ptr {{.*}}, i64 20,58; KMSAN: call void @__msan_poison_alloca(ptr {{.*}}, i64 20,59; CHECK: ret void60 61define void @array32() sanitize_memory {62entry:63 %x = alloca i32, i32 5, align 464 ret void65}66 67; CHECK-LABEL: define void @array32(68; INLINE: call void @llvm.memset.p0.i64(ptr align 4 {{.*}}, i8 -1, i64 20, i1 false)69; CALL: call void @__msan_poison_stack(ptr {{.*}}, i64 20)70; ORIGIN: call void @__msan_set_alloca_origin_with_descr(ptr {{.*}}, i64 20,71; ORIGIN-LEAN: call void @__msan_set_alloca_origin_no_descr(ptr {{.*}}, i64 20,72; KMSAN: call void @__msan_poison_alloca(ptr {{.*}}, i64 20,73; CHECK: ret void74 75define void @array_non_const(i64 %cnt) sanitize_memory {76entry:77 %x = alloca i32, i64 %cnt, align 478 ret void79}80 81; CHECK-LABEL: define void @array_non_const(82; CHECK: %[[A:.*]] = mul i64 4, %cnt83; INLINE: call void @llvm.memset.p0.i64(ptr align 4 {{.*}}, i8 -1, i64 %[[A]], i1 false)84; CALL: call void @__msan_poison_stack(ptr {{.*}}, i64 %[[A]])85; ORIGIN: call void @__msan_set_alloca_origin_with_descr(ptr {{.*}}, i64 %[[A]],86; ORIGIN-LEAN: call void @__msan_set_alloca_origin_no_descr(ptr {{.*}}, i64 %[[A]],87; KMSAN: call void @__msan_poison_alloca(ptr {{.*}}, i64 %[[A]],88; CHECK: ret void89 90define void @array_non_const32(i32 %cnt) sanitize_memory {91entry:92 %x = alloca i32, i32 %cnt, align 493 ret void94}95 96; CHECK-LABEL: define void @array_non_const32(97; CHECK: %[[Z:.*]] = zext i32 %cnt to i6498; CHECK: %[[A:.*]] = mul i64 4, %[[Z]]99; INLINE: call void @llvm.memset.p0.i64(ptr align 4 {{.*}}, i8 -1, i64 %[[A]], i1 false)100; CALL: call void @__msan_poison_stack(ptr {{.*}}, i64 %[[A]])101; ORIGIN: call void @__msan_set_alloca_origin_with_descr(ptr {{.*}}, i64 %[[A]],102; ORIGIN-LEAN: call void @__msan_set_alloca_origin_no_descr(ptr {{.*}}, i64 %[[A]],103; KMSAN: call void @__msan_poison_alloca(ptr {{.*}}, i64 %[[A]],104; CHECK: ret void105 106; Check that the local is unpoisoned in the absence of sanitize_memory107define void @unpoison_local() {108entry:109 %x = alloca i32, i64 5, align 4110 ret void111}112 113; CHECK-LABEL: define void @unpoison_local(114; INLINE: call void @llvm.memset.p0.i64(ptr align 4 {{.*}}, i8 0, i64 20, i1 false)115; CALL: call void @llvm.memset.p0.i64(ptr align 4 {{.*}}, i8 0, i64 20, i1 false)116; ORIGIN-NOT: call void @__msan_set_alloca_origin_with_descr(ptr {{.*}}, i64 20,117; ORIGIN-LEAN-NOT: call void @__msan_set_alloca_origin_no_descr(ptr {{.*}}, i64 20,118; KMSAN: call void @__msan_unpoison_alloca(ptr {{.*}}, i64 20)119; CHECK: ret void120 121; Check that every llvm.lifetime.start() causes poisoning of locals.122define void @lifetime_start() sanitize_memory {123entry:124 %x = alloca i32, align 4125 br label %another_bb126 127another_bb:128 call void @llvm.lifetime.start.p0(ptr nonnull %x)129 store i32 7, ptr %x130 call void @llvm.lifetime.end.p0(ptr nonnull %x)131 call void @llvm.lifetime.start.p0(ptr nonnull %x)132 store i32 8, ptr %x133 call void @llvm.lifetime.end.p0(ptr nonnull %x)134 ret void135}136 137; CHECK-LABEL: define void @lifetime_start(138; CHECK-LABEL: entry:139; CHECK: %x = alloca i32140; CHECK-LABEL: another_bb:141 142; CHECK: call void @llvm.lifetime.start143; INLINE: call void @llvm.memset.p0.i64(ptr align 4 {{.*}}, i8 -1, i64 4, i1 false)144; CALL: call void @__msan_poison_stack(ptr {{.*}}, i64 4)145; ORIGIN: call void @__msan_set_alloca_origin_with_descr(ptr {{.*}}, i64 4,146; ORIGIN-LEAN: call void @__msan_set_alloca_origin_no_descr(ptr {{.*}}, i64 4,147; KMSAN: call void @__msan_poison_alloca(ptr {{.*}}, i64 4,148 149; CHECK: call void @llvm.lifetime.start150; INLINE: call void @llvm.memset.p0.i64(ptr align 4 {{.*}}, i8 -1, i64 4, i1 false)151; CALL: call void @__msan_poison_stack(ptr {{.*}}, i64 4)152; ORIGIN: call void @__msan_set_alloca_origin_with_descr(ptr {{.*}}, i64 4,153; ORIGIN-LEAN: call void @__msan_set_alloca_origin_no_descr(ptr {{.*}}, i64 4,154; KMSAN: call void @__msan_poison_alloca(ptr {{.*}}, i64 4,155; CHECK: ret void156 157; Make sure variable-length arrays are handled correctly.158define void @lifetime_start_var(i64 %cnt) sanitize_memory {159entry:160 %x = alloca i32, i64 %cnt, align 4161 call void @llvm.lifetime.start.p0(ptr nonnull %x)162 call void @llvm.lifetime.end.p0(ptr nonnull %x)163 call void @llvm.lifetime.start.p0(ptr nonnull %x)164 call void @llvm.lifetime.end.p0(ptr nonnull %x)165 ret void166}167 168; CHECK-LABEL: define void @lifetime_start_var(169; CHECK-LABEL: entry:170; CHECK: %x = alloca i32, i64 %cnt171; CHECK: call void @llvm.lifetime.start172; CHECK: %[[A:.*]] = mul i64 4, %cnt173; INLINE: call void @llvm.memset.p0.i64(ptr align 4 {{.*}}, i8 -1, i64 %[[A]], i1 false)174; CALL: call void @__msan_poison_stack(ptr {{.*}}, i64 %[[A]])175; ORIGIN: call void @__msan_set_alloca_origin_with_descr(ptr {{.*}}, i64 %[[A]],176; ORIGIN-LEAN: call void @__msan_set_alloca_origin_no_descr(ptr {{.*}}, i64 %[[A]],177; KMSAN: call void @__msan_poison_alloca(ptr {{.*}}, i64 %[[A]],178; CHECK: call void @llvm.lifetime.end179; CHECK: ret void180 181declare void @llvm.lifetime.start.p0(ptr nocapture)182declare void @llvm.lifetime.end.p0(ptr nocapture)183