[sanitizer] Simplify and future-proof maybeMarkSanitizerLibraryCallNoBuiltin().

Sanitizers set nobuiltin attribute on certain library functions to
avoid a situation where such function is neither instrumented nor
intercepted.

At the moment the list of interesting functions is hardcoded. This
change replaces it with logic based on
TargetLibraryInfo::hasOptimizedCodegen and the presense of readnone
function attribute (sanitizers are generally interested in memory
behavior of library functions).

This is expected to be a no-op change: the new logic matches exactly
the same set of functions.

r276771 (currently reverted) added mempcpy() to the list, breaking
MSan tests. With this change, r276771 can be safely re-landed.

llvm-svn: 277086
This commit is contained in:
Evgeniy Stepanov 2016-07-28 23:45:15 +00:00
parent c6af5ead86
commit d240a889ad
1 changed files with 6 additions and 17 deletions
llvm/lib/Transforms/Utils

View File

@ -1954,23 +1954,12 @@ bool llvm::recognizeBSwapOrBitReverseIdiom(
// in ASan/MSan/TSan/DFSan, and thus make us miss some memory accesses, // in ASan/MSan/TSan/DFSan, and thus make us miss some memory accesses,
// we mark affected calls as NoBuiltin, which will disable optimization // we mark affected calls as NoBuiltin, which will disable optimization
// in CodeGen. // in CodeGen.
void llvm::maybeMarkSanitizerLibraryCallNoBuiltin(CallInst *CI, void llvm::maybeMarkSanitizerLibraryCallNoBuiltin(
const TargetLibraryInfo *TLI) { CallInst *CI, const TargetLibraryInfo *TLI) {
Function *F = CI->getCalledFunction(); Function *F = CI->getCalledFunction();
LibFunc::Func Func; LibFunc::Func Func;
if (!F || F->hasLocalLinkage() || !F->hasName() || if (F && !F->hasLocalLinkage() && F->hasName() &&
!TLI->getLibFunc(F->getName(), Func)) TLI->getLibFunc(F->getName(), Func) && TLI->hasOptimizedCodeGen(Func) &&
return; !F->doesNotAccessMemory())
switch (Func) { CI->addAttribute(AttributeSet::FunctionIndex, Attribute::NoBuiltin);
default: break;
case LibFunc::memcmp:
case LibFunc::memchr:
case LibFunc::strcpy:
case LibFunc::stpcpy:
case LibFunc::strcmp:
case LibFunc::strlen:
case LibFunc::strnlen:
CI->addAttribute(AttributeSet::FunctionIndex, Attribute::NoBuiltin);
break;
}
} }