[clang] 4782597 - [clang][dataflow] Add a test for not explicitly initialized fields in aggregate initialization.
Martin Braenne via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 17 00:26:21 PDT 2023
Author: Martin Braenne
Date: 2023-07-17T07:26:08Z
New Revision: 4782597e3cd1b26cf8bd437e36fd6320f55d3d89
URL: https://github.com/llvm/llvm-project/commit/4782597e3cd1b26cf8bd437e36fd6320f55d3d89
DIFF: https://github.com/llvm/llvm-project/commit/4782597e3cd1b26cf8bd437e36fd6320f55d3d89.diff
LOG: [clang][dataflow] Add a test for not explicitly initialized fields in aggregate initialization.
Reviewed By: ymandel
Differential Revision: https://reviews.llvm.org/D155074
Added:
Modified:
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Removed:
################################################################################
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 5a5540cbaee3dc..e2800452ab6bdb 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2944,6 +2944,39 @@ TEST(TransferTest, AggregateInitializationReferenceField) {
});
}
+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 {
More information about the cfe-commits
mailing list