[clang] [WebKit Checkers] Treat attributes as trivial (PR #127289)

Ryosuke Niwa via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 14 16:58:33 PST 2025


https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/127289

For the purpose of determining triviality, ignore all attributes.

>From 31e0fcbf7f8bf4d2244c863041df3716a598db3f Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Wed, 12 Feb 2025 22:16:11 -0800
Subject: [PATCH] [WebKit Checkers] Treat attributes as trivial

For the purpose of determining triviality, ignore all attributes.
---
 .../lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp | 5 +++++
 clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp    | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 5b8d1184050e9..8340de9e5a7a9 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -392,6 +392,11 @@ class TrivialFunctionAnalysisVisitor
     return false;
   }
 
+  bool VisitAttributedStmt(const AttributedStmt *AS) {
+    // Ignore attributes.
+    return Visit(AS->getSubStmt());
+  }
+
   bool VisitCompoundStmt(const CompoundStmt *CS) {
     // A compound statement is allowed as long each individual sub-statement
     // is trivial.
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index cf403851b74fd..fe7ce158eb8ba 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -376,6 +376,7 @@ class RefCounted {
   };
   void trivial68() { point pt = { 1.0 }; }
   unsigned trivial69() { return offsetof(RefCounted, children); }
+  DerivedNumber* trivial70() { [[clang::suppress]] return static_cast<DerivedNumber*>(number); }
 
   static RefCounted& singleton() {
     static RefCounted s_RefCounted;
@@ -564,6 +565,7 @@ class UnrelatedClass {
     getFieldTrivial().trivial67()->trivial6(); // no-warning
     getFieldTrivial().trivial68(); // no-warning
     getFieldTrivial().trivial69(); // no-warning
+    getFieldTrivial().trivial70(); // no-warning
 
     RefCounted::singleton().trivial18(); // no-warning
     RefCounted::singleton().someFunction(); // no-warning



More information about the cfe-commits mailing list