Index: clang/lib/AST/ExprConstant.cpp =================================================================== --- clang/lib/AST/ExprConstant.cpp +++ clang/lib/AST/ExprConstant.cpp @@ -11200,6 +11200,7 @@ } case Builtin::BI__builtin_expect: + case Builtin::BI__builtin_expect_with_probability: return Visit(E->getArg(0)); case Builtin::BI__builtin_ffs: Index: clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp @@ -64,10 +64,12 @@ case Builtin::BI__builtin_unpredictable: case Builtin::BI__builtin_expect: + case Builtin::BI__builtin_expect_with_probability: case Builtin::BI__builtin_assume_aligned: case Builtin::BI__builtin_addressof: { - // For __builtin_unpredictable, __builtin_expect, and - // __builtin_assume_aligned, just return the value of the subexpression. + // For __builtin_unpredictable, __builtin_expect, + // __builtin_expect_with_probability and __builtin_assume_aligned, + // just return the value of the subexpression. // __builtin_addressof is going from a reference to a pointer, but those // are represented the same way in the analyzer. assert (Call.getNumArgs() > 0); Index: clang/test/Sema/builtin-expect-with-probability.cpp =================================================================== --- clang/test/Sema/builtin-expect-with-probability.cpp +++ clang/test/Sema/builtin-expect-with-probability.cpp @@ -1,4 +1,30 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s + +__attribute__((noreturn)) extern void bar(); + +int test_no_warn(int x) { + if (x) { + if (__builtin_expect_with_probability(1, 1, 1)) + bar(); + } else { + return 0; + } +} // should not emit warn "control may reach end of non-void function" here since expr is constantly true, so the "if(__bui..)" should be constantly true condition and be ignored + +template void tempf() { + static_assert(b == 1, "should be evaluated as 1"); // should not have error here +} + +constexpr int constf() { + return __builtin_expect_with_probability(1, 1, 1); +} + +void foo() { + tempf<__builtin_expect_with_probability(1, 1, 1)>(); + constexpr int f = constf(); + static_assert(f == 1, "should be evaluated as 1"); // should not have error here +} + extern int global; struct S {