[clang] [clang][ExprConst] Fix second arg of __builtin_{clzg,ctzg} not always being evaluated (PR #86742)
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 26 15:19:48 PDT 2024
================
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+constexpr int increment(int& x) {
+ x++;
+ return x;
+}
+
+constexpr int test_clzg_0() {
+ int x = 0;
+ [[maybe_unused]] int unused = __builtin_clzg(0U, increment(x));
+ return x;
+}
+
+static_assert(test_clzg_0() == 1);
+
+constexpr int test_clzg_1() {
+ int x = 0;
+ [[maybe_unused]] int unused = __builtin_clzg(1U, increment(x));
+ return x;
+}
+
+static_assert(test_clzg_1() == 1);
+
+constexpr int test_ctzg_0() {
+ int x = 0;
+ [[maybe_unused]] int unused = __builtin_ctzg(0U, increment(x));
+ return x;
+}
+
+static_assert(test_ctzg_0() == 1);
+
+constexpr int test_ctzg_1() {
+ int x = 0;
+ [[maybe_unused]] int unused = __builtin_ctzg(1U, increment(x));
----------------
zygoloid wrote:
Can you cast to `void` instead?
```suggestion
(void)__builtin_clzg(0U, increment(x));
return x;
}
static_assert(test_clzg_0() == 1);
constexpr int test_clzg_1() {
int x = 0;
(void)__builtin_clzg(1U, increment(x));
return x;
}
static_assert(test_clzg_1() == 1);
constexpr int test_ctzg_0() {
int x = 0;
(void)__builtin_ctzg(0U, increment(x));
return x;
}
static_assert(test_ctzg_0() == 1);
constexpr int test_ctzg_1() {
int x = 0;
(void)__builtin_ctzg(1U, increment(x));
```
https://github.com/llvm/llvm-project/pull/86742
More information about the cfe-commits
mailing list