-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang][dataflow] Handle AtomicExpr
in ResultObjectVisitor
.
#94963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][dataflow] Handle AtomicExpr
in ResultObjectVisitor
.
#94963
Conversation
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.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-analysis Author: None (martinboehme) ChangesThis is one of the node kinds that should be considered an "original Full diff: https://github.com/llvm/llvm-project/pull/94963.diff 2 Files Affected:
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 {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…#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.
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.