[clang] [SSAF][WPA] Add a lit test for the WPA improvement of #198889 (PR #204018)
Ziqing Luo via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 15 16:01:54 PDT 2026
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/204018
This commit adds a lit test, which is an example of the issue solved by #198889 and was discovered independently when applying the analysis to a real project.
rdar://179754164
>From 4c3f839fdba0486a5443da80811ec17130fbfb6e Mon Sep 17 00:00:00 2001
From: Ziqing Luo <ziqing_luo at apple.com>
Date: Mon, 15 Jun 2026 15:37:26 -0700
Subject: [PATCH] [SSAF][WPA] Add a lit test for the WPA improvement of #198889
This commit adds a lit test, which is an example of the issue solved
by #198889 and was discovered independently when applying the analysis
to a real project.
rdar://179754164
---
.../multi-dim-pointer-flow-constraint.test | 41 +++++++++++++++++++
1 file changed, 41 insertions(+)
create mode 100644 clang/test/Analysis/Scalable/PointerFlow/multi-dim-pointer-flow-constraint.test
diff --git a/clang/test/Analysis/Scalable/PointerFlow/multi-dim-pointer-flow-constraint.test b/clang/test/Analysis/Scalable/PointerFlow/multi-dim-pointer-flow-constraint.test
new file mode 100644
index 0000000000000..511b375c05f6c
--- /dev/null
+++ b/clang/test/Analysis/Scalable/PointerFlow/multi-dim-pointer-flow-constraint.test
@@ -0,0 +1,41 @@
+// Test that a node '(a, 2)' can propagate to node '(b, 2)' through an edge '(a, 1) -> (b, 1)'
+// properly.
+
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: split-file %s %t
+
+
+// RUN: %clang_cc1 -fsyntax-only %t/src.cpp \
+// RUN: --ssaf-extract-summaries=PointerFlow,UnsafeBufferUsage \
+// RUN: --ssaf-compilation-unit-id="tu-1" \
+// RUN: --ssaf-tu-summary-file=%t/src.summary.json
+
+// RUN: clang-ssaf-linker %t/src.summary.json -o %t/lu.json
+
+// RUN: clang-ssaf-analyzer %t/lu.json -o %t/wpa.json \
+// RUN: -a UnsafeBufferReachableAnalysisResult
+
+// RUN: FileCheck %s --input-file=%t/wpa.json
+
+//--- src.cpp
+void foo(char **bufs, char **vlines, int i, int j) {
+ bufs[i] = nullptr; // unsafe at (bufs, 1)
+ bufs[i][j] = 0; // unsafe at (bufs, 2)
+ bufs = vlines; // PFG: (bufs, 1) -> (vlines, 1)
+}
+
+// Check that both (vlines, 1) and (vlines, 2) are in the reachable
+// set of unsafe buffers.
+
+// CHECK-DAG: "id": [[bufs_ID:[0-9]+]],{{([^]]|[[:space:]])+\],[[:space:]]+"suffix": "1",[[:space:]]+"usr": }}"c:@F at foo#**C#S0_#I#I#"
+// CHECK-DAG: "id": [[vlines_ID:[0-9]+]],{{([^]]|[[:space:]])+\],[[:space:]]+"suffix": "2",[[:space:]]+"usr": }}"c:@F at foo#**C#S0_#I#I#"
+
+// CHECK: "analysis_name": "UnsafeBufferReachableAnalysisResult"
+
+// CHECK-DAG: {{\{[[:space:]]+}}"@": [[bufs_ID]]{{[[:space:]]+\},[[:space:]]+1[[:space:]]+\]}}
+// CHECK-DAG: {{\{[[:space:]]+}}"@": [[bufs_ID]]{{[[:space:]]+\},[[:space:]]+2[[:space:]]+\]}}
+// CHECK-DAG: {{\{[[:space:]]+}}"@": [[vlines_ID]]{{[[:space:]]+\},[[:space:]]+1[[:space:]]+\]}}
+// CHECK-DAG: {{\{[[:space:]]+}}"@": [[vlines_ID]]{{[[:space:]]+\},[[:space:]]+2[[:space:]]+\]}}
+// CHECK-NOT: {{\{[[:space:]]+}}"@": {{[0-9]+[[:space:]]+\},[[:space:]]+3[[:space:]]+\]}}
+
+// CHECK: "analysis_name":
\ No newline at end of file
More information about the cfe-commits
mailing list