[clang] [analyzer] performTrivialCopy triggers checkLocation before binding (PR #129016)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 28 06:19:26 PST 2025


================
@@ -84,4 +118,24 @@ TEST(ExprEngineVisitTest, checkPostStmtGCCAsmStmt) {
   EXPECT_EQ(Diags, "ExprEngineVisitPostChecker: checkPostStmt<GCCAsmStmt>\n");
 }
 
+TEST(ExprEngineVisitTest, checkLocationAndBind) {
+  std::string Diags;
+  EXPECT_TRUE(runCheckerOnCode<addMemAccessChecker>(R"(
+    class MyClass{
+    public:
+      int Value;
+    };
+    extern MyClass MyClassWrite, MyClassRead; 
+    void top() {
+      MyClassWrite = MyClassRead;
+    }
+  )",
+                                                    Diags));
+
+  std::string RHSMsg = "checkLocation: Loc = MyClassRead";
+  std::string LHSMsg = "checkBind: Loc = MyClassWrite";
+  EXPECT_NE(Diags.find(RHSMsg), std::string::npos);
+  EXPECT_NE(Diags.find(LHSMsg), std::string::npos);
----------------
steakhal wrote:

I think it makes sense to enforce the ordering: first checkLocation should see a load event, then the checkBind should see the store side effect of the assignment.

https://github.com/llvm/llvm-project/pull/129016


More information about the cfe-commits mailing list