[PATCH] [Patch] Fix for crash in nsdmi-defer6.C (PR15721)

Karthik Bhat kv.bhat at samsung.com
Fri Sep 13 07:38:20 PDT 2013


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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1678.1.patch
Type: text/x-patch
Size: 968 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130913/4fd064a3/attachment.bin>


More information about the cfe-commits mailing list