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
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 4dd49c9..781ffa6 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -270,16 +270,17 @@
          !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 @@
     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;