Skip to content

[WebKit checkers] Treat asm brk as trivial #155046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rniwa
Copy link
Contributor

@rniwa rniwa commented Aug 22, 2025

Like other functions which results in abort, treat asm brk instruction as trivial.

Like other functions which results in abort, treat asm brk instruction as trivial.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Aug 22, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 22, 2025

@llvm/pr-subscribers-clang

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

Author: Ryosuke Niwa (rniwa)

Changes

Like other functions which results in abort, treat asm brk instruction as trivial.


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

2 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp (+7)
  • (added) clang/test/Analysis/Checkers/WebKit/trivial-code-check-asm-brk.cpp (+22)
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 36c12582a5787..93ffc58b1055e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -666,6 +666,13 @@ class TrivialFunctionAnalysisVisitor
     return IsFunctionTrivial(Callee);
   }
 
+  bool VisitGCCAsmStmt(const GCCAsmStmt *AS) {
+    auto *Asm = AS->getAsmString();
+    if (!Asm)
+      return false;
+    return Asm->getString() == "brk #0xc471";
+  }
+
   bool
   VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E) {
     // Non-type template paramter is compile time constant and trivial.
diff --git a/clang/test/Analysis/Checkers/WebKit/trivial-code-check-asm-brk.cpp b/clang/test/Analysis/Checkers/WebKit/trivial-code-check-asm-brk.cpp
new file mode 100644
index 0000000000000..de98c77eb7347
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/trivial-code-check-asm-brk.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_analyze_cc1 -triple arm-darwin -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+void crash()
+{
+  __asm__ volatile ("brk #0xc471");
+  __builtin_unreachable();
+}
+
+class SomeObj {
+public:
+  void ref();
+  void deref();
+
+  void someWork() { crash(); }
+};
+
+SomeObj* provide();
+
+void doSomeWork() {
+  provide()->someWork();
+}

@rniwa rniwa force-pushed the fix-webkit-treat-asm-trap-as-trivial branch from 17eed25 to f222293 Compare August 22, 2025 23:21
@@ -666,6 +666,10 @@ class TrivialFunctionAnalysisVisitor
return IsFunctionTrivial(Callee);
}

bool VisitGCCAsmStmt(const GCCAsmStmt *AS) {
return AS->getAsmString() == "brk #0xc471";
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need to be restricted to a specific brk constant, and should it include int3, and similar?

I guess it's unlikely as whitespace is usually present only in multiline asm but is it worth considering stripping white space?

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