1; RUN: opt < %s -msan-check-access-address=0 -S -passes='module(msan-module),function(msan)' 2>&1 | FileCheck -allow-deprecated-dag-overlap %s 2; RUN: opt < %s --passes='module(msan-module),function(msan)' -msan-check-access-address=0 -S | FileCheck -allow-deprecated-dag-overlap %s 3; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S -passes='module(msan-module),function(msan)' 2>&1 | \ 4; RUN: FileCheck -allow-deprecated-dag-overlap -check-prefixes=CHECK,CHECK-ORIGINS %s 5; RUN: opt < %s -passes='module(msan-module),function(msan)' -msan-check-access-address=0 -msan-track-origins=1 -S | \ 6; RUN: FileCheck -allow-deprecated-dag-overlap -check-prefixes=CHECK,CHECK-ORIGINS %s 7; RUN: opt < %s -passes='module(msan-module),function(msan)' -msan-instrumentation-with-call-threshold=0 -msan-track-origins=1 -S | \ 8; RUN: FileCheck -allow-deprecated-dag-overlap -check-prefixes=CHECK-CALLS %s 9 10target 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" 11target triple = "x86_64-unknown-linux-gnu" 12 13; CHECK: @llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @msan.module_ctor to i8*)] 14; CHECK: @llvm.global_ctors {{.*}} { i32 0, void ()* @msan.module_ctor, i8* null } 15 16; Check the presence and the linkage type of __msan_track_origins and 17; other interface symbols. 18; CHECK-NOT: @__msan_track_origins 19; CHECK-ORIGINS: @__msan_track_origins = weak_odr constant i32 1 20; CHECK-NOT: @__msan_keep_going = weak_odr constant i32 0 21; CHECK: @__msan_retval_tls = external thread_local(initialexec) global [{{.*}}] 22; CHECK: @__msan_retval_origin_tls = external thread_local(initialexec) global i32 23; CHECK: @__msan_param_tls = external thread_local(initialexec) global [{{.*}}] 24; CHECK: @__msan_param_origin_tls = external thread_local(initialexec) global [{{.*}}] 25; CHECK: @__msan_va_arg_tls = external thread_local(initialexec) global [{{.*}}] 26; CHECK: @__msan_va_arg_overflow_size_tls = external thread_local(initialexec) global i64 27 28 29; Check instrumentation of stores 30 31define void @Store(i32* nocapture %p, i32 %x) nounwind uwtable sanitize_memory { 32entry: 33 store i32 %x, i32* %p, align 4 34 ret void 35} 36 37; CHECK-LABEL: @Store 38; CHECK: load {{.*}} @__msan_param_tls 39; CHECK-ORIGINS: load {{.*}} @__msan_param_origin_tls 40; CHECK: store 41; CHECK-ORIGINS: icmp 42; CHECK-ORIGINS: br i1 43; CHECK-ORIGINS: {{^[0-9]+}}: 44; CHECK-ORIGINS: store 45; CHECK-ORIGINS: br label 46; CHECK-ORIGINS: {{^[0-9]+}}: 47; CHECK: store 48; CHECK: ret void 49 50 51; Check instrumentation of aligned stores 52; Shadow store has the same alignment as the original store; origin store 53; does not specify explicit alignment. 54 55define void @AlignedStore(i32* nocapture %p, i32 %x) nounwind uwtable sanitize_memory { 56entry: 57 store i32 %x, i32* %p, align 32 58 ret void 59} 60 61; CHECK-LABEL: @AlignedStore 62; CHECK: load {{.*}} @__msan_param_tls 63; CHECK-ORIGINS: load {{.*}} @__msan_param_origin_tls 64; CHECK: store {{.*}} align 32 65; CHECK-ORIGINS: icmp 66; CHECK-ORIGINS: br i1 67; CHECK-ORIGINS: {{^[0-9]+}}: 68; CHECK-ORIGINS: store {{.*}} align 32 69; CHECK-ORIGINS: br label 70; CHECK-ORIGINS: {{^[0-9]+}}: 71; CHECK: store {{.*}} align 32 72; CHECK: ret void 73 74 75; load followed by cmp: check that we load the shadow and call __msan_warning_with_origin. 76define void @LoadAndCmp(i32* nocapture %a) nounwind uwtable sanitize_memory { 77entry: 78 %0 = load i32, i32* %a, align 4 79 %tobool = icmp eq i32 %0, 0 80 br i1 %tobool, label %if.end, label %if.then 81 82if.then: ; preds = %entry 83 tail call void (...) @foo() nounwind 84 br label %if.end 85 86if.end: ; preds = %entry, %if.then 87 ret void 88} 89 90declare void @foo(...) 91 92; CHECK-LABEL: @LoadAndCmp 93; CHECK: %0 = load i32, 94; CHECK: = load 95; CHECK-ORIGINS: %[[ORIGIN:.*]] = load 96; CHECK: call void @__msan_warning_with_origin_noreturn(i32 97; CHECK-ORIGINS-SAME %[[ORIGIN]]) 98; CHECK-CONT: 99; CHECK-NEXT: unreachable 100; CHECK: br i1 %tobool 101; CHECK: ret void 102 103; Check that we store the shadow for the retval. 104define i32 @ReturnInt() nounwind uwtable readnone sanitize_memory { 105entry: 106 ret i32 123 107} 108 109; CHECK-LABEL: @ReturnInt 110; CHECK: store i32 0,{{.*}}__msan_retval_tls 111; CHECK: ret i32 112 113; Check that we get the shadow for the retval. 114define void @CopyRetVal(i32* nocapture %a) nounwind uwtable sanitize_memory { 115entry: 116 %call = tail call i32 @ReturnInt() nounwind 117 store i32 %call, i32* %a, align 4 118 ret void 119} 120 121; CHECK-LABEL: @CopyRetVal 122; CHECK: load{{.*}}__msan_retval_tls 123; CHECK: store 124; CHECK: store 125; CHECK: ret void 126 127 128; Check that we generate PHIs for shadow. 129define void @FuncWithPhi(i32* nocapture %a, i32* %b, i32* nocapture %c) nounwind uwtable sanitize_memory { 130entry: 131 %tobool = icmp eq i32* %b, null 132 br i1 %tobool, label %if.else, label %if.then 133 134 if.then: ; preds = %entry 135 %0 = load i32, i32* %b, align 4 136 br label %if.end 137 138 if.else: ; preds = %entry 139 %1 = load i32, i32* %c, align 4 140 br label %if.end 141 142 if.end: ; preds = %if.else, %if.then 143 %t.0 = phi i32 [ %0, %if.then ], [ %1, %if.else ] 144 store i32 %t.0, i32* %a, align 4 145 ret void 146} 147 148; CHECK-LABEL: @FuncWithPhi 149; CHECK: = phi 150; CHECK-NEXT: = phi 151; CHECK: store 152; CHECK: store 153; CHECK: ret void 154 155; Compute shadow for "x << 10" 156define void @ShlConst(i32* nocapture %x) nounwind uwtable sanitize_memory { 157entry: 158 %0 = load i32, i32* %x, align 4 159 %1 = shl i32 %0, 10 160 store i32 %1, i32* %x, align 4 161 ret void 162} 163 164; CHECK-LABEL: @ShlConst 165; CHECK: = load 166; CHECK: = load 167; CHECK: shl 168; CHECK: shl 169; CHECK: store 170; CHECK: store 171; CHECK: ret void 172 173; Compute shadow for "10 << x": it should have 'sext i1'. 174define void @ShlNonConst(i32* nocapture %x) nounwind uwtable sanitize_memory { 175entry: 176 %0 = load i32, i32* %x, align 4 177 %1 = shl i32 10, %0 178 store i32 %1, i32* %x, align 4 179 ret void 180} 181 182; CHECK-LABEL: @ShlNonConst 183; CHECK: = load 184; CHECK: = load 185; CHECK: = sext i1 186; CHECK: store 187; CHECK: store 188; CHECK: ret void 189 190; SExt 191define void @SExt(i32* nocapture %a, i16* nocapture %b) nounwind uwtable sanitize_memory { 192entry: 193 %0 = load i16, i16* %b, align 2 194 %1 = sext i16 %0 to i32 195 store i32 %1, i32* %a, align 4 196 ret void 197} 198 199; CHECK-LABEL: @SExt 200; CHECK: = load 201; CHECK: = load 202; CHECK: = sext 203; CHECK: = sext 204; CHECK: store 205; CHECK: store 206; CHECK: ret void 207 208 209; memset 210define void @MemSet(i8* nocapture %x) nounwind uwtable sanitize_memory { 211entry: 212 call void @llvm.memset.p0i8.i64(i8* %x, i8 42, i64 10, i1 false) 213 ret void 214} 215 216declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind 217 218; CHECK-LABEL: @MemSet 219; CHECK: call i8* @__msan_memset 220; CHECK: ret void 221 222 223; memcpy 224define void @MemCpy(i8* nocapture %x, i8* nocapture %y) nounwind uwtable sanitize_memory { 225entry: 226 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %x, i8* %y, i64 10, i1 false) 227 ret void 228} 229 230declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind 231 232; CHECK-LABEL: @MemCpy 233; CHECK: call i8* @__msan_memcpy 234; CHECK: ret void 235 236 237; memmove is lowered to a call 238define void @MemMove(i8* nocapture %x, i8* nocapture %y) nounwind uwtable sanitize_memory { 239entry: 240 call void @llvm.memmove.p0i8.p0i8.i64(i8* %x, i8* %y, i64 10, i1 false) 241 ret void 242} 243 244declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind 245 246; CHECK-LABEL: @MemMove 247; CHECK: call i8* @__msan_memmove 248; CHECK: ret void 249 250;; ------------ 251;; Placeholder tests that will fail once element atomic @llvm.mem[cpy|move|set] intrinsics have 252;; been added to the MemIntrinsic class hierarchy. These will act as a reminder to 253;; verify that MSAN handles these intrinsics properly once they have been 254;; added to that class hierarchy. 255declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* nocapture writeonly, i8, i64, i32) nounwind 256declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32) nounwind 257declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32) nounwind 258 259define void @atomic_memcpy(i8* nocapture %x, i8* nocapture %y) nounwind { 260 ; CHECK-LABEL: atomic_memcpy 261 ; CHECK-NEXT: call void @llvm.donothing 262 ; CHECK-NEXT: call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %x, i8* align 2 %y, i64 16, i32 1) 263 ; CHECK-NEXT: ret void 264 call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %x, i8* align 2 %y, i64 16, i32 1) 265 ret void 266} 267 268define void @atomic_memmove(i8* nocapture %x, i8* nocapture %y) nounwind { 269 ; CHECK-LABEL: atomic_memmove 270 ; CHECK-NEXT: call void @llvm.donothing 271 ; CHECK-NEXT: call void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %x, i8* align 2 %y, i64 16, i32 1) 272 ; CHECK-NEXT: ret void 273 call void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %x, i8* align 2 %y, i64 16, i32 1) 274 ret void 275} 276 277define void @atomic_memset(i8* nocapture %x) nounwind { 278 ; CHECK-LABEL: atomic_memset 279 ; CHECK-NEXT: call void @llvm.donothing 280 ; CHECK-NEXT: call void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* align 1 %x, i8 88, i64 16, i32 1) 281 ; CHECK-NEXT: ret void 282 call void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* align 1 %x, i8 88, i64 16, i32 1) 283 ret void 284} 285 286;; ------------ 287 288 289; Check that we propagate shadow for "select" 290 291define i32 @Select(i32 %a, i32 %b, i1 %c) nounwind uwtable readnone sanitize_memory { 292entry: 293 %cond = select i1 %c, i32 %a, i32 %b 294 ret i32 %cond 295} 296 297; CHECK-LABEL: @Select 298; CHECK: select i1 299; CHECK-DAG: or i32 300; CHECK-DAG: xor i32 301; CHECK: or i32 302; CHECK-DAG: select i1 303; CHECK-ORIGINS-DAG: select 304; CHECK-ORIGINS-DAG: select 305; CHECK-DAG: select i1 306; CHECK: store i32{{.*}}@__msan_retval_tls 307; CHECK-ORIGINS: store i32{{.*}}@__msan_retval_origin_tls 308; CHECK: ret i32 309 310 311; Check that we propagate origin for "select" with vector condition. 312; Select condition is flattened to i1, which is then used to select one of the 313; argument origins. 314 315define <8 x i16> @SelectVector(<8 x i16> %a, <8 x i16> %b, <8 x i1> %c) nounwind uwtable readnone sanitize_memory { 316entry: 317 %cond = select <8 x i1> %c, <8 x i16> %a, <8 x i16> %b 318 ret <8 x i16> %cond 319} 320 321; CHECK-LABEL: @SelectVector 322; CHECK: select <8 x i1> 323; CHECK-DAG: or <8 x i16> 324; CHECK-DAG: xor <8 x i16> 325; CHECK: or <8 x i16> 326; CHECK-DAG: select <8 x i1> 327; CHECK-ORIGINS-DAG: select 328; CHECK-ORIGINS-DAG: select 329; CHECK-DAG: select <8 x i1> 330; CHECK: store <8 x i16>{{.*}}@__msan_retval_tls 331; CHECK-ORIGINS: store i32{{.*}}@__msan_retval_origin_tls 332; CHECK: ret <8 x i16> 333 334 335; Check that we propagate origin for "select" with scalar condition and vector 336; arguments. Select condition shadow is sign-extended to the vector type and 337; mixed into the result shadow. 338 339define <8 x i16> @SelectVector2(<8 x i16> %a, <8 x i16> %b, i1 %c) nounwind uwtable readnone sanitize_memory { 340entry: 341 %cond = select i1 %c, <8 x i16> %a, <8 x i16> %b 342 ret <8 x i16> %cond 343} 344 345; CHECK-LABEL: @SelectVector2 346; CHECK: select i1 347; CHECK-DAG: or <8 x i16> 348; CHECK-DAG: xor <8 x i16> 349; CHECK: or <8 x i16> 350; CHECK-DAG: select i1 351; CHECK-ORIGINS-DAG: select i1 352; CHECK-ORIGINS-DAG: select i1 353; CHECK-DAG: select i1 354; CHECK: ret <8 x i16> 355 356 357define { i64, i64 } @SelectStruct(i1 zeroext %x, { i64, i64 } %a, { i64, i64 } %b) readnone sanitize_memory { 358entry: 359 %c = select i1 %x, { i64, i64 } %a, { i64, i64 } %b 360 ret { i64, i64 } %c 361} 362 363; CHECK-LABEL: @SelectStruct 364; CHECK: select i1 {{.*}}, { i64, i64 } 365; CHECK-NEXT: select i1 {{.*}}, { i64, i64 } { i64 -1, i64 -1 }, { i64, i64 } 366; CHECK-ORIGINS: select i1 367; CHECK-ORIGINS: select i1 368; CHECK-NEXT: select i1 {{.*}}, { i64, i64 } 369; CHECK: ret { i64, i64 } 370 371 372define { i64*, double } @SelectStruct2(i1 zeroext %x, { i64*, double } %a, { i64*, double } %b) readnone sanitize_memory { 373entry: 374 %c = select i1 %x, { i64*, double } %a, { i64*, double } %b 375 ret { i64*, double } %c 376} 377 378; CHECK-LABEL: @SelectStruct2 379; CHECK: select i1 {{.*}}, { i64, i64 } 380; CHECK-NEXT: select i1 {{.*}}, { i64, i64 } { i64 -1, i64 -1 }, { i64, i64 } 381; CHECK-ORIGINS: select i1 382; CHECK-ORIGINS: select i1 383; CHECK-NEXT: select i1 {{.*}}, { i64*, double } 384; CHECK: ret { i64*, double } 385 386 387define i8* @IntToPtr(i64 %x) nounwind uwtable readnone sanitize_memory { 388entry: 389 %0 = inttoptr i64 %x to i8* 390 ret i8* %0 391} 392 393; CHECK-LABEL: @IntToPtr 394; CHECK: load i64, i64*{{.*}}__msan_param_tls 395; CHECK-ORIGINS-NEXT: load i32, i32*{{.*}}__msan_param_origin_tls 396; CHECK-NEXT: call void @llvm.donothing 397; CHECK-NEXT: inttoptr 398; CHECK-NEXT: store i64{{.*}}__msan_retval_tls 399; CHECK: ret i8* 400 401 402define i8* @IntToPtr_ZExt(i16 %x) nounwind uwtable readnone sanitize_memory { 403entry: 404 %0 = inttoptr i16 %x to i8* 405 ret i8* %0 406} 407 408; CHECK-LABEL: @IntToPtr_ZExt 409; CHECK: load i16, i16*{{.*}}__msan_param_tls 410; CHECK: zext 411; CHECK-NEXT: inttoptr 412; CHECK-NEXT: store i64{{.*}}__msan_retval_tls 413; CHECK: ret i8* 414 415 416; Check that we insert exactly one check on udiv 417; (2nd arg shadow is checked, 1st arg shadow is propagated) 418 419define i32 @Div(i32 %a, i32 %b) nounwind uwtable readnone sanitize_memory { 420entry: 421 %div = udiv i32 %a, %b 422 ret i32 %div 423} 424 425; CHECK-LABEL: @Div 426; CHECK: icmp 427; CHECK: call void @__msan_warning_with_origin 428; CHECK-NOT: icmp 429; CHECK: udiv 430; CHECK-NOT: icmp 431; CHECK: ret i32 432 433; Check that fdiv, unlike udiv, simply propagates shadow. 434 435define float @FDiv(float %a, float %b) nounwind uwtable readnone sanitize_memory { 436entry: 437 %c = fdiv float %a, %b 438 ret float %c 439} 440 441; CHECK-LABEL: @FDiv 442; CHECK: %[[SA:.*]] = load i32,{{.*}}@__msan_param_tls 443; CHECK: %[[SB:.*]] = load i32,{{.*}}@__msan_param_tls 444; CHECK: %[[SC:.*]] = or i32 %[[SA]], %[[SB]] 445; CHECK: = fdiv float 446; CHECK: store i32 %[[SC]], i32* {{.*}}@__msan_retval_tls 447; CHECK: ret float 448 449; Check that fneg simply propagates shadow. 450 451define float @FNeg(float %a) nounwind uwtable readnone sanitize_memory { 452entry: 453 %c = fneg float %a 454 ret float %c 455} 456 457; CHECK-LABEL: @FNeg 458; CHECK: %[[SA:.*]] = load i32,{{.*}}@__msan_param_tls 459; CHECK-ORIGINS: %[[SB:.*]] = load i32,{{.*}}@__msan_param_origin_tls 460; CHECK: = fneg float 461; CHECK: store i32 %[[SA]], i32* {{.*}}@__msan_retval_tls 462; CHECK-ORIGINS: store i32{{.*}}@__msan_retval_origin_tls 463; CHECK: ret float 464 465; Check that we propagate shadow for x<0, x>=0, etc (i.e. sign bit tests) 466 467define zeroext i1 @ICmpSLTZero(i32 %x) nounwind uwtable readnone sanitize_memory { 468 %1 = icmp slt i32 %x, 0 469 ret i1 %1 470} 471 472; CHECK-LABEL: @ICmpSLTZero 473; CHECK: icmp slt 474; CHECK-NOT: call void @__msan_warning_with_origin 475; CHECK: icmp slt 476; CHECK-NOT: call void @__msan_warning_with_origin 477; CHECK: ret i1 478 479define zeroext i1 @ICmpSGEZero(i32 %x) nounwind uwtable readnone sanitize_memory { 480 %1 = icmp sge i32 %x, 0 481 ret i1 %1 482} 483 484; CHECK-LABEL: @ICmpSGEZero 485; CHECK: icmp slt 486; CHECK-NOT: call void @__msan_warning_with_origin 487; CHECK: icmp sge 488; CHECK-NOT: call void @__msan_warning_with_origin 489; CHECK: ret i1 490 491define zeroext i1 @ICmpSGTZero(i32 %x) nounwind uwtable readnone sanitize_memory { 492 %1 = icmp sgt i32 0, %x 493 ret i1 %1 494} 495 496; CHECK-LABEL: @ICmpSGTZero 497; CHECK: icmp slt 498; CHECK-NOT: call void @__msan_warning_with_origin 499; CHECK: icmp sgt 500; CHECK-NOT: call void @__msan_warning_with_origin 501; CHECK: ret i1 502 503define zeroext i1 @ICmpSLEZero(i32 %x) nounwind uwtable readnone sanitize_memory { 504 %1 = icmp sle i32 0, %x 505 ret i1 %1 506} 507 508; CHECK-LABEL: @ICmpSLEZero 509; CHECK: icmp slt 510; CHECK-NOT: call void @__msan_warning_with_origin 511; CHECK: icmp sle 512; CHECK-NOT: call void @__msan_warning_with_origin 513; CHECK: ret i1 514 515 516; Check that we propagate shadow for x<=-1, x>-1, etc (i.e. sign bit tests) 517 518define zeroext i1 @ICmpSLTAllOnes(i32 %x) nounwind uwtable readnone sanitize_memory { 519 %1 = icmp slt i32 -1, %x 520 ret i1 %1 521} 522 523; CHECK-LABEL: @ICmpSLTAllOnes 524; CHECK: icmp slt 525; CHECK-NOT: call void @__msan_warning_with_origin 526; CHECK: icmp slt 527; CHECK-NOT: call void @__msan_warning_with_origin 528; CHECK: ret i1 529 530define zeroext i1 @ICmpSGEAllOnes(i32 %x) nounwind uwtable readnone sanitize_memory { 531 %1 = icmp sge i32 -1, %x 532 ret i1 %1 533} 534 535; CHECK-LABEL: @ICmpSGEAllOnes 536; CHECK: icmp slt 537; CHECK-NOT: call void @__msan_warning_with_origin 538; CHECK: icmp sge 539; CHECK-NOT: call void @__msan_warning_with_origin 540; CHECK: ret i1 541 542define zeroext i1 @ICmpSGTAllOnes(i32 %x) nounwind uwtable readnone sanitize_memory { 543 %1 = icmp sgt i32 %x, -1 544 ret i1 %1 545} 546 547; CHECK-LABEL: @ICmpSGTAllOnes 548; CHECK: icmp slt 549; CHECK-NOT: call void @__msan_warning_with_origin 550; CHECK: icmp sgt 551; CHECK-NOT: call void @__msan_warning_with_origin 552; CHECK: ret i1 553 554define zeroext i1 @ICmpSLEAllOnes(i32 %x) nounwind uwtable readnone sanitize_memory { 555 %1 = icmp sle i32 %x, -1 556 ret i1 %1 557} 558 559; CHECK-LABEL: @ICmpSLEAllOnes 560; CHECK: icmp slt 561; CHECK-NOT: call void @__msan_warning_with_origin 562; CHECK: icmp sle 563; CHECK-NOT: call void @__msan_warning_with_origin 564; CHECK: ret i1 565 566 567; Check that we propagate shadow for x<0, x>=0, etc (i.e. sign bit tests) 568; of the vector arguments. 569 570define <2 x i1> @ICmpSLT_vector_Zero(<2 x i32*> %x) nounwind uwtable readnone sanitize_memory { 571 %1 = icmp slt <2 x i32*> %x, zeroinitializer 572 ret <2 x i1> %1 573} 574 575; CHECK-LABEL: @ICmpSLT_vector_Zero 576; CHECK: icmp slt <2 x i64> 577; CHECK-NOT: call void @__msan_warning_with_origin 578; CHECK: icmp slt <2 x i32*> 579; CHECK-NOT: call void @__msan_warning_with_origin 580; CHECK: ret <2 x i1> 581 582; Check that we propagate shadow for x<=-1, x>0, etc (i.e. sign bit tests) 583; of the vector arguments. 584 585define <2 x i1> @ICmpSLT_vector_AllOnes(<2 x i32> %x) nounwind uwtable readnone sanitize_memory { 586 %1 = icmp slt <2 x i32> <i32 -1, i32 -1>, %x 587 ret <2 x i1> %1 588} 589 590; CHECK-LABEL: @ICmpSLT_vector_AllOnes 591; CHECK: icmp slt <2 x i32> 592; CHECK-NOT: call void @__msan_warning_with_origin 593; CHECK: icmp slt <2 x i32> 594; CHECK-NOT: call void @__msan_warning_with_origin 595; CHECK: ret <2 x i1> 596 597 598; Check that we propagate shadow for unsigned relational comparisons with 599; constants 600 601define zeroext i1 @ICmpUGTConst(i32 %x) nounwind uwtable readnone sanitize_memory { 602entry: 603 %cmp = icmp ugt i32 %x, 7 604 ret i1 %cmp 605} 606 607; CHECK-LABEL: @ICmpUGTConst 608; CHECK: icmp ugt i32 609; CHECK-NOT: call void @__msan_warning_with_origin 610; CHECK: icmp ugt i32 611; CHECK-NOT: call void @__msan_warning_with_origin 612; CHECK: icmp ugt i32 613; CHECK-NOT: call void @__msan_warning_with_origin 614; CHECK: ret i1 615 616 617; Check that loads of shadow have the same alignment as the original loads. 618; Check that loads of origin have the alignment of max(4, original alignment). 619 620define i32 @ShadowLoadAlignmentLarge() nounwind uwtable sanitize_memory { 621 %y = alloca i32, align 64 622 %1 = load volatile i32, i32* %y, align 64 623 ret i32 %1 624} 625 626; CHECK-LABEL: @ShadowLoadAlignmentLarge 627; CHECK: load volatile i32, i32* {{.*}} align 64 628; CHECK: load i32, i32* {{.*}} align 64 629; CHECK: ret i32 630 631define i32 @ShadowLoadAlignmentSmall() nounwind uwtable sanitize_memory { 632 %y = alloca i32, align 2 633 %1 = load volatile i32, i32* %y, align 2 634 ret i32 %1 635} 636 637; CHECK-LABEL: @ShadowLoadAlignmentSmall 638; CHECK: load volatile i32, i32* {{.*}} align 2 639; CHECK: load i32, i32* {{.*}} align 2 640; CHECK-ORIGINS: load i32, i32* {{.*}} align 4 641; CHECK: ret i32 642 643 644; Test vector manipulation instructions. 645; Check that the same bit manipulation is applied to the shadow values. 646; Check that there is a zero test of the shadow of %idx argument, where present. 647 648define i32 @ExtractElement(<4 x i32> %vec, i32 %idx) sanitize_memory { 649 %x = extractelement <4 x i32> %vec, i32 %idx 650 ret i32 %x 651} 652 653; CHECK-LABEL: @ExtractElement 654; CHECK: extractelement 655; CHECK: call void @__msan_warning_with_origin 656; CHECK: extractelement 657; CHECK: ret i32 658 659define <4 x i32> @InsertElement(<4 x i32> %vec, i32 %idx, i32 %x) sanitize_memory { 660 %vec1 = insertelement <4 x i32> %vec, i32 %x, i32 %idx 661 ret <4 x i32> %vec1 662} 663 664; CHECK-LABEL: @InsertElement 665; CHECK: insertelement 666; CHECK: call void @__msan_warning_with_origin 667; CHECK: insertelement 668; CHECK: ret <4 x i32> 669 670define <4 x i32> @ShuffleVector(<4 x i32> %vec, <4 x i32> %vec1) sanitize_memory { 671 %vec2 = shufflevector <4 x i32> %vec, <4 x i32> %vec1, 672 <4 x i32> <i32 0, i32 4, i32 1, i32 5> 673 ret <4 x i32> %vec2 674} 675 676; CHECK-LABEL: @ShuffleVector 677; CHECK: shufflevector 678; CHECK-NOT: call void @__msan_warning_with_origin 679; CHECK: shufflevector 680; CHECK: ret <4 x i32> 681 682 683; Test bswap intrinsic instrumentation 684define i32 @BSwap(i32 %x) nounwind uwtable readnone sanitize_memory { 685 %y = tail call i32 @llvm.bswap.i32(i32 %x) 686 ret i32 %y 687} 688 689declare i32 @llvm.bswap.i32(i32) nounwind readnone 690 691; CHECK-LABEL: @BSwap 692; CHECK-NOT: call void @__msan_warning_with_origin 693; CHECK: @llvm.bswap.i32 694; CHECK-NOT: call void @__msan_warning_with_origin 695; CHECK: @llvm.bswap.i32 696; CHECK-NOT: call void @__msan_warning_with_origin 697; CHECK: ret i32 698 699; Test handling of vectors of pointers. 700; Check that shadow of such vector is a vector of integers. 701 702define <8 x i8*> @VectorOfPointers(<8 x i8*>* %p) nounwind uwtable sanitize_memory { 703 %x = load <8 x i8*>, <8 x i8*>* %p 704 ret <8 x i8*> %x 705} 706 707; CHECK-LABEL: @VectorOfPointers 708; CHECK: load <8 x i8*>, <8 x i8*>* 709; CHECK: load <8 x i64>, <8 x i64>* 710; CHECK: store <8 x i64> {{.*}} @__msan_retval_tls 711; CHECK: ret <8 x i8*> 712 713; Test handling of va_copy. 714 715declare void @llvm.va_copy(i8*, i8*) nounwind 716 717define void @VACopy(i8* %p1, i8* %p2) nounwind uwtable sanitize_memory { 718 call void @llvm.va_copy(i8* %p1, i8* %p2) nounwind 719 ret void 720} 721 722; CHECK-LABEL: @VACopy 723; CHECK: call void @llvm.memset.p0i8.i64({{.*}}, i8 0, i64 24, i1 false) 724; CHECK: ret void 725 726 727; Test that va_start instrumentation does not use va_arg_tls*. 728; It should work with a local stack copy instead. 729 730%struct.__va_list_tag = type { i32, i32, i8*, i8* } 731declare void @llvm.va_start(i8*) nounwind 732 733; Function Attrs: nounwind uwtable 734define void @VAStart(i32 %x, ...) sanitize_memory { 735entry: 736 %x.addr = alloca i32, align 4 737 %va = alloca [1 x %struct.__va_list_tag], align 16 738 store i32 %x, i32* %x.addr, align 4 739 %arraydecay = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %va, i32 0, i32 0 740 %arraydecay1 = bitcast %struct.__va_list_tag* %arraydecay to i8* 741 call void @llvm.va_start(i8* %arraydecay1) 742 ret void 743} 744 745; CHECK-LABEL: @VAStart 746; CHECK: call void @llvm.va_start 747; CHECK-NOT: @__msan_va_arg_tls 748; CHECK-NOT: @__msan_va_arg_overflow_size_tls 749; CHECK: ret void 750 751 752; Test handling of volatile stores. 753; Check that MemorySanitizer does not add a check of the value being stored. 754 755define void @VolatileStore(i32* nocapture %p, i32 %x) nounwind uwtable sanitize_memory { 756entry: 757 store volatile i32 %x, i32* %p, align 4 758 ret void 759} 760 761; CHECK-LABEL: @VolatileStore 762; CHECK-NOT: @__msan_warning_with_origin 763; CHECK: ret void 764 765 766; Test that checks are omitted and returned value is always initialized if 767; sanitize_memory attribute is missing. 768 769define i32 @NoSanitizeMemory(i32 %x) uwtable { 770entry: 771 %tobool = icmp eq i32 %x, 0 772 br i1 %tobool, label %if.end, label %if.then 773 774if.then: ; preds = %entry 775 tail call void @bar() 776 br label %if.end 777 778if.end: ; preds = %entry, %if.then 779 ret i32 %x 780} 781 782declare void @bar() 783 784; CHECK-LABEL: @NoSanitizeMemory 785; CHECK-NOT: @__msan_warning_with_origin 786; CHECK: store i32 0, {{.*}} @__msan_retval_tls 787; CHECK-NOT: @__msan_warning_with_origin 788; CHECK: ret i32 789 790 791; Test that stack allocations are unpoisoned in functions missing 792; sanitize_memory attribute 793 794define i32 @NoSanitizeMemoryAlloca() { 795entry: 796 %p = alloca i32, align 4 797 %x = call i32 @NoSanitizeMemoryAllocaHelper(i32* %p) 798 ret i32 %x 799} 800 801declare i32 @NoSanitizeMemoryAllocaHelper(i32* %p) 802 803; CHECK-LABEL: @NoSanitizeMemoryAlloca 804; CHECK: call void @llvm.memset.p0i8.i64(i8* align 4 {{.*}}, i8 0, i64 4, i1 false) 805; CHECK: call i32 @NoSanitizeMemoryAllocaHelper(i32* 806; CHECK: ret i32 807 808 809; Test that undef is unpoisoned in functions missing 810; sanitize_memory attribute 811 812define i32 @NoSanitizeMemoryUndef() { 813entry: 814 %x = call i32 @NoSanitizeMemoryUndefHelper(i32 undef) 815 ret i32 %x 816} 817 818declare i32 @NoSanitizeMemoryUndefHelper(i32 %x) 819 820; CHECK-LABEL: @NoSanitizeMemoryUndef 821; CHECK: store i32 0, i32* {{.*}} @__msan_param_tls 822; CHECK: call i32 @NoSanitizeMemoryUndefHelper(i32 undef) 823; CHECK: ret i32 824 825 826; Test PHINode instrumentation in ignorelisted functions 827 828define i32 @NoSanitizeMemoryPHI(i32 %x) { 829entry: 830 %tobool = icmp ne i32 %x, 0 831 br i1 %tobool, label %cond.true, label %cond.false 832 833cond.true: ; preds = %entry 834 br label %cond.end 835 836cond.false: ; preds = %entry 837 br label %cond.end 838 839cond.end: ; preds = %cond.false, %cond.true 840 %cond = phi i32 [ undef, %cond.true ], [ undef, %cond.false ] 841 ret i32 %cond 842} 843 844; CHECK: [[A:%.*]] = phi i32 [ undef, %cond.true ], [ undef, %cond.false ] 845; CHECK: store i32 0, i32* bitcast {{.*}} @__msan_retval_tls 846; CHECK: ret i32 [[A]] 847 848 849; Test that there are no __msan_param_origin_tls stores when 850; argument shadow is a compile-time zero constant (which is always the case 851; in functions missing sanitize_memory attribute). 852 853define i32 @NoSanitizeMemoryParamTLS(i32* nocapture readonly %x) { 854entry: 855 %0 = load i32, i32* %x, align 4 856 %call = tail call i32 @NoSanitizeMemoryParamTLSHelper(i32 %0) 857 ret i32 %call 858} 859 860declare i32 @NoSanitizeMemoryParamTLSHelper(i32 %x) 861 862; CHECK-LABEL: define i32 @NoSanitizeMemoryParamTLS( 863; CHECK-NOT: __msan_param_origin_tls 864; CHECK: ret i32 865 866 867; Test argument shadow alignment 868 869define <2 x i64> @ArgumentShadowAlignment(i64 %a, <2 x i64> %b) sanitize_memory { 870entry: 871 ret <2 x i64> %b 872} 873 874; CHECK-LABEL: @ArgumentShadowAlignment 875; CHECK: load <2 x i64>, <2 x i64>* {{.*}} @__msan_param_tls {{.*}}, align 8 876; CHECK: store <2 x i64> {{.*}} @__msan_retval_tls {{.*}}, align 8 877; CHECK: ret <2 x i64> 878 879 880; Test origin propagation for insertvalue 881 882define { i64, i32 } @make_pair_64_32(i64 %x, i32 %y) sanitize_memory { 883entry: 884 %a = insertvalue { i64, i32 } undef, i64 %x, 0 885 %b = insertvalue { i64, i32 } %a, i32 %y, 1 886 ret { i64, i32 } %b 887} 888 889; CHECK-ORIGINS: @make_pair_64_32 890; First element shadow 891; CHECK-ORIGINS: insertvalue { i64, i32 } { i64 -1, i32 -1 }, i64 {{.*}}, 0 892; First element origin 893; CHECK-ORIGINS: icmp ne i64 894; CHECK-ORIGINS: select i1 895; First element app value 896; CHECK-ORIGINS: insertvalue { i64, i32 } undef, i64 {{.*}}, 0 897; Second element shadow 898; CHECK-ORIGINS: insertvalue { i64, i32 } {{.*}}, i32 {{.*}}, 1 899; Second element origin 900; CHECK-ORIGINS: icmp ne i32 901; CHECK-ORIGINS: select i1 902; Second element app value 903; CHECK-ORIGINS: insertvalue { i64, i32 } {{.*}}, i32 {{.*}}, 1 904; CHECK-ORIGINS: ret { i64, i32 } 905 906 907; Test shadow propagation for aggregates passed through ellipsis. 908 909%struct.StructByVal = type { i32, i32, i32, i32 } 910 911declare void @VAArgStructFn(i32 %guard, ...) 912 913define void @VAArgStruct(%struct.StructByVal* nocapture %s) sanitize_memory { 914entry: 915 %agg.tmp2 = alloca %struct.StructByVal, align 8 916 %0 = bitcast %struct.StructByVal* %s to i8* 917 %agg.tmp.sroa.0.0..sroa_cast = bitcast %struct.StructByVal* %s to i64* 918 %agg.tmp.sroa.0.0.copyload = load i64, i64* %agg.tmp.sroa.0.0..sroa_cast, align 4 919 %agg.tmp.sroa.2.0..sroa_idx = getelementptr inbounds %struct.StructByVal, %struct.StructByVal* %s, i64 0, i32 2 920 %agg.tmp.sroa.2.0..sroa_cast = bitcast i32* %agg.tmp.sroa.2.0..sroa_idx to i64* 921 %agg.tmp.sroa.2.0.copyload = load i64, i64* %agg.tmp.sroa.2.0..sroa_cast, align 4 922 %1 = bitcast %struct.StructByVal* %agg.tmp2 to i8* 923 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %1, i8* align 4 %0, i64 16, i1 false) 924 call void (i32, ...) @VAArgStructFn(i32 undef, i64 %agg.tmp.sroa.0.0.copyload, i64 %agg.tmp.sroa.2.0.copyload, i64 %agg.tmp.sroa.0.0.copyload, i64 %agg.tmp.sroa.2.0.copyload, %struct.StructByVal* byval(%struct.StructByVal) align 8 %agg.tmp2) 925 ret void 926} 927 928; "undef" and the first 2 structs go to general purpose registers; 929; the third struct goes to the overflow area byval 930 931; CHECK-LABEL: @VAArgStruct 932; undef not stored to __msan_va_arg_tls - it's a fixed argument 933; first struct through general purpose registers 934; CHECK: store i64 {{.*}}, i64* {{.*}}@__msan_va_arg_tls{{.*}}, i64 8){{.*}}, align 8 935; CHECK: store i64 {{.*}}, i64* {{.*}}@__msan_va_arg_tls{{.*}}, i64 16){{.*}}, align 8 936; second struct through general purpose registers 937; CHECK: store i64 {{.*}}, i64* {{.*}}@__msan_va_arg_tls{{.*}}, i64 24){{.*}}, align 8 938; CHECK: store i64 {{.*}}, i64* {{.*}}@__msan_va_arg_tls{{.*}}, i64 32){{.*}}, align 8 939; third struct through the overflow area byval 940; CHECK: ptrtoint %struct.StructByVal* {{.*}} to i64 941; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64{{.*}}@__msan_va_arg_tls {{.*}}, i64 176 942; CHECK: store i64 16, i64* @__msan_va_arg_overflow_size_tls 943; CHECK: call void (i32, ...) @VAArgStructFn 944; CHECK: ret void 945 946; Same code compiled without SSE (see attributes below). 947; The register save area is only 48 bytes instead of 176. 948define void @VAArgStructNoSSE(%struct.StructByVal* nocapture %s) sanitize_memory #0 { 949entry: 950 %agg.tmp2 = alloca %struct.StructByVal, align 8 951 %0 = bitcast %struct.StructByVal* %s to i8* 952 %agg.tmp.sroa.0.0..sroa_cast = bitcast %struct.StructByVal* %s to i64* 953 %agg.tmp.sroa.0.0.copyload = load i64, i64* %agg.tmp.sroa.0.0..sroa_cast, align 4 954 %agg.tmp.sroa.2.0..sroa_idx = getelementptr inbounds %struct.StructByVal, %struct.StructByVal* %s, i64 0, i32 2 955 %agg.tmp.sroa.2.0..sroa_cast = bitcast i32* %agg.tmp.sroa.2.0..sroa_idx to i64* 956 %agg.tmp.sroa.2.0.copyload = load i64, i64* %agg.tmp.sroa.2.0..sroa_cast, align 4 957 %1 = bitcast %struct.StructByVal* %agg.tmp2 to i8* 958 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %1, i8* align 4 %0, i64 16, i1 false) 959 call void (i32, ...) @VAArgStructFn(i32 undef, i64 %agg.tmp.sroa.0.0.copyload, i64 %agg.tmp.sroa.2.0.copyload, i64 %agg.tmp.sroa.0.0.copyload, i64 %agg.tmp.sroa.2.0.copyload, %struct.StructByVal* byval(%struct.StructByVal) align 8 %agg.tmp2) 960 ret void 961} 962 963attributes #0 = { "target-features"="+fxsr,+x87,-sse" } 964 965; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64{{.*}}@__msan_va_arg_tls {{.*}}, i64 48 966 967declare i32 @InnerTailCall(i32 %a) 968 969define void @MismatchedReturnTypeTailCall(i32 %a) sanitize_memory { 970 %b = tail call i32 @InnerTailCall(i32 %a) 971 ret void 972} 973 974; We used to strip off the 'tail' modifier, but now that we unpoison return slot 975; shadow before the call, we don't need to anymore. 976 977; CHECK-LABEL: define void @MismatchedReturnTypeTailCall 978; CHECK: tail call i32 @InnerTailCall 979; CHECK: ret void 980 981 982declare i32 @MustTailCall(i32 %a) 983 984define i32 @CallMustTailCall(i32 %a) sanitize_memory { 985 %b = musttail call i32 @MustTailCall(i32 %a) 986 ret i32 %b 987} 988 989; For "musttail" calls we can not insert any shadow manipulating code between 990; call and the return instruction. And we don't need to, because everything is 991; taken care of in the callee. 992 993; CHECK-LABEL: define i32 @CallMustTailCall 994; CHECK: musttail call i32 @MustTailCall 995; No instrumentation between call and ret. 996; CHECK-NEXT: ret i32 997 998declare i32* @MismatchingMustTailCall(i32 %a) 999 1000define i8* @MismatchingCallMustTailCall(i32 %a) sanitize_memory { 1001 %b = musttail call i32* @MismatchingMustTailCall(i32 %a) 1002 %c = bitcast i32* %b to i8* 1003 ret i8* %c 1004} 1005 1006; For "musttail" calls we can not insert any shadow manipulating code between 1007; call and the return instruction. And we don't need to, because everything is 1008; taken care of in the callee. 1009 1010; CHECK-LABEL: define i8* @MismatchingCallMustTailCall 1011; CHECK: musttail call i32* @MismatchingMustTailCall 1012; No instrumentation between call and ret. 1013; CHECK-NEXT: bitcast i32* {{.*}} to i8* 1014; CHECK-NEXT: ret i8* 1015 1016 1017; CHECK-LABEL: define internal void @msan.module_ctor() #[[#ATTR:]] { 1018; CHECK: call void @__msan_init() 1019 1020; CHECK-CALLS: declare void @__msan_maybe_warning_1(i8 zeroext, i32 zeroext) 1021; CHECK-CALLS: declare void @__msan_maybe_store_origin_1(i8 zeroext, i8*, i32 zeroext) 1022; CHECK-CALLS: declare void @__msan_maybe_warning_2(i16 zeroext, i32 zeroext) 1023; CHECK-CALLS: declare void @__msan_maybe_store_origin_2(i16 zeroext, i8*, i32 zeroext) 1024; CHECK-CALLS: declare void @__msan_maybe_warning_4(i32 zeroext, i32 zeroext) 1025; CHECK-CALLS: declare void @__msan_maybe_store_origin_4(i32 zeroext, i8*, i32 zeroext) 1026; CHECK-CALLS: declare void @__msan_maybe_warning_8(i64 zeroext, i32 zeroext) 1027; CHECK-CALLS: declare void @__msan_maybe_store_origin_8(i64 zeroext, i8*, i32 zeroext) 1028 1029; CHECK: attributes #[[#ATTR]] = { nounwind } 1030