[clang] [CIR] Lowering __builtin_stdc_* calls (PR #214931)

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 10 12:46:22 PDT 2026


================
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c23 -I%S/../../CodeGen/Inputs -fclangir -emit-cir %s -o - | FileCheck %s
+
+#include <stdbit.h>
+
+void test_stdc_trailing_zeros(unsigned long long x) {
+  int cnt = __builtin_stdc_trailing_zeros(x);
+  (void)cnt;
+}
+
+// CHECK-LABEL: test_stdc_trailing_zeros
+// CHECK: cir.ctz
+// CHECK-NOT: poison_zero
+// CHECK: cir.return
+
+unsigned test_stdc_leading_zeros(unsigned x) {
+  return __builtin_stdc_leading_zeros(x);
+}
+
+// CHECK-LABEL: test_stdc_leading_zeros
----------------
bcardosolopes wrote:

`test_stdc_leading_zeros` is a prefix of `test_stdc_leading_zeros_ui` below. Works today by ordering, breaks as soon as someone reorders the file. Anchor on `@test_stdc_leading_zeros(`.

https://github.com/llvm/llvm-project/pull/214931


More information about the cfe-commits mailing list