[PATCH] Fix PR19195
Karthik Bhat
kv.bhat at samsung.com
Tue Apr 1 04:22:57 PDT 2014
Hi rsmith, nicholas, bkramer,
Hi All,
A small patch ti fix PR19195. A call to getExpr from CXXDefaultInitExpr can return null in case we have not yet parsed and attached the in class initializer like in this test case.
Check if getExpr returns null and handle the same to prevent a crash during dynamic cast in StmtVisitor.
It would be great if someone could review the same and let me know if this is good for commit.
Thanks
Karthik Bhat
http://llvm-reviews.chandlerc.com/D3243
Files:
test/CodeGenCXX/pr19195.cpp
lib/CodeGen/CGExprScalar.cpp
lib/CodeGen/CGDecl.cpp
Index: test/CodeGenCXX/pr19195.cpp
===================================================================
--- test/CodeGenCXX/pr19195.cpp
+++ test/CodeGenCXX/pr19195.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++11 -emit-llvm-only %s -o %t
+/* Testcase for PR19195 - clang hits assert during in class initialization */
+
+class Cls {
+ Cls();
+ template <typename> struct Templ {
+ Templ() {}
+ int initialized_member = 0;
+ };
+ Templ<int> trigger_instantiation;
+};
+Cls::Cls() {}
Index: lib/CodeGen/CGExprScalar.cpp
===================================================================
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -349,6 +349,8 @@
}
Value *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) {
CodeGenFunction::CXXDefaultInitExprScope Scope(CGF);
+ if(!DIE->getExpr())
+ return 0;
return Visit(DIE->getExpr());
}
Value *VisitCXXThisExpr(CXXThisExpr *TE) {
Index: lib/CodeGen/CGDecl.cpp
===================================================================
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -571,6 +571,8 @@
Qualifiers::ObjCLifetime lifetime = lvalue.getObjCLifetime();
if (!lifetime) {
llvm::Value *value = EmitScalarExpr(init);
+ if (!value)
+ return;
if (capturedByInit)
drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D));
EmitStoreThroughLValue(RValue::get(value), lvalue, true);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3243.1.patch
Type: text/x-patch
Size: 1424 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140401/56a4a3ae/attachment.bin>
More information about the cfe-commits
mailing list