From d240a889ad7d9be18a83f56cc723f77f74e2f8de Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Thu, 28 Jul 2016 23:45:15 +0000 Subject: [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 --- llvm/lib/Transforms/Utils/Local.cpp | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'llvm/lib') diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 40432680e38..3148bae292e 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -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); } -- cgit v1.2.3