diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-11-01 21:06:14 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-11-01 21:06:14 +0000 |
commit | cecf184e64befbd160d7d0b42b2a10c7853f19f0 (patch) | |
tree | 929ea863dfba7166d4c9107c5082849ff64e163c /clang/lib/AST/ExprConstant.cpp | |
parent | 1f1f2d8ca39f038e6f6d52771efe62b319efcdb2 (diff) | |
download | bcm5719-llvm-cecf184e64befbd160d7d0b42b2a10c7853f19f0.tar.gz bcm5719-llvm-cecf184e64befbd160d7d0b42b2a10c7853f19f0.zip |
When constant-folding, don't look at the initializer of a global const variable
if it's marked as weak: that definition may not end up being used.
llvm-svn: 143496
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 4dd49c91250..781ffa6fb4d 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -270,16 +270,17 @@ static bool IsLiteralLValue(const LValue &Value) { !isa<MaterializeTemporaryExpr>(Value.Base); } -static bool IsWeakLValue(const LValue &Value) { - const ValueDecl *Decl = GetLValueBaseDecl(Value); - if (!Decl) - return false; - +static bool IsWeakDecl(const ValueDecl *Decl) { return Decl->hasAttr<WeakAttr>() || Decl->hasAttr<WeakRefAttr>() || Decl->isWeakImported(); } +static bool IsWeakLValue(const LValue &Value) { + const ValueDecl *Decl = GetLValueBaseDecl(Value); + return Decl && IsWeakDecl(Decl); +} + static bool EvalPointerValueAsBool(const LValue &Value, bool &Result) { const Expr* Base = Value.Base; @@ -394,6 +395,11 @@ static bool EvaluateVarDeclInit(EvalInfo &Info, const VarDecl *VD, return true; } + // Never evaluate the initializer of a weak variable. We can't be sure that + // this is the definition which will be used. + if (IsWeakDecl(VD)) + return false; + const Expr *Init = VD->getAnyInitializer(); if (!Init) return false; |