diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2010-05-07 15:18:43 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2010-05-07 15:18:43 +0000 |
commit | a7d3c04fcfe9d4af2f7758f46aef26b1a8f8ac09 (patch) | |
tree | a4af21aa17e871ab40dbcf20bcabb117380cb4cb /lib/AST/ExprConstant.cpp | |
parent | 565f8d6cc0c5e5a14fa9a8c93970e23378307ff7 (diff) |
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
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 30ef6f3aec..7f831737d1 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -70,9 +70,20 @@ static bool EvaluateComplex(const Expr *E, APValue &Result, EvalInfo &Info); //===----------------------------------------------------------------------===// 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; } |