diff --git a/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp index 58108290d8d..a3a688d7c8d 100644 --- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -366,11 +366,13 @@ bool MemorySanitizer::doInitialization(Module &M) { appendToGlobalCtors(M, cast(M.getOrInsertFunction( "__msan_init", IRB.getVoidTy(), NULL)), 0); - new GlobalVariable(M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage, - IRB.getInt32(TrackOrigins), "__msan_track_origins"); + if (TrackOrigins) + new GlobalVariable(M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage, + IRB.getInt32(TrackOrigins), "__msan_track_origins"); - new GlobalVariable(M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage, - IRB.getInt32(ClKeepGoing), "__msan_keep_going"); + if (ClKeepGoing) + new GlobalVariable(M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage, + IRB.getInt32(ClKeepGoing), "__msan_keep_going"); return true; } diff --git a/test/Instrumentation/MemorySanitizer/msan_basic.ll b/test/Instrumentation/MemorySanitizer/msan_basic.ll index 433b8bab4cc..3a8092bdc46 100644 --- a/test/Instrumentation/MemorySanitizer/msan_basic.ll +++ b/test/Instrumentation/MemorySanitizer/msan_basic.ll @@ -10,8 +10,9 @@ target triple = "x86_64-unknown-linux-gnu" ; Check the presence and the linkage type of __msan_track_origins and ; other interface symbols. -; CHECK: @__msan_track_origins = weak_odr constant i32 0 -; CHECK: @__msan_keep_going = weak_odr constant i32 0 +; CHECK-NOT: @__msan_track_origins +; CHECK-ORIGINS: @__msan_track_origins = weak_odr constant i32 1 +; CHECK-NOT: @__msan_keep_going = weak_odr constant i32 0 ; CHECK: @__msan_retval_tls = external thread_local(initialexec) global [{{.*}}] ; CHECK: @__msan_retval_origin_tls = external thread_local(initialexec) global i32 ; CHECK: @__msan_param_tls = external thread_local(initialexec) global [{{.*}}]