Hi rsmith, jordan_rose,

Hi,
Added a patch to fix crash in nsdmi-defer6.C mentioned in PR15721 
(http://llvm.org/bugs/show_bug.cgi?id=15721).

The reason for the crash seems to be because we are not handling case were 
initialization expression can be null in VisitCXXDefaultInitExpr.

Not handling this case results in a crash when we try to dynamic_cast a null 
pointer in Visit function.

Added code to handle case were initialization expression is null.

To reproduce the crash we can compile nsdmi-defer6.C (gcc cpp0x testsuite) with 
-std=c++11 option.

Please let me know your inputs on the same.
Thanks!


http://llvm-reviews.chandlerc.com/D1678

Files:
  lib/AST/ExprConstant.cpp

Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -3742,8 +3742,13 @@
     { return StmtVisitorTy::Visit(E->getReplacement()); }
   RetTy VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
     { return StmtVisitorTy::Visit(E->getExpr()); }
-  RetTy VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E)
-    { return StmtVisitorTy::Visit(E->getExpr()); }
+  RetTy VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E) {
+    // In case in-class initializer is not parsed and attached yet
+    // E->getExpr() will be null. Handle the same.
+    if (!E->getExpr())
+      return false;
+    return StmtVisitorTy::Visit(E->getExpr());
+  }
   // We cannot create any objects for which cleanups are required, so there is
   // nothing to do here; all cleanups must come from unevaluated 
subexpressions.
   RetTy VisitExprWithCleanups(const ExprWithCleanups *E)
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -3742,8 +3742,13 @@
     { return StmtVisitorTy::Visit(E->getReplacement()); }
   RetTy VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
     { return StmtVisitorTy::Visit(E->getExpr()); }
-  RetTy VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E)
-    { return StmtVisitorTy::Visit(E->getExpr()); }
+  RetTy VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E) {
+    // In case in-class initializer is not parsed and attached yet
+    // E->getExpr() will be null. Handle the same.
+    if (!E->getExpr())
+      return false;
+    return StmtVisitorTy::Visit(E->getExpr());
+  }
   // We cannot create any objects for which cleanups are required, so there is
   // nothing to do here; all cleanups must come from unevaluated subexpressions.
   RetTy VisitExprWithCleanups(const ExprWithCleanups *E)
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to