@@ -2153,4 +2153,171 @@ TEST_F(TransferTest, AssignFromBoolNegation) {
2153
2153
});
2154
2154
}
2155
2155
2156
+ TEST_F (TransferTest, StaticIntSingleVarDecl) {
2157
+ std::string Code = R"(
2158
+ void target() {
2159
+ static int Foo;
2160
+ // [[p]]
2161
+ }
2162
+ )" ;
2163
+ runDataflow (Code,
2164
+ [](llvm::ArrayRef<
2165
+ std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
2166
+ Results,
2167
+ ASTContext &ASTCtx) {
2168
+ ASSERT_THAT (Results, ElementsAre (Pair (" p" , _)));
2169
+ const Environment &Env = Results[0 ].second .Env ;
2170
+
2171
+ const ValueDecl *FooDecl = findValueDecl (ASTCtx, " Foo" );
2172
+ ASSERT_THAT (FooDecl, NotNull ());
2173
+
2174
+ const StorageLocation *FooLoc =
2175
+ Env.getStorageLocation (*FooDecl, SkipPast::None);
2176
+ ASSERT_TRUE (isa_and_nonnull<ScalarStorageLocation>(FooLoc));
2177
+
2178
+ const Value *FooVal = Env.getValue (*FooLoc);
2179
+ EXPECT_TRUE (isa_and_nonnull<IntegerValue>(FooVal));
2180
+ });
2181
+ }
2182
+
2183
+ TEST_F (TransferTest, StaticIntGroupVarDecl) {
2184
+ std::string Code = R"(
2185
+ void target() {
2186
+ static int Foo, Bar;
2187
+ (void)0;
2188
+ // [[p]]
2189
+ }
2190
+ )" ;
2191
+ runDataflow (Code,
2192
+ [](llvm::ArrayRef<
2193
+ std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
2194
+ Results,
2195
+ ASTContext &ASTCtx) {
2196
+ ASSERT_THAT (Results, ElementsAre (Pair (" p" , _)));
2197
+ const Environment &Env = Results[0 ].second .Env ;
2198
+
2199
+ const ValueDecl *FooDecl = findValueDecl (ASTCtx, " Foo" );
2200
+ ASSERT_THAT (FooDecl, NotNull ());
2201
+
2202
+ const ValueDecl *BarDecl = findValueDecl (ASTCtx, " Bar" );
2203
+ ASSERT_THAT (BarDecl, NotNull ());
2204
+
2205
+ const StorageLocation *FooLoc =
2206
+ Env.getStorageLocation (*FooDecl, SkipPast::None);
2207
+ ASSERT_TRUE (isa_and_nonnull<ScalarStorageLocation>(FooLoc));
2208
+
2209
+ const StorageLocation *BarLoc =
2210
+ Env.getStorageLocation (*BarDecl, SkipPast::None);
2211
+ ASSERT_TRUE (isa_and_nonnull<ScalarStorageLocation>(BarLoc));
2212
+
2213
+ const Value *FooVal = Env.getValue (*FooLoc);
2214
+ EXPECT_TRUE (isa_and_nonnull<IntegerValue>(FooVal));
2215
+
2216
+ const Value *BarVal = Env.getValue (*BarLoc);
2217
+ EXPECT_TRUE (isa_and_nonnull<IntegerValue>(BarVal));
2218
+
2219
+ EXPECT_NE (FooVal, BarVal);
2220
+ });
2221
+ }
2222
+
2223
+ TEST_F (TransferTest, GlobalIntVarDecl) {
2224
+ std::string Code = R"(
2225
+ static int Foo;
2226
+
2227
+ void target() {
2228
+ int Bar = Foo;
2229
+ int Baz = Foo;
2230
+ // [[p]]
2231
+ }
2232
+ )" ;
2233
+ runDataflow (Code,
2234
+ [](llvm::ArrayRef<
2235
+ std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
2236
+ Results,
2237
+ ASTContext &ASTCtx) {
2238
+ ASSERT_THAT (Results, ElementsAre (Pair (" p" , _)));
2239
+ const Environment &Env = Results[0 ].second .Env ;
2240
+
2241
+ const ValueDecl *BarDecl = findValueDecl (ASTCtx, " Bar" );
2242
+ ASSERT_THAT (BarDecl, NotNull ());
2243
+
2244
+ const ValueDecl *BazDecl = findValueDecl (ASTCtx, " Baz" );
2245
+ ASSERT_THAT (BazDecl, NotNull ());
2246
+
2247
+ const Value *BarVal =
2248
+ cast<IntegerValue>(Env.getValue (*BarDecl, SkipPast::None));
2249
+ const Value *BazVal =
2250
+ cast<IntegerValue>(Env.getValue (*BazDecl, SkipPast::None));
2251
+ EXPECT_EQ (BarVal, BazVal);
2252
+ });
2253
+ }
2254
+
2255
+ TEST_F (TransferTest, StaticMemberIntVarDecl) {
2256
+ std::string Code = R"(
2257
+ struct A {
2258
+ static int Foo;
2259
+ };
2260
+
2261
+ void target(A a) {
2262
+ int Bar = a.Foo;
2263
+ int Baz = a.Foo;
2264
+ // [[p]]
2265
+ }
2266
+ )" ;
2267
+ runDataflow (Code,
2268
+ [](llvm::ArrayRef<
2269
+ std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
2270
+ Results,
2271
+ ASTContext &ASTCtx) {
2272
+ ASSERT_THAT (Results, ElementsAre (Pair (" p" , _)));
2273
+ const Environment &Env = Results[0 ].second .Env ;
2274
+
2275
+ const ValueDecl *BarDecl = findValueDecl (ASTCtx, " Bar" );
2276
+ ASSERT_THAT (BarDecl, NotNull ());
2277
+
2278
+ const ValueDecl *BazDecl = findValueDecl (ASTCtx, " Baz" );
2279
+ ASSERT_THAT (BazDecl, NotNull ());
2280
+
2281
+ const Value *BarVal =
2282
+ cast<IntegerValue>(Env.getValue (*BarDecl, SkipPast::None));
2283
+ const Value *BazVal =
2284
+ cast<IntegerValue>(Env.getValue (*BazDecl, SkipPast::None));
2285
+ EXPECT_EQ (BarVal, BazVal);
2286
+ });
2287
+ }
2288
+
2289
+ TEST_F (TransferTest, StaticMemberRefVarDecl) {
2290
+ std::string Code = R"(
2291
+ struct A {
2292
+ static int &Foo;
2293
+ };
2294
+
2295
+ void target(A a) {
2296
+ int Bar = a.Foo;
2297
+ int Baz = a.Foo;
2298
+ // [[p]]
2299
+ }
2300
+ )" ;
2301
+ runDataflow (Code,
2302
+ [](llvm::ArrayRef<
2303
+ std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
2304
+ Results,
2305
+ ASTContext &ASTCtx) {
2306
+ ASSERT_THAT (Results, ElementsAre (Pair (" p" , _)));
2307
+ const Environment &Env = Results[0 ].second .Env ;
2308
+
2309
+ const ValueDecl *BarDecl = findValueDecl (ASTCtx, " Bar" );
2310
+ ASSERT_THAT (BarDecl, NotNull ());
2311
+
2312
+ const ValueDecl *BazDecl = findValueDecl (ASTCtx, " Baz" );
2313
+ ASSERT_THAT (BazDecl, NotNull ());
2314
+
2315
+ const Value *BarVal =
2316
+ cast<IntegerValue>(Env.getValue (*BarDecl, SkipPast::None));
2317
+ const Value *BazVal =
2318
+ cast<IntegerValue>(Env.getValue (*BazDecl, SkipPast::None));
2319
+ EXPECT_EQ (BarVal, BazVal);
2320
+ });
2321
+ }
2322
+
2156
2323
} // namespace
0 commit comments