[clang] [alpha.webkit.UncountedCallArgsChecker] Treat true/false as trivial (PR #90169)

Ryosuke Niwa via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 25 23:05:17 PDT 2024


https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/90169

>From f7640709bf3cebbd3f1b04f6eba4b8f60bb18c13 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Thu, 25 Apr 2024 23:03:00 -0700
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Treat true/false as
 trivial

Treat boolean literal "true" and "false" as trivial.
---
 .../lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp  | 1 +
 clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp     | 4 ++++
 2 files changed, 5 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 287f6a52870056..ec8598bffe97b1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -463,6 +463,7 @@ class TrivialFunctionAnalysisVisitor
   bool VisitFixedPointLiteral(const FixedPointLiteral *E) { return true; }
   bool VisitCharacterLiteral(const CharacterLiteral *E) { return true; }
   bool VisitStringLiteral(const StringLiteral *E) { return true; }
+  bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) { return true; }
 
   bool VisitConstantExpr(const ConstantExpr *CE) {
     // Constant expressions are trivial.
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 80a9a263dab140..3f628f2600d55f 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -201,6 +201,8 @@ class RefCounted {
   unsigned trivial25() const { return __c11_atomic_load((volatile _Atomic(unsigned) *)&v, __ATOMIC_RELAXED); }
   bool trivial26() { bool hasValue = v; return !hasValue; }
   bool trivial27(int v) { bool value; value = v ? 1 : 0; return value; }
+  bool trivial28() { return false; }
+  bool trivial29() { return true; }
 
   static RefCounted& singleton() {
     static RefCounted s_RefCounted;
@@ -322,6 +324,8 @@ class UnrelatedClass {
     getFieldTrivial().trivial25(); // no-warning
     getFieldTrivial().trivial26(); // no-warning
     getFieldTrivial().trivial27(5); // no-warning
+    getFieldTrivial().trivial28(); // no-warning
+    getFieldTrivial().trivial29(); // no-warning
     RefCounted::singleton().trivial18(); // no-warning
     RefCounted::singleton().someFunction(); // no-warning
 



More information about the cfe-commits mailing list