[clang] 7cb5d89 - [SSAF][UnsafeBufferAnalysis] Do not create entries for empty contributors (follow-up change on #209354) (#216526)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 16 13:00:02 PDT 2026
Author: Ziqing Luo
Date: 2026-08-16T12:59:58-07:00
New Revision: 7cb5d896117ccd4142cd7a7bde284ea3392dd3b4
URL: https://github.com/llvm/llvm-project/commit/7cb5d896117ccd4142cd7a7bde284ea3392dd3b4
DIFF: https://github.com/llvm/llvm-project/commit/7cb5d896117ccd4142cd7a7bde284ea3392dd3b4.diff
LOG: [SSAF][UnsafeBufferAnalysis] Do not create entries for empty contributors (follow-up change on #209354) (#216526)
Address follow up questions after the approval.
- The analysis should not create entries for empty contributors, which
otherwise is non-empty in the serialized format.
- use std IO instead of a tmp file for regex-ing FileCheck queries.
rdar://179151541 and rdar://179151882
Added:
Modified:
clang/lib/ScalableStaticAnalysis/Analyses/UnsafeBufferUsage/UnsafeBufferUsageAnalysis.cpp
clang/test/Analysis/Scalable/TypeConstrainedPointers/unsafe-buffer-reachable-excludes-type-constrained-main.cpp
clang/test/Analysis/Scalable/TypeConstrainedPointers/unsafe-buffer-reachable-excludes-type-constrained-new-delete.cpp
Removed:
################################################################################
diff --git a/clang/lib/ScalableStaticAnalysis/Analyses/UnsafeBufferUsage/UnsafeBufferUsageAnalysis.cpp b/clang/lib/ScalableStaticAnalysis/Analyses/UnsafeBufferUsage/UnsafeBufferUsageAnalysis.cpp
index 664eba23f3bb0..4c92a37a078d1 100644
--- a/clang/lib/ScalableStaticAnalysis/Analyses/UnsafeBufferUsage/UnsafeBufferUsageAnalysis.cpp
+++ b/clang/lib/ScalableStaticAnalysis/Analyses/UnsafeBufferUsage/UnsafeBufferUsageAnalysis.cpp
@@ -272,8 +272,9 @@ class UnsafeBufferReachableAnalysis
for (auto &[Contributor, EPLs] : UnsafePtrs) {
auto FilteredRange = llvm::make_filter_range(EPLs, HasNoTypeConstraint);
- getResult().Reachables[Contributor].insert(FilteredRange.begin(),
- FilteredRange.end());
+ if (!FilteredRange.empty())
+ getResult().Reachables[Contributor].insert(FilteredRange.begin(),
+ FilteredRange.end());
}
return llvm::Error::success();
}
diff --git a/clang/test/Analysis/Scalable/TypeConstrainedPointers/unsafe-buffer-reachable-excludes-type-constrained-main.cpp b/clang/test/Analysis/Scalable/TypeConstrainedPointers/unsafe-buffer-reachable-excludes-type-constrained-main.cpp
index 95eff21fbb0e5..91449e2511aa2 100644
--- a/clang/test/Analysis/Scalable/TypeConstrainedPointers/unsafe-buffer-reachable-excludes-type-constrained-main.cpp
+++ b/clang/test/Analysis/Scalable/TypeConstrainedPointers/unsafe-buffer-reachable-excludes-type-constrained-main.cpp
@@ -20,8 +20,7 @@
// RUN: sed -e 's|$NS|{{([^]]\|[[:space:]])+\\],}}|g' \
// RUN: -e 's|$WS|{{[[:space:]]+}}|g' \
// RUN: -e 's|$PTR_L1|{{[[:space:]]+\\},[[:space:]]+1[[:space:]]+\\]}}|g' \
-// RUN: %s > %t/checks.txt
-// RUN: FileCheck %t/checks.txt --input-file=%t/wpa.json
+// RUN: %s | FileCheck - --input-file=%t/wpa.json
int main(int argc, char **argv) {
@@ -37,9 +36,9 @@ void foo(int *q) {
// CHECK-DAG: "id": [[Q_ID:[0-9]+]],$NS$WS"suffix": "1",$WS"usr": "c:@F at foo#*I#"
// CHECK-DAG: "id": [[ARGV_ID:[0-9]+]],$NS$WS"suffix": "2",$WS"usr": "c:@F at main{{.*}}"
-// Contributor function ids:
+// Contributor function id (main contributes nothing in the end thus absent):
// CHECK-DAG: "id": [[CONTRIBUTOR_FOO:[0-9]+]],$NS$WS"suffix": "",$WS"usr": "c:@F at foo#*I#"
-// CHECK-DAG: "id": [[CONTRIBUTOR_MAIN:[0-9]+]],$NS$WS"suffix": "",$WS"usr": "c:@F at main{{.*}}"
+// CHECK-NOT: "id": [[CONTRIBUTOR_MAIN:[0-9]+]],$NS$WS"suffix": "",$WS"usr": "c:@F at main{{.*}}"
// 'argv' is reported as type-constrained.
// CHECK: "analysis_name": "TypeConstrainedPointersAnalysisResult"
@@ -53,8 +52,4 @@ void foo(int *q) {
// CHECK: "@": [[Q_ID]]$PTR_L1
// CHECK-NOT: "@":
-// 'main' contributes nothing: 'argv' is type-constrained and excluded.
-// CHECK: "@": [[CONTRIBUTOR_MAIN]]$WS},$WS[
-// CHECK-NOT: "@": [[ARGV_ID]]
-
// CHECK: "analysis_name"
diff --git a/clang/test/Analysis/Scalable/TypeConstrainedPointers/unsafe-buffer-reachable-excludes-type-constrained-new-delete.cpp b/clang/test/Analysis/Scalable/TypeConstrainedPointers/unsafe-buffer-reachable-excludes-type-constrained-new-delete.cpp
index 798b714e14af2..22df8ad075ef9 100644
--- a/clang/test/Analysis/Scalable/TypeConstrainedPointers/unsafe-buffer-reachable-excludes-type-constrained-new-delete.cpp
+++ b/clang/test/Analysis/Scalable/TypeConstrainedPointers/unsafe-buffer-reachable-excludes-type-constrained-new-delete.cpp
@@ -22,8 +22,7 @@
// RUN: sed -e 's|$NS|{{([^]]\|[[:space:]])+\\],}}|g' \
// RUN: -e 's|$WS|{{[[:space:]]+}}|g' \
// RUN: -e 's|$PTR_L1|{{[[:space:]]+\\},[[:space:]]+1[[:space:]]+\\]}}|g' \
-// RUN: %s > %t/checks.txt
-// RUN: FileCheck %t/checks.txt --input-file=%t/wpa.json
+// RUN: %s | FileCheck - --input-file=%t/wpa.json
typedef __SIZE_TYPE__ size_t;
More information about the cfe-commits
mailing list