[PATCH] D30636: [analyzer] Fix crash when building CFG with variable of incomplete type

Martin Böhme via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 7 00:54:47 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL297129: [analyzer] Fix crash when building CFG with variable of incomplete type (authored by mboehme).

Changed prior to commit:
  https://reviews.llvm.org/D30636?vs=90660&id=90810#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30636

Files:
  cfe/trunk/lib/Analysis/CFG.cpp
  cfe/trunk/unittests/Analysis/CFGTest.cpp


Index: cfe/trunk/lib/Analysis/CFG.cpp
===================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp
+++ cfe/trunk/lib/Analysis/CFG.cpp
@@ -1390,7 +1390,7 @@
 
   // Check if type is a C++ class with non-trivial destructor.
   if (const CXXRecordDecl *CD = QT->getAsCXXRecordDecl())
-    if (!CD->hasTrivialDestructor()) {
+    if (CD->hasDefinition() && !CD->hasTrivialDestructor()) {
       // Add the variable to scope
       Scope = createOrReuseLocalScope(Scope);
       Scope->addVar(VD);
Index: cfe/trunk/unittests/Analysis/CFGTest.cpp
===================================================================
--- cfe/trunk/unittests/Analysis/CFGTest.cpp
+++ cfe/trunk/unittests/Analysis/CFGTest.cpp
@@ -35,7 +35,9 @@
     if (!Body)
       return;
     TheBuildResult = SawFunctionBody;
-    if (CFG::buildCFG(nullptr, Body, Result.Context, CFG::BuildOptions()))
+    CFG::BuildOptions Options;
+    Options.AddImplicitDtors = true;
+    if (CFG::buildCFG(nullptr, Body, Result.Context, Options))
         TheBuildResult = BuiltCFG;
   }
 };
@@ -75,6 +77,16 @@
   EXPECT_EQ(BuiltCFG, BuildCFG(Code));
 }
 
+// Constructing a CFG on a function template with a variable of incomplete type
+// should not crash.
+TEST(CFG, VariableOfIncompleteType) {
+  const char *Code = "template<class T> void f() {\n"
+                     "  class Undefined;\n"
+                     "  Undefined u;\n"
+                     "}\n";
+  EXPECT_EQ(BuiltCFG, BuildCFG(Code));
+}
+
 } // namespace
 } // namespace analysis
 } // namespace clang


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30636.90810.patch
Type: text/x-patch
Size: 1568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170307/536327a0/attachment.bin>


More information about the cfe-commits mailing list