Skip to content

[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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h"
#include <clang/AST/Stmt.h>
#include <clang/Basic/LLVM.h>
#include <clang/StaticAnalyzer/Core/PathSensitive/SVals.h>
#include <cstdio>
#include <llvm/Support/raw_ostream.h>

using namespace clang;
using namespace ento;
Expand Down Expand Up @@ -77,6 +82,26 @@ bool BuiltinFunctionChecker::evalCall(const CallEvent &Call,
const LocationContext *LCtx = C.getLocationContext();
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;
}
}
}

if (isBuiltinLikeFunction(Call)) {
C.addTransition(state->BindExpr(CE, LCtx, Call.getArgSVal(0)));
return true;
Expand Down
Loading