aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
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;