Skip to content

Commit

Permalink
[analyzer] Model Microsoft "__assume" in the same way as clang "__bui…
Browse files Browse the repository at this point in the history
…ltin_assume"
  • Loading branch information
loic-joly-sonarsource authored and steakhal committed Feb 5, 2024
1 parent 0ac4438 commit ae354c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ bool BuiltinFunctionChecker::evalCall(const CallEvent &Call,
default:
return false;

case Builtin::BI__builtin_assume: {
case Builtin::BI__builtin_assume:
case Builtin::BI__assume: {
assert (Call.getNumArgs() > 0);
SVal Arg = Call.getArgSVal(0);
if (Arg.isUndef())
Expand Down
18 changes: 18 additions & 0 deletions clang/test/Analysis/builtin-functions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
// RUN: %clang_analyze_cc1 -triple x86_64-pc-windows-msvc19.11.0 -fms-extensions -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify

void clang_analyzer_eval(bool);
void clang_analyzer_warnIfReached();
Expand Down Expand Up @@ -65,6 +66,23 @@ void g(int i) {
}
}

#ifdef _WIN32
namespace ms {
void f(int i) {
__assume(i < 10);
clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
}

void g(int i) {
if (i > 5) {
__assume(i < 5);
clang_analyzer_warnIfReached(); // Assumtion contradicts constraints.
// We give up the analysis on this path.
}
}
} // namespace ms
#endif

void test_constant_p(void *ptr) {
int i = 1;
const int j = 2;
Expand Down

0 comments on commit ae354c5

Please sign in to comment.