[PATCH] D155074: [clang][dataflow] Add a test for not explicitly initialized fields in aggregate initialization.
Martin Böhme via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 17 00:26:41 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4782597e3cd1: [clang][dataflow] Add a test for not explicitly initialized fields in aggregate… (authored by mboehme).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D155074/new/
https://reviews.llvm.org/D155074
Files:
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
@@ -2944,6 +2944,39 @@
});
}
+TEST(TransferTest, AggregateInitialization_NotExplicitlyInitializedField) {
+ std::string Code = R"(
+ struct S {
+ int i1;
+ int i2;
+ };
+
+ void target(int i) {
+ S s = { i };
+ /*[[p]]*/
+ }
+ )";
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ const ValueDecl *I1FieldDecl = findValueDecl(ASTCtx, "i1");
+ const ValueDecl *I2FieldDecl = findValueDecl(ASTCtx, "i2");
+
+ auto &SLoc = getLocForDecl<AggregateStorageLocation>(ASTCtx, Env, "s");
+
+ auto &IValue = getValueForDecl<IntegerValue>(ASTCtx, Env, "i");
+ auto &I1Value =
+ *cast<IntegerValue>(getFieldValue(&SLoc, *I1FieldDecl, Env));
+ EXPECT_EQ(&I1Value, &IValue);
+ auto &I2Value =
+ *cast<IntegerValue>(getFieldValue(&SLoc, *I2FieldDecl, Env));
+ EXPECT_NE(&I2Value, &IValue);
+ });
+}
+
TEST(TransferTest, AssignToUnionMember) {
std::string Code = R"(
union A {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155074.540880.patch
Type: text/x-patch
Size: 1417 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230717/036577d8/attachment.bin>
More information about the cfe-commits
mailing list