diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -321,13 +321,10 @@ cl::desc("Apply no_sanitize to the whole file"), cl::Hidden, cl::init(false)); -// This is an experiment to enable handling of cases where shadow is a non-zero -// compile-time constant. For some unexplainable reason they were silently -// ignored in the instrumentation. static cl::opt ClCheckConstantShadow("msan-check-constant-shadow", cl::desc("Insert checks for constant shadow values"), - cl::Hidden, cl::init(false)); + cl::Hidden, cl::init(true)); // This is off by default because of a bug in gold: // https://sourceware.org/bugzilla/show_bug.cgi?id=19002 @@ -1779,9 +1776,7 @@ Value *getOrigin(Value *V) { if (!MS.TrackOrigins) return nullptr; - if (!PropagateShadow) - return getCleanOrigin(); - if (isa(V)) + if (!PropagateShadow || isa(V) || isa(V)) return getCleanOrigin(); assert((isa(V) || isa(V)) && "Unexpected value type in getOrigin()"); diff --git a/llvm/test/Instrumentation/MemorySanitizer/check-constant-shadow.ll b/llvm/test/Instrumentation/MemorySanitizer/check-constant-shadow.ll --- a/llvm/test/Instrumentation/MemorySanitizer/check-constant-shadow.ll +++ b/llvm/test/Instrumentation/MemorySanitizer/check-constant-shadow.ll @@ -1,5 +1,5 @@ -; RUN: opt < %s -msan-check-access-address=0 -msan-check-constant-shadow=1 -msan-eager-checks=1 -msan-track-origins=1 -S -passes=msan 2>&1 | FileCheck --check-prefixes=CHECK,CONST %s --implicit-check-not=icmp --implicit-check-not="store i" --implicit-check-not="call void @__msan" -; RUN: opt < %s -msan-check-access-address=0 -msan-eager-checks=1 -msan-track-origins=1 -S -passes=msan 2>&1 | FileCheck --check-prefixes=CHECK %s --implicit-check-not=icmp --implicit-check-not="store i" --implicit-check-not="call void @__msan" +; RUN: opt < %s -msan-check-access-address=0 -msan-eager-checks=1 -msan-track-origins=1 -S -passes=msan 2>&1 | FileCheck --check-prefixes=CHECK,CONST %s --implicit-check-not=icmp --implicit-check-not="store i" --implicit-check-not="call void @__msan" +; RUN: opt < %s -msan-check-access-address=0 -msan-check-constant-shadow=0 -msan-eager-checks=1 -msan-track-origins=1 -S -passes=msan 2>&1 | FileCheck --check-prefixes=CHECK %s --implicit-check-not=icmp --implicit-check-not="store i" --implicit-check-not="call void @__msan" target 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" target triple = "x86_64-unknown-linux-gnu"