diff options
| author | John McCall <rjmccall@apple.com> | 2010-05-07 21:34:32 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2010-05-07 21:34:32 +0000 |
| commit | eb3e4f3481e817f2da33235fbc902c0d9a3541fa (patch) | |
| tree | 83eccda076f2fd29486c7e878e3ac39e33dd6bf6 /clang/lib/AST/ExprConstant.cpp | |
| parent | 06f0e097568b647a31338861f3a8adcbb021c4d4 (diff) | |
| download | bcm5719-llvm-eb3e4f3481e817f2da33235fbc902c0d9a3541fa.tar.gz bcm5719-llvm-eb3e4f3481e817f2da33235fbc902c0d9a3541fa.zip | |
Make that null-dereference fix a little clearer by rearranging some code.
llvm-svn: 103298
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
| -rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index c534d03a5ed..30eaae14d71 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -113,12 +113,24 @@ static bool EvaluateComplex(const Expr *E, ComplexValue &Res, EvalInfo &Info); static bool EvalPointerValueAsBool(LValue& Value, bool& Result) { const Expr* Base = Value.Base; - Result = Base || !Value.Offset.isZero(); + // A null base expression indicates a null pointer. These are always + // evaluatable, and they are false unless the offset is zero. + if (!Base) { + Result = !Value.Offset.isZero(); + return true; + } + + // We have a non-null base expression. These are generally known to + // be true, but if it'a decl-ref to a weak symbol it can be null at + // runtime. + + Result = true; - const DeclRefExpr* DeclRef = dyn_cast_or_null<DeclRefExpr>(Base); + const DeclRefExpr* DeclRef = dyn_cast<DeclRefExpr>(Base); if (!DeclRef) return true; + // If it's a weak symbol, it isn't constant-evaluable. const ValueDecl* Decl = DeclRef->getDecl(); if (Decl->hasAttr<WeakAttr>() || Decl->hasAttr<WeakRefAttr>() || |

