https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/216526
>From a5d03987a4c65d5fceb81c1013f4eb8ca9265a91 Mon Sep 17 00:00:00 2001 From: Ziqing Luo <[email protected]> Date: Sat, 15 Aug 2026 18:05:23 -0700 Subject: [PATCH] [SSAF][UnsafeBufferAnalysis] Address follow up questions after the approval of #209354 - 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 & rdar://179151882 --- .../UnsafeBufferUsage/UnsafeBufferUsageAnalysis.cpp | 5 +++-- ...uffer-reachable-excludes-type-constrained-main.cpp | 11 +++-------- ...reachable-excludes-type-constrained-new-delete.cpp | 3 +-- 3 files changed, 7 insertions(+), 12 deletions(-) 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@foo#*I#" // CHECK-DAG: "id": [[ARGV_ID:[0-9]+]],$NS$WS"suffix": "2",$WS"usr": "c:@F@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@foo#*I#" -// CHECK-DAG: "id": [[CONTRIBUTOR_MAIN:[0-9]+]],$NS$WS"suffix": "",$WS"usr": "c:@F@main{{.*}}" +// CHECK-NOT: "id": [[CONTRIBUTOR_MAIN:[0-9]+]],$NS$WS"suffix": "",$WS"usr": "c:@F@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; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
