Author: Loïc Joly Date: 2024-02-05T17:02:24+01:00 New Revision: ae354c5a45d319b3117c2822b8f6988461f3cb33
URL: https://github.com/llvm/llvm-project/commit/ae354c5a45d319b3117c2822b8f6988461f3cb33 DIFF: https://github.com/llvm/llvm-project/commit/ae354c5a45d319b3117c2822b8f6988461f3cb33.diff LOG: [analyzer] Model Microsoft "__assume" in the same way as clang "__builtin_assume" Added: Modified: clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp clang/test/Analysis/builtin-functions.cpp Removed: ################################################################################ diff --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp index 61521c259ca90a..01e46fa8591c07 100644 --- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp @@ -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()) diff --git a/clang/test/Analysis/builtin-functions.cpp b/clang/test/Analysis/builtin-functions.cpp index 37e522049b1748..8719193e405c4c 100644 --- a/clang/test/Analysis/builtin-functions.cpp +++ b/clang/test/Analysis/builtin-functions.cpp @@ -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(); @@ -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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits