File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
clang/unittests/Analysis/FlowSensitive Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -3953,6 +3953,33 @@ TEST(TransferTest, PointerEquality) {
3953
3953
});
3954
3954
}
3955
3955
3956
+ TEST (TransferTest, PointerEqualityUnionMembers) {
3957
+ std::string Code = R"(
3958
+ union U {
3959
+ int i1;
3960
+ int i2;
3961
+ };
3962
+ void target() {
3963
+ U u;
3964
+ bool i1_eq_i2 = (&u.i1 == &u.i2);
3965
+
3966
+ (void)0; // [[p]]
3967
+ }
3968
+ )" ;
3969
+ runDataflow (
3970
+ Code,
3971
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
3972
+ ASTContext &ASTCtx) {
3973
+ const Environment &Env = getEnvironmentAtAnnotation (Results, " p" );
3974
+
3975
+ // FIXME: By the standard, `u.i1` and `u.i2` should have the same
3976
+ // address, but we don't yet model this property of union members
3977
+ // correctly. This test documents the current wrong behavior.
3978
+ EXPECT_EQ (&getValueForDecl<BoolValue>(ASTCtx, Env, " i1_eq_i2" ),
3979
+ &Env.getBoolLiteralValue (false ));
3980
+ });
3981
+ }
3982
+
3956
3983
TEST (TransferTest, IntegerLiteralEquality) {
3957
3984
std::string Code = R"(
3958
3985
void target() {
You can’t perform that action at this time.
0 commit comments