Skip to content

Commit dd4aa8b

Browse files
committed
Add a test demonstrating that we don't yet model address equality of union
members correctly.
1 parent 32fe6eb commit dd4aa8b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3953,6 +3953,33 @@ TEST(TransferTest, PointerEquality) {
39533953
});
39543954
}
39553955

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+
39563983
TEST(TransferTest, IntegerLiteralEquality) {
39573984
std::string Code = R"(
39583985
void target() {

0 commit comments

Comments
 (0)