[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,
// we mark affected calls as NoBuiltin, which will disable optimization
// in CodeGen.
void llvm::maybeMarkSanitizerLibraryCallNoBuiltin(CallInst *CI,
const TargetLibraryInfo *TLI) {
void llvm::maybeMarkSanitizerLibraryCallNoBuiltin(
CallInst *CI, const TargetLibraryInfo *TLI) {
Function *F = CI->getCalledFunction();
LibFunc::Func Func;
if (!F || F->hasLocalLinkage() || !F->hasName() ||
!TLI->getLibFunc(F->getName(), Func))
return;
switch (Func) {
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;
}
if (F && !F->hasLocalLinkage() && F->hasName() &&
TLI->getLibFunc(F->getName(), Func) && TLI->hasOptimizedCodeGen(Func) &&
!F->doesNotAccessMemory())
CI->addAttribute(AttributeSet::FunctionIndex, Attribute::NoBuiltin);
}