diff options
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGDeclCXX.cpp | 14 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 17 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 7 |
3 files changed, 19 insertions, 19 deletions
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp index c2877409f77..6a03e9afe4d 100644 --- a/clang/lib/CodeGen/CGDeclCXX.cpp +++ b/clang/lib/CodeGen/CGDeclCXX.cpp @@ -245,12 +245,14 @@ CreateGlobalInitOrDestructFunction(CodeGenModule &CGM, if (!CGM.getLangOpts().Exceptions) Fn->setDoesNotThrow(); - if (CGM.getSanOpts().Address) - Fn->addFnAttr(llvm::Attribute::SanitizeAddress); - if (CGM.getSanOpts().Thread) - Fn->addFnAttr(llvm::Attribute::SanitizeThread); - if (CGM.getSanOpts().Memory) - Fn->addFnAttr(llvm::Attribute::SanitizeMemory); + if (!CGM.getSanitizerBlacklist().isIn(*Fn)) { + if (CGM.getLangOpts().Sanitize.Address) + Fn->addFnAttr(llvm::Attribute::SanitizeAddress); + if (CGM.getLangOpts().Sanitize.Thread) + Fn->addFnAttr(llvm::Attribute::SanitizeThread); + if (CGM.getLangOpts().Sanitize.Memory) + Fn->addFnAttr(llvm::Attribute::SanitizeMemory); + } return Fn; } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index ce99c2b484c..e5d72241262 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -89,9 +89,7 @@ CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO, GenericBlockLiteralType(nullptr), LifetimeStartFn(nullptr), LifetimeEndFn(nullptr), SanitizerBlacklist( - llvm::SpecialCaseList::createOrDie(CGO.SanitizerBlacklistFile)), - SanOpts(SanitizerBlacklist->isIn(M) ? SanitizerOptions::Disabled - : LangOpts.Sanitize) { + llvm::SpecialCaseList::createOrDie(CGO.SanitizerBlacklistFile)) { // Initialize the type cache. llvm::LLVMContext &LLVMContext = M.getContext(); @@ -122,7 +120,7 @@ CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO, createCUDARuntime(); // Enable TBAA unless it's suppressed. ThreadSanitizer needs TBAA even at O0. - if (SanOpts.Thread || + if (LangOpts.Sanitize.Thread || (!CodeGenOpts.RelaxedAliasing && CodeGenOpts.OptimizationLevel > 0)) TBAA = new CodeGenTBAA(Context, VMContext, CodeGenOpts, getLangOpts(), getCXXABI().getMangleContext()); @@ -735,14 +733,13 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, if (!SanitizerBlacklist->isIn(*F)) { // When AddressSanitizer is enabled, set SanitizeAddress attribute // unless __attribute__((no_sanitize_address)) is used. - if (SanOpts.Address && !D->hasAttr<NoSanitizeAddressAttr>()) + if (LangOpts.Sanitize.Address && !D->hasAttr<NoSanitizeAddressAttr>()) B.addAttribute(llvm::Attribute::SanitizeAddress); // Same for ThreadSanitizer and __attribute__((no_sanitize_thread)) - if (SanOpts.Thread && !D->hasAttr<NoSanitizeThreadAttr>()) { + if (LangOpts.Sanitize.Thread && !D->hasAttr<NoSanitizeThreadAttr>()) B.addAttribute(llvm::Attribute::SanitizeThread); - } // Same for MemorySanitizer and __attribute__((no_sanitize_memory)) - if (SanOpts.Memory && !D->hasAttr<NoSanitizeMemoryAttr>()) + if (LangOpts.Sanitize.Memory && !D->hasAttr<NoSanitizeMemoryAttr>()) B.addAttribute(llvm::Attribute::SanitizeMemory); } @@ -1966,7 +1963,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { void CodeGenModule::reportGlobalToASan(llvm::GlobalVariable *GV, SourceLocation Loc, bool IsDynInit) { - if (!SanOpts.Address) + if (!LangOpts.Sanitize.Address) return; IsDynInit &= !SanitizerBlacklist->isIn(*GV, "init"); bool IsBlacklisted = SanitizerBlacklist->isIn(*GV); @@ -2796,7 +2793,7 @@ CodeGenModule::GetAddrOfConstantStringFromLiteral(const StringLiteral *S) { // Mangle the string literal if the ABI allows for it. However, we cannot // do this if we are compiling with ASan or -fwritable-strings because they // rely on strings having normal linkage. - if (!LangOpts.WritableStrings && !SanOpts.Address && + if (!LangOpts.WritableStrings && !LangOpts.Sanitize.Address && getCXXABI().getMangleContext().shouldMangleStringLiteral(S)) { llvm::raw_svector_ostream Out(MangledNameBuffer); getCXXABI().getMangleContext().mangleStringLiteral(S, Out); diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 8ce4668e032..2f605184876 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -475,8 +475,6 @@ class CodeGenModule : public CodeGenTypeCache { std::unique_ptr<llvm::SpecialCaseList> SanitizerBlacklist; - const SanitizerOptions &SanOpts; - /// @} public: CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts, @@ -1014,7 +1012,10 @@ public: return *SanitizerBlacklist; } - const SanitizerOptions &getSanOpts() const { return SanOpts; } + const SanitizerOptions &getSanOpts() const { + return SanitizerBlacklist->isIn(TheModule) ? SanitizerOptions::Disabled + : LangOpts.Sanitize; + } void reportGlobalToASan(llvm::GlobalVariable *GV, SourceLocation Loc, bool IsDynInit = false); |