[PATCH] D156402: [clang][dataflow] Don't crash when constructing an array of records.
Martin Böhme via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 27 05:46:28 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe6e83cbcc748: [clang][dataflow] Don't crash when constructing an array of records. (authored by mboehme).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156402/new/
https://reviews.llvm.org/D156402
Files:
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===================================================================
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -310,6 +310,28 @@
});
}
+TEST(TransferTest, StructArrayVarDecl) {
+ std::string Code = R"(
+ struct A {};
+
+ void target() {
+ A Array[2];
+ // [[p]]
+ }
+ )";
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *ArrayDecl = findValueDecl(ASTCtx, "Array");
+
+ // We currently don't create values for arrays.
+ ASSERT_THAT(Env.getValue(*ArrayDecl), IsNull());
+ });
+}
+
TEST(TransferTest, ClassVarDecl) {
std::string Code = R"(
class A {
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -500,9 +500,14 @@
return;
}
- auto &InitialVal = *cast<StructValue>(Env.createValue(S->getType()));
- copyRecord(InitialVal.getAggregateLoc(), Env.getResultObjectLocation(*S),
- Env);
+ // `CXXConstructExpr` can have array type if default-initializing an array
+ // of records, and we currently can't create values for arrays. So check if
+ // we've got a record type.
+ if (S->getType()->isRecordType()) {
+ auto &InitialVal = *cast<StructValue>(Env.createValue(S->getType()));
+ copyRecord(InitialVal.getAggregateLoc(), Env.getResultObjectLocation(*S),
+ Env);
+ }
transferInlineCall(S, ConstructorDecl);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156402.544727.patch
Type: text/x-patch
Size: 1861 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230727/29796a3b/attachment.bin>
More information about the cfe-commits
mailing list