]> granicus.if.org Git - clang/commitdiff
Teach Expr::isNullPointerConstant() about ImplicitCastExpr's.
authorSteve Naroff <snaroff@apple.com>
Tue, 28 Aug 2007 21:20:34 +0000 (21:20 +0000)
committerSteve Naroff <snaroff@apple.com>
Tue, 28 Aug 2007 21:20:34 +0000 (21:20 +0000)
This fixes the following (recent) regression noticed by Keith Bauer (thanks!).

void func(void *a);

main() {
  void *p;
  p = 0;
  func(0);
}

...which now works as you would expect.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41557 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp

index cacfcfa0ca9e41daf9219501d9be9d183b5e1396..69ea9442ffad1c0dec10f897daee846fdcaa6186 100644 (file)
@@ -647,6 +647,14 @@ bool Expr::isNullPointerConstant(ASTContext &Ctx) const {
           CE->getSubExpr()->getType()->isIntegerType())            // from int.
         return CE->getSubExpr()->isNullPointerConstant(Ctx);
     }
+  } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
+    // Check that it is a cast to void*.
+    if (const PointerType *PT = dyn_cast<PointerType>(ICE->getType())) {
+      QualType Pointee = PT->getPointeeType();
+      if (Pointee.getQualifiers() == 0 && Pointee->isVoidType() && // to void*
+          ICE->getSubExpr()->getType()->isIntegerType())           // from int.
+        return ICE->getSubExpr()->isNullPointerConstant(Ctx);
+    }
   } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) {
     // Accept ((void*)0) as a null pointer constant, as many other
     // implementations do.