Fix PR4386 by implementing gcc's old behaviour (4.2) when initializing
variables with a comparison of a function pointer with 0.
llvm-svn: 103253
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 30ef6f3..7f83173 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/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;
}