aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-11-01 21:06:14 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-11-01 21:06:14 +0000
commit65ac598c7ba7e36f2ad611f2bb39cc957053be5d (patch)
tree35e0864095caae7e184da77a337799d827b64f17 /lib/AST/ExprConstant.cpp
parent344d78d6a669fb324f89937fc0739f97670f4700 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143496 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r--lib/AST/ExprConstant.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 4dd49c9125..781ffa6fb4 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/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;