[clang] 2825342 - [clang][dataflow] Handle `AtomicExpr` in `ResultObjectVisitor`. (#94963)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 10 23:38:07 PDT 2024
Author: martinboehme
Date: 2024-06-11T08:38:03+02:00
New Revision: 282534268e3be0949fcac1589b1004bc5672b434
URL: https://github.com/llvm/llvm-project/commit/282534268e3be0949fcac1589b1004bc5672b434
DIFF: https://github.com/llvm/llvm-project/commit/282534268e3be0949fcac1589b1004bc5672b434.diff
LOG: [clang][dataflow] Handle `AtomicExpr` in `ResultObjectVisitor`. (#94963)
This is one of the node kinds that should be considered an "original
initializer". The patch adds a test that was causing an assertion
failure in
`assert(Children.size() == 1)` without the fix.
Added:
Modified:
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 0d7967c8b9344..7c88917faf9c6 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -415,7 +415,7 @@ class ResultObjectVisitor : public AnalysisASTVisitor<ResultObjectVisitor> {
// below them can initialize the same object (or part of it).
if (isa<CXXConstructExpr>(E) || isa<CallExpr>(E) || isa<LambdaExpr>(E) ||
isa<CXXDefaultArgExpr>(E) || isa<CXXDefaultInitExpr>(E) ||
- isa<CXXStdInitializerListExpr>(E) ||
+ isa<CXXStdInitializerListExpr>(E) || isa<AtomicExpr>(E) ||
// We treat `BuiltinBitCastExpr` as an "original initializer" too as
// it may not even be casting from a record type -- and even if it is,
// the two objects are in general of unrelated type.
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index f7e6b0c22e8db..2a74d7fa63fd7 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3345,6 +3345,32 @@ TEST(TransferTest, ResultObjectLocationForBuiltinBitCastExpr) {
});
}
+TEST(TransferTest, ResultObjectLocationForAtomicExpr) {
+ std::string Code = R"(
+ struct S {};
+ void target(_Atomic(S) *ptr) {
+ S s = __c11_atomic_load(ptr, __ATOMIC_SEQ_CST);
+ // [[p]]
+ }
+ )";
+ using ast_matchers::atomicExpr;
+ 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 *Atomic = selectFirst<AtomicExpr>(
+ "atomic", match(atomicExpr().bind("atomic"), ASTCtx));
+
+ EXPECT_EQ(&Env.getResultObjectLocation(*Atomic),
+ &getLocForDecl<RecordStorageLocation>(ASTCtx, Env, "s"));
+ });
+}
+
TEST(TransferTest, ResultObjectLocationPropagatesThroughConditionalOperator) {
std::string Code = R"(
struct A {
More information about the cfe-commits
mailing list