From: Alexey Samsonov Date: Mon, 7 Jul 2014 23:59:57 +0000 (+0000) Subject: [Sanitizer] Remove brittle cache variable and slightly simplify blacklisting code. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ac4afe49e7b7d17a5b7f5e9872baccd8fb5c8a97;p=platform%2Fupstream%2Fllvm.git [Sanitizer] Remove brittle cache variable and slightly simplify blacklisting code. Now CodeGenFunction is responsible for looking at sanitizer blacklist (in CodeGenFunction::StartFunction) and turning off instrumentation, if necessary. No functionality change. llvm-svn: 212501 --- diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 62ecc73..c99e669 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -407,7 +407,7 @@ CodeGenFunction::EmitReferenceBindingToExpr(const Expr *E) { assert(LV.isSimple()); llvm::Value *Value = LV.getAddress(); - if (SanitizePerformTypeCheck && !E->getType()->isFunctionType()) { + if (sanitizePerformTypeCheck() && !E->getType()->isFunctionType()) { // C++11 [dcl.ref]p5 (as amended by core issue 453): // If a glvalue to which a reference is directly bound designates neither // an existing object or function of an appropriate type nor a region of @@ -441,10 +441,15 @@ static llvm::Value *emitHash16Bytes(CGBuilderTy &Builder, llvm::Value *Low, return Builder.CreateMul(B1, KMul); } +bool CodeGenFunction::sanitizePerformTypeCheck() const { + return SanOpts->Null | SanOpts->Alignment | SanOpts->ObjectSize | + SanOpts->Vptr; +} + void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *Address, QualType Ty, CharUnits Alignment) { - if (!SanitizePerformTypeCheck) + if (!sanitizePerformTypeCheck()) return; // Don't check pointers outside the default address space. The null check @@ -2877,7 +2882,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { // C++11 [expr.static.cast]p2: Behavior is undefined if a downcast is // performed and the object is not of the derived type. - if (SanitizePerformTypeCheck) + if (sanitizePerformTypeCheck()) EmitTypeCheck(TCK_DowncastReference, E->getExprLoc(), Derived, E->getType()); diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index a4abc0f..1be7b42 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -1328,7 +1328,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) { // C++11 [expr.static.cast]p11: Behavior is undefined if a downcast is // performed and the object is not of the derived type. - if (CGF.SanitizePerformTypeCheck) + if (CGF.sanitizePerformTypeCheck()) CGF.EmitTypeCheck(CodeGenFunction::TCK_DowncastPointer, CE->getExprLoc(), Derived, DestTy->getPointeeType()); diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 7de619e..4b202e13 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -37,11 +37,7 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext) : CodeGenTypeCache(cgm), CGM(cgm), Target(cgm.getTarget()), Builder(cgm.getModule().getContext(), llvm::ConstantFolder(), CGBuilderInserterTy(this)), CapturedStmtInfo(nullptr), - SanitizePerformTypeCheck(CGM.getSanOpts().Null | - CGM.getSanOpts().Alignment | - CGM.getSanOpts().ObjectSize | - CGM.getSanOpts().Vptr), - SanOpts(&CGM.getSanOpts()), AutoreleaseResult(false), BlockInfo(nullptr), + SanOpts(&CGM.getLangOpts().Sanitize), AutoreleaseResult(false), BlockInfo(nullptr), BlockPointer(nullptr), LambdaThisCaptureField(nullptr), NormalCleanupDest(nullptr), NextCleanupDestIndex(1), FirstBlockInfo(nullptr), EHResumeBlock(nullptr), ExceptionSlot(nullptr), @@ -539,10 +535,8 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, CurFnInfo = &FnInfo; assert(CurFn->isDeclaration() && "Function already has body?"); - if (CGM.getSanitizerBlacklist().isIn(*Fn)) { + if (CGM.getSanitizerBlacklist().isIn(*Fn)) SanOpts = &SanitizerOptions::Disabled; - SanitizePerformTypeCheck = false; - } // Pass inline keyword to optimizer if it appears explicitly on any // declaration. Also, in the case of -fno-inline attach NoInline diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 2d6d99a..6aa3f9a 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -231,10 +231,6 @@ public: /// potentially higher performance penalties. unsigned char BoundsChecking; - /// \brief Whether any type-checking sanitizers are enabled. If \c false, - /// calls to EmitTypeCheck can be skipped. - bool SanitizePerformTypeCheck; - /// \brief Sanitizer options to use for this function. const SanitizerOptions *SanOpts; @@ -1693,6 +1689,10 @@ public: TCK_DowncastReference }; + /// \brief Whether any type-checking sanitizers are enabled. If \c false, + /// calls to EmitTypeCheck can be skipped. + bool sanitizePerformTypeCheck() const; + /// \brief Emit a check that \p V is the address of storage of the /// appropriate size and alignment for an object of type \p Type. void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 2f60518..bb4c010 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -1012,11 +1012,6 @@ public: return *SanitizerBlacklist; } - const SanitizerOptions &getSanOpts() const { - return SanitizerBlacklist->isIn(TheModule) ? SanitizerOptions::Disabled - : LangOpts.Sanitize; - } - void reportGlobalToASan(llvm::GlobalVariable *GV, SourceLocation Loc, bool IsDynInit = false);