r297129 - [analyzer] Fix crash when building CFG with variable of incomplete type
Martin Bohme via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 7 00:42:38 PST 2017
Author: mboehme
Date: Tue Mar 7 02:42:37 2017
New Revision: 297129
URL: http://llvm.org/viewvc/llvm-project?rev=297129&view=rev
Log:
[analyzer] Fix crash when building CFG with variable of incomplete type
Summary:
I've included a unit test with a function template containing a variable
of incomplete type. Clang compiles this without errors (the standard
does not require a diagnostic in this case). Without the fix, this case
triggers the crash.
Reviewers: klimek
Reviewed By: klimek
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D30636
Modified:
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/unittests/Analysis/CFGTest.cpp
Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=297129&r1=297128&r2=297129&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Tue Mar 7 02:42:37 2017
@@ -1390,7 +1390,7 @@ LocalScope* CFGBuilder::addLocalScopeFor
// 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);
Modified: cfe/trunk/unittests/Analysis/CFGTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Analysis/CFGTest.cpp?rev=297129&r1=297128&r2=297129&view=diff
==============================================================================
--- cfe/trunk/unittests/Analysis/CFGTest.cpp (original)
+++ cfe/trunk/unittests/Analysis/CFGTest.cpp Tue Mar 7 02:42:37 2017
@@ -35,7 +35,9 @@ public:
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;
}
};
@@ -74,6 +76,16 @@ TEST(CFG, DeleteExpressionOnDependentTyp
"}\n";
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
More information about the cfe-commits
mailing list