[cfe-commits] r103298 - /cfe/trunk/lib/AST/ExprConstant.cpp

John McCall rjmccall at apple.com
Fri May 7 14:34:32 PDT 2010


Author: rjmccall
Date: Fri May  7 16:34:32 2010
New Revision: 103298

URL: http://llvm.org/viewvc/llvm-project?rev=103298&view=rev
Log:
Make that null-dereference fix a little clearer by rearranging some code.


Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=103298&r1=103297&r2=103298&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri May  7 16:34:32 2010
@@ -113,12 +113,24 @@
 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>() ||





More information about the cfe-commits mailing list