diff options
author | Discookie <viktor.cseh@ericsson.com> | 2025-03-04 10:38:06 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-04 10:38:06 +0000 |
commit | 680391f07a45272bb9bfd385cf4c6846b8be32dd (patch) | |
tree | d19eeadce95981dc3e1df75ec399f78e278bb768 /clang/unittests/Analysis/FlowSensitive/TransferTest.cpp | |
parent | e27b8b2eda767eb59d3d605d288e733b154a48c5 (diff) | |
download | llvm-680391f07a45272bb9bfd385cf4c6846b8be32dd.zip llvm-680391f07a45272bb9bfd385cf4c6846b8be32dd.tar.gz llvm-680391f07a45272bb9bfd385cf4c6846b8be32dd.tar.bz2 |
[clang][dataflow] Fix unsupported types always being equal (#129502)
Previously when the framework encountered unsupported values (such as
enum classes), they were always treated as equal when comparing with
`==`, regardless of their actual values being different.
Now the two sides are only equal if there's a Value assigned to them.
Added a Value assignment for `nullptr`, to handle the special case of
`nullptr == nullptr`.
Diffstat (limited to 'clang/unittests/Analysis/FlowSensitive/TransferTest.cpp')
-rw-r--r-- | clang/unittests/Analysis/FlowSensitive/TransferTest.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index 0f731f4..f52b73d 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -4974,6 +4974,41 @@ TEST(TransferTest, IntegerLiteralEquality) { }); } +TEST(TransferTest, UnsupportedValueEquality) { + std::string Code = R"( + // An explicitly unsupported type by the framework. + enum class EC { + A, + B + }; + + void target() { + EC ec = EC::A; + + bool unsupported_eq_same = (EC::A == EC::A); + bool unsupported_eq_other = (EC::A == EC::B); + bool unsupported_eq_var = (ec == EC::B); + + (void)0; // [[p]] + } + )"; + runDataflow( + Code, + [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results, + ASTContext &ASTCtx) { + const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); + + // We do not model the values of unsupported types, so this + // seemingly-trivial case will not be true either. + EXPECT_TRUE(isa<AtomicBoolValue>( + getValueForDecl<BoolValue>(ASTCtx, Env, "unsupported_eq_same"))); + EXPECT_TRUE(isa<AtomicBoolValue>( + getValueForDecl<BoolValue>(ASTCtx, Env, "unsupported_eq_other"))); + EXPECT_TRUE(isa<AtomicBoolValue>( + getValueForDecl<BoolValue>(ASTCtx, Env, "unsupported_eq_var"))); + }); +} + TEST(TransferTest, CorrelatedBranches) { std::string Code = R"( void target(bool B, bool C) { |