Skip to content

Commit ae354c5

Browse files
loic-joly-sonarsourcesteakhal
authored andcommitted
[analyzer] Model Microsoft "__assume" in the same way as clang "__builtin_assume"
1 parent 0ac4438 commit ae354c5

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ bool BuiltinFunctionChecker::evalCall(const CallEvent &Call,
4444
default:
4545
return false;
4646

47-
case Builtin::BI__builtin_assume: {
47+
case Builtin::BI__builtin_assume:
48+
case Builtin::BI__assume: {
4849
assert (Call.getNumArgs() > 0);
4950
SVal Arg = Call.getArgSVal(0);
5051
if (Arg.isUndef())

clang/test/Analysis/builtin-functions.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
2+
// RUN: %clang_analyze_cc1 -triple x86_64-pc-windows-msvc19.11.0 -fms-extensions -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
23

34
void clang_analyzer_eval(bool);
45
void clang_analyzer_warnIfReached();
@@ -65,6 +66,23 @@ void g(int i) {
6566
}
6667
}
6768

69+
#ifdef _WIN32
70+
namespace ms {
71+
void f(int i) {
72+
__assume(i < 10);
73+
clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
74+
}
75+
76+
void g(int i) {
77+
if (i > 5) {
78+
__assume(i < 5);
79+
clang_analyzer_warnIfReached(); // Assumtion contradicts constraints.
80+
// We give up the analysis on this path.
81+
}
82+
}
83+
} // namespace ms
84+
#endif
85+
6886
void test_constant_p(void *ptr) {
6987
int i = 1;
7088
const int j = 2;

0 commit comments

Comments
 (0)