-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[analyzer] Handle [[assume(cond)]]
as __builtin_assume(cond)
#101063
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
base: main
Are you sure you want to change the base?
Conversation
@steakhal Kinda stuck... It builds properly but doesn't detect the assume attribute. |
You can test this locally with the following command:git-clang-format --diff 13996378d81c8fa9a364aeaafd7382abbc1db83a 97de745341dfc17e7ad9c595d239346a9114a4c6 --extensions cpp -- clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp View the diff from clang-format here.diff --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
index 1a4eb88fb6..8ab8b97d8e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -83,23 +83,23 @@ bool BuiltinFunctionChecker::evalCall(const CallEvent &Call,
const Expr *CE = Call.getOriginExpr();
if (const auto *AttrStmt = dyn_cast<AttributedStmt>(CE)) {
- for (const Attr *I : AttrStmt->getAttrs()) {
- if (const auto *AssumeAttr = dyn_cast<CXXAssumeAttr>(I)) {
- const Expr *AssumeExpr = AssumeAttr->getAssumption();
- SVal Arg = C.getSVal(AssumeExpr);
- if (Arg.isUndef())
- return true;
-
- state = state->assume(Arg.castAs<DefinedOrUnknownSVal>(), true);
- if (!state) {
- C.generateSink(C.getState(), C.getPredecessor());
- return true;
- }
-
- C.addTransition(state);
- return true;
- }
+ for (const Attr *I : AttrStmt->getAttrs()) {
+ if (const auto *AssumeAttr = dyn_cast<CXXAssumeAttr>(I)) {
+ const Expr *AssumeExpr = AssumeAttr->getAssumption();
+ SVal Arg = C.getSVal(AssumeExpr);
+ if (Arg.isUndef())
+ return true;
+
+ state = state->assume(Arg.castAs<DefinedOrUnknownSVal>(), true);
+ if (!state) {
+ C.generateSink(C.getState(), C.getPredecessor());
+ return true;
+ }
+
+ C.addTransition(state);
+ return true;
}
+ }
}
if (isBuiltinLikeFunction(Call)) {
|
No, its cool. You are on the right track. Ill come back to you tomorrow. |
[[assume(cond)]]
as __builtin_assume(cond)
Alright, It's not as easy as I first thought. We could also patch the CFG, as it already has the
And for us, we would need to evaluate the operands of the AttributedStmt before we would evaluate the AttributedStmt itself - because the assumption probably refers to values of expression of child AST nodes. So, it doesn't look easy :D My bad. |
[[assume(cond)]]
as__builtin_assume(cond)
#100762