[clang] [CIR] Use the AST result type for sizeof/alignof constants (PR #203942)
Akshay K via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 16 07:29:34 PDT 2026
================
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -std=c++20 -triple i686-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR
+// RUN: %clang_cc1 -std=c++20 -triple i686-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM
+// RUN: %clang_cc1 -std=c++20 -triple i686-unknown-linux-gnu -emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG
+
+// The result of sizeof/alignof/__builtin_vectorelements is size_t, which is
+// 32 bits wide on this target. The emitted constants must use that width
+// rather than a hardcoded 64-bit type.
+
+using size_t = decltype(sizeof(int));
+
+size_t size_of_int() { return sizeof(int); }
+
+// CIR-LABEL: cir.func {{.*}}@_Z11size_of_intv() -> !u32i
+// CIR: cir.const #cir.int<4> : !u32i
+
+// LLVM-LABEL: define {{.*}}i32 @_Z11size_of_intv()
+// LLVM: store i32 4, ptr
+
+// OGCG-LABEL: define {{.*}}i32 @_Z11size_of_intv()
----------------
kumarak wrote:
@andykaylor, merged both LLVM and OGCG into one pattern prefix. Had it separate because the classic codegen layer was folding trivial return cases.
https://github.com/llvm/llvm-project/pull/203942
More information about the cfe-commits
mailing list