llvm-project/clang/test/Sema/constant-builtins-all-args-evaluated.cpp
OverMighty cf73f136c5
[clang][ExprConst] Fix second arg of __builtin_{clzg,ctzg} not always being evaluated (#86742)
Even if we don't actually use the value of the second argument, we have to evaluate it for side-effects.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2024-03-29 14:01:19 -07:00

35 lines
579 B
C++

// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
constexpr int test_clzg_0() {
int x = 0;
(void)__builtin_clzg(0U, ++x);
return x;
}
static_assert(test_clzg_0() == 1);
constexpr int test_clzg_1() {
int x = 0;
(void)__builtin_clzg(1U, ++x);
return x;
}
static_assert(test_clzg_1() == 1);
constexpr int test_ctzg_0() {
int x = 0;
(void)__builtin_ctzg(0U, ++x);
return x;
}
static_assert(test_ctzg_0() == 1);
constexpr int test_ctzg_1() {
int x = 0;
(void)__builtin_ctzg(1U, ++x);
return x;
}
static_assert(test_ctzg_1() == 1);