[PATCH] D83362: Fix warning caused by __builtin_expect_with_probability was not handled in places such as constant folding

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 8 12:21:50 PDT 2020


erichkeane added inline comments.


================
Comment at: clang/test/Sema/builtin-expect-with-probability.cpp:17
+constexpr int constf() {
+  return __builtin_expect_with_probability(1, 1, 1); // should not have error here
+}
----------------
I mean something more like:

    template<int b>
    void foo() { static_assert(!b,""); } // expected-error {{....}}

    void bar() {
      foo<__builtin_expect_with_probability(1,1,1)>();
    }


This example doesn't require that constf is executed at compile time.  You'd need to either send the result of constf to a template, or assign it to a constexpr variable in order to make it work.

So something like:

    void foo() {
       constexpr int f = constf();
       static_assert(f == 1, "");
    }



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83362/new/

https://reviews.llvm.org/D83362





More information about the cfe-commits mailing list