llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-analysis Author: None (martinboehme) <details> <summary>Changes</summary> 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. --- Full diff: https://github.com/llvm/llvm-project/pull/94963.diff 2 Files Affected: - (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+1-1) - (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+26) ``````````diff 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 { `````````` </details> https://github.com/llvm/llvm-project/pull/94963 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits