-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[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
Conversation
Like other functions which results in abort, treat asm brk instruction as trivial.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-static-analyzer-1 Author: Ryosuke Niwa (rniwa) ChangesLike 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:
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();
+}
|
17eed25
to
f222293
Compare
} | ||
|
||
bool VisitGCCAsmStmt(const GCCAsmStmt *AS) { | ||
return AS->getAsmString() == "brk #0xc471"; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be other kinds of brk as long as it triggers a crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could consider stripping whitespace but it's probably not necessary for a WebKit specific checker since we would never add random whitespace around brk
. Having said that, in long term, a better solution would be to provide a way to annotate that a function causes the program to terminate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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.
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.