Fix PR4386 by implementing gcc's old behaviour (4.2) when initializing
variables with a comparison of a function pointer with 0.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103253 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 30ef6f3..7f83173 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -70,9 +70,20 @@
 //===----------------------------------------------------------------------===//
 
 static bool EvalPointerValueAsBool(APValue& Value, bool& Result) {
-  // FIXME: Is this accurate for all kinds of bases?  If not, what would
-  // the check look like?
-  Result = Value.getLValueBase() || !Value.getLValueOffset().isZero();
+  const Expr* Base = Value.getLValueBase();
+
+  Result = Base || !Value.getLValueOffset().isZero();
+
+  const DeclRefExpr* DeclRef = dyn_cast<DeclRefExpr>(Base);
+  if (!DeclRef)
+    return true;
+
+  const ValueDecl* Decl = DeclRef->getDecl();
+  if (Decl->hasAttr<WeakAttr>() ||
+      Decl->hasAttr<WeakRefAttr>() ||
+      Decl->hasAttr<WeakImportAttr>())
+    return false;
+
   return true;
 }