aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
diff options
context:
space:
mode:
authormartinboehme <mboehme@google.com>2024-04-17 08:17:56 +0200
committerGitHub <noreply@github.com>2024-04-17 08:17:56 +0200
commit1bccbe1f49abc39b9f980cf3f1b171da5541d1a4 (patch)
tree65ec2f771c9887ca64631cdfb356494fe7e6a9a6 /clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
parent47148832d4e3bf4901430732f1af6673147accb2 (diff)
downloadllvm-1bccbe1f49abc39b9f980cf3f1b171da5541d1a4.zip
llvm-1bccbe1f49abc39b9f980cf3f1b171da5541d1a4.tar.gz
llvm-1bccbe1f49abc39b9f980cf3f1b171da5541d1a4.tar.bz2
[clang][dataflow] Treat `BuiltinBitCastExpr` correctly in `PropagateResultObject()`. (#88875)
This patch includes a test that assert-fails without the fix.
Diffstat (limited to 'clang/unittests/Analysis/FlowSensitive/TransferTest.cpp')
-rw-r--r--clang/unittests/Analysis/FlowSensitive/TransferTest.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index d7a51b0..97ec321 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3208,6 +3208,32 @@ TEST(TransferTest, ResultObjectLocationForStmtExpr) {
});
}
+TEST(TransferTest, ResultObjectLocationForBuiltinBitCastExpr) {
+ std::string Code = R"(
+ struct S { int i; };
+ void target(int i) {
+ S s = __builtin_bit_cast(S, i);
+ // [[p]]
+ }
+ )";
+ using ast_matchers::explicitCastExpr;
+ using ast_matchers::match;
+ using ast_matchers::selectFirst;
+ using ast_matchers::traverse;
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ ASTContext &ASTCtx) {
+ const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+ auto *BuiltinBitCast = selectFirst<BuiltinBitCastExpr>(
+ "cast", match(explicitCastExpr().bind("cast"), ASTCtx));
+
+ EXPECT_EQ(&Env.getResultObjectLocation(*BuiltinBitCast),
+ &getLocForDecl<RecordStorageLocation>(ASTCtx, Env, "s"));
+ });
+}
+
TEST(TransferTest, ResultObjectLocationPropagatesThroughConditionalOperator) {
std::string Code = R"(
struct A {