Skip to content

Conversation

@rniwa
Copy link
Contributor

@rniwa rniwa commented Jul 14, 2025

No description provided.

@rniwa rniwa requested a review from t-rasmud July 14, 2025 20:59
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Jul 14, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 14, 2025

@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/148721.diff

2 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+4-1)
  • (modified) clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm (+4)
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index cfcc47c5e71c8..478bd85177143 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -177,7 +177,10 @@ bool tryToFindPtrOrigin(
       E = unaryOp->getSubExpr();
       continue;
     }
-
+    if (auto *BoxedExpr = dyn_cast<ObjCBoxedExpr>(E)) {
+      E = BoxedExpr->getSubExpr();
+      continue;
+    }
     break;
   }
   // Some other expression.
diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm b/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
index c33d53b047c2e..c69113c48806d 100644
--- a/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
+++ b/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
@@ -329,13 +329,17 @@ void foo() {
   }
 }
 
+#define YES 1
+
 namespace call_with_cf_constant {
   void bar(const NSArray *);
   void baz(const NSDictionary *);
+  void boo(NSNumber *);
   void foo() {
     CFArrayCreateMutable(kCFAllocatorDefault, 10);
     bar(@[@"hello"]);
     baz(@{@"hello": @3});
+    boo(@YES);
   }
 }
 

@llvmbot
Copy link
Member

llvmbot commented Jul 14, 2025

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Ryosuke Niwa (rniwa)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/148721.diff

2 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+4-1)
  • (modified) clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm (+4)
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index cfcc47c5e71c8..478bd85177143 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -177,7 +177,10 @@ bool tryToFindPtrOrigin(
       E = unaryOp->getSubExpr();
       continue;
     }
-
+    if (auto *BoxedExpr = dyn_cast<ObjCBoxedExpr>(E)) {
+      E = BoxedExpr->getSubExpr();
+      continue;
+    }
     break;
   }
   // Some other expression.
diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm b/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
index c33d53b047c2e..c69113c48806d 100644
--- a/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
+++ b/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
@@ -329,13 +329,17 @@ void foo() {
   }
 }
 
+#define YES 1
+
 namespace call_with_cf_constant {
   void bar(const NSArray *);
   void baz(const NSDictionary *);
+  void boo(NSNumber *);
   void foo() {
     CFArrayCreateMutable(kCFAllocatorDefault, 10);
     bar(@[@"hello"]);
     baz(@{@"hello": @3});
+    boo(@YES);
   }
 }
 

}
}

#define YES 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it just @YES/@no that are safe constants? What's the expected behavior for say #define RANDOM 3 and boo(@ RANDOM);?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are also considered safe. Basically @ any number should be treated as safe.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it. Thank you.

Copy link
Contributor

@t-rasmud t-rasmud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rniwa
Copy link
Contributor Author

rniwa commented Jul 15, 2025

Thanks for the review!

@rniwa rniwa merged commit ae3bba4 into llvm:main Jul 15, 2025
12 checks passed
@rniwa rniwa deleted the recognize-boxed-int branch July 15, 2025 22:12
@steakhal
Copy link
Contributor

FYI I think it's good practice to not tag people in commit title/summaries unless it's strictly desired.
See the relevant discussion about this proposed policy change on Discuss.

@rniwa
Copy link
Contributor Author

rniwa commented Jul 16, 2025

oh, I didn't even realize @YES and @NO would tag people.

rniwa added a commit to rniwa/llvm-project that referenced this pull request Aug 21, 2025
adrian-prantl pushed a commit to swiftlang/llvm-project that referenced this pull request Aug 21, 2025
adrian-prantl added a commit to swiftlang/llvm-project that referenced this pull request Aug 21, 2025
…stants

WebKit checkers: recgonize @yES / @no as safe constants (llvm#148721)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:static analyzer clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants