https://github.com/bursot updated https://github.com/llvm/llvm-project/pull/157333
From b51c2c06909a402632fe75709997716cea990fc0 Mon Sep 17 00:00:00 2001 From: Burhan <sega...@hotmail.com> Date: Sun, 7 Sep 2025 11:52:47 +0300 Subject: [PATCH 1/9] [CIR] Upstream a batch of passing tests from CIR-Incubator --- clang/test/CIR/CodeGen/OpenMP/taskwait.cpp | 9 + clang/test/CIR/CodeGen/StringExample.cpp | 34 +++ clang/test/CIR/CodeGen/binassign.cpp | 75 +++++ clang/test/CIR/CodeGen/bswap.cpp | 30 ++ clang/test/CIR/CodeGen/c89-implicit-int.c | 10 + clang/test/CIR/CodeGen/comma.cpp | 30 ++ clang/test/CIR/CodeGen/complex-cast.c | 264 ++++++++++++++++++ .../test/CIR/CodeGen/compound-literal-empty.c | 18 ++ clang/test/CIR/CodeGen/expressions.cpp | 11 + clang/test/CIR/CodeGen/func_dsolocal_pie.c | 34 +++ clang/test/CIR/CodeGen/gnu89.c | 5 + clang/test/CIR/CodeGen/if-constexpr.cpp | 92 ++++++ clang/test/CIR/CodeGen/implicit-return.cpp | 26 ++ clang/test/CIR/CodeGen/inc-bool.cpp | 14 + clang/test/CIR/CodeGen/inc-dec.cpp | 55 ++++ clang/test/CIR/CodeGen/lalg.c | 20 ++ clang/test/CIR/CodeGen/literals.c | 9 + clang/test/CIR/CodeGen/literals.cpp | 8 + clang/test/CIR/CodeGen/loop-scope.cpp | 32 +++ clang/test/CIR/CodeGen/lvalue-refs.cpp | 19 ++ clang/test/CIR/CodeGen/ms-intrinsics-other.c | 55 ++++ clang/test/CIR/CodeGen/no-pie.c | 11 + clang/test/CIR/CodeGen/no-proto-fun-ptr.c | 27 ++ clang/test/CIR/CodeGen/no-proto-is-void.cpp | 13 + .../CIR/CodeGen/null-arithmatic-expression.c | 12 + clang/test/CIR/CodeGen/operators.cpp | 14 + clang/test/CIR/CodeGen/optimization-attr.cpp | 32 +++ clang/test/CIR/CodeGen/pointer.cpp | 6 + clang/test/CIR/CodeGen/return.cpp | 33 +++ clang/test/CIR/CodeGen/shift.cpp | 8 + clang/test/CIR/CodeGen/spelling-locations.cpp | 100 +++++++ clang/test/CIR/CodeGen/std-array.cpp | 13 + clang/test/CIR/CodeGen/stmt-expr.c | 42 +++ clang/test/CIR/CodeGen/store.c | 29 ++ .../switch-unreachable-after-break.cpp | 49 ++++ clang/test/CIR/CodeGen/trap.cpp | 28 ++ clang/test/CIR/CodeGen/types-IEEE-quad.c | 32 +++ clang/test/CIR/CodeGen/types-nullptr.cpp | 9 + clang/test/CIR/CodeGen/types.c | 46 +++ clang/test/CIR/CodeGen/unary.c | 44 +++ clang/test/CIR/CodeGen/unreachable.cpp | 28 ++ clang/test/CIR/Lowering/bitfieils.c | 32 +++ clang/test/CIR/Lowering/global-ptr.c | 55 ++++ clang/test/CIR/Lowering/nested-switch.cpp | 69 +++++ clang/test/CIR/Lowering/str.c | 9 + clang/test/CIR/Lowering/switch-while.c | 84 ++++++ clang/test/CIR/hello.c | 5 + clang/test/CIR/test.c | 1 + 48 files changed, 1681 insertions(+) create mode 100644 clang/test/CIR/CodeGen/OpenMP/taskwait.cpp create mode 100644 clang/test/CIR/CodeGen/StringExample.cpp create mode 100644 clang/test/CIR/CodeGen/binassign.cpp create mode 100644 clang/test/CIR/CodeGen/bswap.cpp create mode 100644 clang/test/CIR/CodeGen/c89-implicit-int.c create mode 100644 clang/test/CIR/CodeGen/comma.cpp create mode 100644 clang/test/CIR/CodeGen/complex-cast.c create mode 100644 clang/test/CIR/CodeGen/compound-literal-empty.c create mode 100644 clang/test/CIR/CodeGen/expressions.cpp create mode 100644 clang/test/CIR/CodeGen/func_dsolocal_pie.c create mode 100644 clang/test/CIR/CodeGen/gnu89.c create mode 100644 clang/test/CIR/CodeGen/if-constexpr.cpp create mode 100644 clang/test/CIR/CodeGen/implicit-return.cpp create mode 100644 clang/test/CIR/CodeGen/inc-bool.cpp create mode 100644 clang/test/CIR/CodeGen/inc-dec.cpp create mode 100644 clang/test/CIR/CodeGen/lalg.c create mode 100644 clang/test/CIR/CodeGen/literals.c create mode 100644 clang/test/CIR/CodeGen/literals.cpp create mode 100644 clang/test/CIR/CodeGen/loop-scope.cpp create mode 100644 clang/test/CIR/CodeGen/lvalue-refs.cpp create mode 100644 clang/test/CIR/CodeGen/ms-intrinsics-other.c create mode 100644 clang/test/CIR/CodeGen/no-pie.c create mode 100644 clang/test/CIR/CodeGen/no-proto-fun-ptr.c create mode 100644 clang/test/CIR/CodeGen/no-proto-is-void.cpp create mode 100644 clang/test/CIR/CodeGen/null-arithmatic-expression.c create mode 100644 clang/test/CIR/CodeGen/operators.cpp create mode 100644 clang/test/CIR/CodeGen/optimization-attr.cpp create mode 100644 clang/test/CIR/CodeGen/pointer.cpp create mode 100644 clang/test/CIR/CodeGen/return.cpp create mode 100644 clang/test/CIR/CodeGen/shift.cpp create mode 100644 clang/test/CIR/CodeGen/spelling-locations.cpp create mode 100644 clang/test/CIR/CodeGen/std-array.cpp create mode 100644 clang/test/CIR/CodeGen/stmt-expr.c create mode 100644 clang/test/CIR/CodeGen/store.c create mode 100644 clang/test/CIR/CodeGen/switch-unreachable-after-break.cpp create mode 100644 clang/test/CIR/CodeGen/trap.cpp create mode 100644 clang/test/CIR/CodeGen/types-IEEE-quad.c create mode 100644 clang/test/CIR/CodeGen/types-nullptr.cpp create mode 100644 clang/test/CIR/CodeGen/types.c create mode 100644 clang/test/CIR/CodeGen/unary.c create mode 100644 clang/test/CIR/CodeGen/unreachable.cpp create mode 100644 clang/test/CIR/Lowering/bitfieils.c create mode 100644 clang/test/CIR/Lowering/global-ptr.c create mode 100644 clang/test/CIR/Lowering/nested-switch.cpp create mode 100644 clang/test/CIR/Lowering/str.c create mode 100644 clang/test/CIR/Lowering/switch-while.c create mode 100644 clang/test/CIR/hello.c create mode 100644 clang/test/CIR/test.c diff --git a/clang/test/CIR/CodeGen/OpenMP/taskwait.cpp b/clang/test/CIR/CodeGen/OpenMP/taskwait.cpp new file mode 100644 index 0000000000000..3b2059a8b9655 --- /dev/null +++ b/clang/test/CIR/CodeGen/OpenMP/taskwait.cpp @@ -0,0 +1,9 @@ +// TODO: fix crash in emitTaskWaitCall +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fopenmp-enable-irbuilder -fopenmp -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +// CHECK: cir.func +void omp_taskwait_1(){ +// CHECK-DISABLE: omp.taskwait +// #pragma omp taskwait +} diff --git a/clang/test/CIR/CodeGen/StringExample.cpp b/clang/test/CIR/CodeGen/StringExample.cpp new file mode 100644 index 0000000000000..a2c0ef374f1ca --- /dev/null +++ b/clang/test/CIR/CodeGen/StringExample.cpp @@ -0,0 +1,34 @@ +// RUN: true + +int strlen(char const *); +void puts(char const *); + +struct String { + long size; + long capacity; + char *storage; + + String() : size{0}, capacity{0}, storage{nullptr} {} + String(char const *s) : size{strlen(s)}, capacity{size}, + storage{new char[capacity]} {} +}; + +struct StringView { + long size; + char *storage; + + StringView(const String &s) : size{s.size}, storage{s.storage} {} + StringView() : size{0}, storage{nullptr} {} +}; + +int main() { + StringView sv; + { + String s = "Hi"; + sv = s; + + puts(sv.storage); + } + + puts(sv.storage); +} diff --git a/clang/test/CIR/CodeGen/binassign.cpp b/clang/test/CIR/CodeGen/binassign.cpp new file mode 100644 index 0000000000000..934742d13404a --- /dev/null +++ b/clang/test/CIR/CodeGen/binassign.cpp @@ -0,0 +1,75 @@ +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +int foo(int a, int b) { + int x = a * b; + x *= b; + x /= b; + x %= b; + x += b; + x -= b; + x >>= b; + x <<= b; + x &= b; + x ^= b; + x |= b; + return x; +} + +// CHECK: [[Value:%[0-9]+]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] {alignment = 4 : i64} +// CHECK: = cir.binop(mul, +// CHECK: = cir.load {{.*}}[[Value]] +// CHECK: = cir.binop(mul, +// CHECK: cir.store{{.*}} {{.*}}[[Value]] +// CHECK: = cir.load {{.*}}[[Value]] +// CHECK: cir.binop(div, +// CHECK: cir.store{{.*}} {{.*}}[[Value]] +// CHECK: = cir.load {{.*}}[[Value]] +// CHECK: = cir.binop(rem, {{.*}} loc([[SourceLocation:#loc[0-9]+]]) +// CHECK: cir.store{{.*}} {{.*}}[[Value]] +// CHECK: = cir.load {{.*}}[[Value]] +// CHECK: = cir.binop(add, +// CHECK: cir.store{{.*}} {{.*}}[[Value]] +// CHECK: = cir.load {{.*}}[[Value]] +// CHECK: = cir.binop(sub, +// CHECK: cir.store{{.*}} {{.*}}[[Value]] +// CHECK: = cir.load {{.*}}[[Value]] +// CHECK: = cir.shift(right +// CHECK: cir.store{{.*}} {{.*}}[[Value]] +// CHECK: = cir.load {{.*}}[[Value]] +// CHECK: = cir.shift(left +// CHECK: cir.store{{.*}} {{.*}}[[Value]] +// CHECK: = cir.load {{.*}}[[Value]] +// CHECK: = cir.binop(and, +// CHECK: cir.store{{.*}} {{.*}}[[Value]] +// CHECK: = cir.load {{.*}}[[Value]] +// CHECK: = cir.binop(xor, +// CHECK: cir.store{{.*}} {{.*}}[[Value]] +// CHECK: = cir.load {{.*}}[[Value]] +// CHECK: = cir.binop(or, +// CHECK: cir.store{{.*}} {{.*}}[[Value]] + +typedef enum { + A = 3, +} enumy; + +enumy getty(); + +void exec() { + enumy r; + if ((r = getty()) < 0) {} +} + +// CHECK: cir.func dso_local @_Z4execv() +// CHECK: %0 = cir.alloca !u32i, !cir.ptr<!u32i>, ["r"] {alignment = 4 : i64} +// CHECK: cir.scope { +// CHECK: %1 = cir.call @_Z5gettyv() : () -> !u32i +// CHECK: cir.store{{.*}} %1, %0 : !u32i, !cir.ptr<!u32i> +// CHECK: %2 = cir.cast(integral, %1 : !u32i), !s32i +// CHECK: %3 = cir.const #cir.int<0> : !s32i +// CHECK: %4 = cir.cmp(lt, %2, %3) : !s32i, !cir.bool +// CHECK: cir.if %4 { + +// CHECK: [[SourceLocationB:#loc[0-9]+]] = loc("{{.*}}binassign.cpp":8:8) +// CHECK: [[SourceLocationA:#loc[0-9]+]] = loc("{{.*}}binassign.cpp":8:3) +// CHECK: [[SourceLocation]] = loc(fused[[[SourceLocationA]], [[SourceLocationB]]]) diff --git a/clang/test/CIR/CodeGen/bswap.cpp b/clang/test/CIR/CodeGen/bswap.cpp new file mode 100644 index 0000000000000..3473b64ac7228 --- /dev/null +++ b/clang/test/CIR/CodeGen/bswap.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +using u16 = unsigned short; +using u32 = unsigned int; +using u64 = unsigned long long; + +u16 bswap_u16(u16 x) { + return __builtin_bswap16(x); +} + +// CHECK: cir.func dso_local @_Z9bswap_u16t +// CHECK: %{{.+}} = cir.byte_swap %{{.+}} : !u16i +// CHECK: } + +u32 bswap_u32(u32 x) { + return __builtin_bswap32(x); +} + +// CHECK: cir.func dso_local @_Z9bswap_u32j +// CHECK: %{{.+}} = cir.byte_swap %{{.+}} : !u32i +// CHECK: } + +u64 bswap_u64(u64 x) { + return __builtin_bswap64(x); +} + +// CHECK: cir.func dso_local @_Z9bswap_u64y +// CHECK: %{{.+}} = cir.byte_swap %{{.+}} : !u64i +// CHECK: } diff --git a/clang/test/CIR/CodeGen/c89-implicit-int.c b/clang/test/CIR/CodeGen/c89-implicit-int.c new file mode 100644 index 0000000000000..4e2392c44a802 --- /dev/null +++ b/clang/test/CIR/CodeGen/c89-implicit-int.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c89 -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +// Implicit int return type. +test = 0; +// CHECK: cir.global external @test = #cir.int<0> : !s32i +func (void) { +// CHECK: cir.func dso_local @func() -> !s32i + return 0; +} diff --git a/clang/test/CIR/CodeGen/comma.cpp b/clang/test/CIR/CodeGen/comma.cpp new file mode 100644 index 0000000000000..e10be4ac02288 --- /dev/null +++ b/clang/test/CIR/CodeGen/comma.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -Wno-unused-value -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +int c0() { + int a = 1; + int b = 2; + return b + 1, a; +} + +// CHECK: cir.func dso_local @_Z2c0v() -> !s32i +// CHECK: %[[#RET:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"] +// CHECK: %[[#A:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init] +// CHECK: %[[#B:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["b", init] +// CHECK: %[[#LOADED_B:]] = cir.load{{.*}} %[[#B]] : !cir.ptr<!s32i>, !s32i +// CHECK: %[[#]] = cir.binop(add, %[[#LOADED_B]], %[[#]]) nsw : !s32i +// CHECK: %[[#LOADED_A:]] = cir.load{{.*}} %[[#A]] : !cir.ptr<!s32i>, !s32i +// CHECK: cir.store{{.*}} %[[#LOADED_A]], %[[#RET]] : !s32i, !cir.ptr<!s32i> + +int &foo1(); +int &foo2(); + +void c1() { + int &x = (foo1(), foo2()); +} + +// CHECK: cir.func dso_local @_Z2c1v() +// CHECK: %0 = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>> +// CHECK: %1 = cir.call @_Z4foo1v() : () -> !cir.ptr<!s32i> +// CHECK: %2 = cir.call @_Z4foo2v() : () -> !cir.ptr<!s32i> +// CHECK: cir.store{{.*}} %2, %0 : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>> diff --git a/clang/test/CIR/CodeGen/complex-cast.c b/clang/test/CIR/CodeGen/complex-cast.c new file mode 100644 index 0000000000000..5212625694447 --- /dev/null +++ b/clang/test/CIR/CodeGen/complex-cast.c @@ -0,0 +1,264 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -mmlir --mlir-print-ir-before=cir-lowering-prepare -o %t.cir %s 2>&1 | FileCheck --check-prefixes=CIR-BEFORE,CHECK %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -mmlir --mlir-print-ir-after=cir-lowering-prepare -o %t.cir %s 2>&1 | FileCheck --check-prefixes=CIR-AFTER,CHECK %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm -o %t.ll %s +// RUN: FileCheck --input-file=%t.ll --check-prefixes=LLVM,CHECK %s + +#include <stdbool.h> + +volatile double _Complex cd; +volatile float _Complex cf; +volatile int _Complex ci; +volatile short _Complex cs; +volatile double sd; +volatile int si; +volatile bool b; + +void scalar_to_complex() { + cd = sd; + ci = si; + cd = si; + ci = sd; +} + +// CHECK-LABEL: @scalar_to_complex() + +// CIR-BEFORE: %{{.+}} = cir.cast(float_to_complex, %{{.+}} : !cir.double), !cir.complex<!cir.double> + +// CIR-AFTER: %[[#REAL:]] = cir.load volatile{{.*}} %{{.+}} : !cir.ptr<!cir.double>, !cir.double +// CIR-AFTER-NEXT: %[[#IMAG:]] = cir.const #cir.fp<0.000000e+00> : !cir.double +// CIR-AFTER-NEXT: %{{.+}} = cir.complex.create %[[#REAL]], %[[#IMAG]] : !cir.double -> !cir.complex<!cir.double> + +// CIR-BEFORE: %{{.+}} = cir.cast(int_to_complex, %{{.+}} : !s32i), !cir.complex<!s32i> + +// CIR-AFTER: %[[#REAL:]] = cir.load volatile{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i +// CIR-AFTER-NEXT: %[[#IMAG:]] = cir.const #cir.int<0> : !s32i +// CIR-AFTER-NEXT: %{{.+}} = cir.complex.create %[[#REAL]], %[[#IMAG]] : !s32i -> !cir.complex<!s32i> + +// CIR-BEFORE: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.double +// CIR-BEFORE-NEXT: %{{.+}} = cir.cast(float_to_complex, %[[#A]] : !cir.double), !cir.complex<!cir.double> + +// CIR-AFTER: %[[#A:]] = cir.load volatile{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i +// CIR-AFTER-NEXT: %[[#REAL:]] = cir.cast(int_to_float, %[[#A]] : !s32i), !cir.double +// CIR-AFTER-NEXT: %[[#IMAG:]] = cir.const #cir.fp<0.000000e+00> : !cir.double +// CIR-AFTER-NEXT: %{{.+}} = cir.complex.create %[[#REAL]], %[[#IMAG]] : !cir.double -> !cir.complex<!cir.double> + +// CIR-BEFORE: %[[#A:]] = cir.cast(float_to_int, %{{.+}} : !cir.double), !s32i +// CIR-BEFORE-NEXT: %{{.+}} = cir.cast(int_to_complex, %[[#A]] : !s32i), !cir.complex<!s32i> + +// CIR-AFTER: %[[#A:]] = cir.load volatile{{.*}} %{{.+}} : !cir.ptr<!cir.double>, !cir.double +// CIR-AFTER-NEXT: %[[#REAL:]] = cir.cast(float_to_int, %[[#A]] : !cir.double), !s32i +// CIR-AFTER-NEXT: %[[#IMAG:]] = cir.const #cir.int<0> : !s32i +// CIR-AFTER-NEXT: %{{.+}} = cir.complex.create %[[#REAL]], %[[#IMAG]] : !s32i -> !cir.complex<!s32i> + +// LLVM: %[[#REAL:]] = load volatile double, ptr @sd, align 8 +// LLVM-NEXT: %[[#A:]] = insertvalue { double, double } {{.*}}, double %[[#REAL]], 0 +// LLVM-NEXT: %{{.+}} = insertvalue { double, double } %[[#A]], double 0.000000e+00, 1 + +// LLVM: %[[#REAL:]] = load volatile i32, ptr @si, align 4 +// LLVM-NEXT: %[[#A:]] = insertvalue { i32, i32 } {{.*}}, i32 %[[#REAL]], 0 +// LLVM-NEXT: %{{.+}} = insertvalue { i32, i32 } %[[#A]], i32 0, 1 + +// LLVM: %[[#A:]] = load volatile i32, ptr @si, align 4 +// LLVM-NEXT: %[[#REAL:]] = sitofp i32 %[[#A]] to double +// LLVM-NEXT: %[[#B:]] = insertvalue { double, double } {{.*}}, double %[[#REAL]], 0 +// LLVM-NEXT: %{{.+}} = insertvalue { double, double } %[[#B]], double 0.000000e+00, 1 + +// LLVM: %[[#A:]] = load volatile double, ptr @sd, align 8 +// LLVM-NEXT: %[[#REAL:]] = fptosi double %[[#A]] to i32 +// LLVM-NEXT: %[[#B:]] = insertvalue { i32, i32 } {{.*}}, i32 %[[#REAL]], 0 +// LLVM-NEXT: %{{.+}} = insertvalue { i32, i32 } %[[#B]], i32 0, 1 + +// CHECK: } + +void scalar_to_complex_explicit() { + cd = (double _Complex)sd; + ci = (int _Complex)si; + cd = (double _Complex)si; + ci = (int _Complex)sd; +} + +// CHECK-LABEL: @scalar_to_complex_explicit() + +// CIR-BEFORE: %{{.+}} = cir.cast(float_to_complex, %{{.+}} : !cir.double), !cir.complex<!cir.double> + +// CIR-AFTER: %[[#IMAG:]] = cir.const #cir.fp<0.000000e+00> : !cir.double +// CIR-AFTER-NEXT: %{{.+}} = cir.complex.create %{{.+}}, %[[#IMAG]] : !cir.double -> !cir.complex<!cir.double> + +// LLVM: %[[#A:]] = insertvalue { double, double } {{.*}}, double %{{.+}}, 0 +// LLVM-NEXT: %{{.+}} = insertvalue { double, double } %[[#A]], double 0.000000e+00, 1 + +// CIR-BEFORE: %{{.+}} = cir.cast(int_to_complex, %{{.+}} : !s32i), !cir.complex<!s32i> + +// CIR-AFTER: %[[#IMAG:]] = cir.const #cir.int<0> : !s32i +// CIR-AFTER-NEXT: %{{.+}} = cir.complex.create %{{.+}}, %[[#IMAG]] : !s32i -> !cir.complex<!s32i> + +// LLVM: %[[#A:]] = insertvalue { i32, i32 } {{.*}}, i32 %{{.+}}, 0 +// LLVM-NEXT: %{{.+}} = insertvalue { i32, i32 } %[[#A]], i32 0, 1 + +// CIR-BEFORE: %[[#A:]] = cir.cast(int_to_float, %{{.+}} : !s32i), !cir.double +// CIR-BEFORE-NEXT: %{{.+}} = cir.cast(float_to_complex, %[[#A]] : !cir.double), !cir.complex<!cir.double> + +// CIR-AFTER: %[[#REAL:]] = cir.cast(int_to_float, %11 : !s32i), !cir.double +// CIR-AFTER-NEXT: %[[#IMAG:]] = cir.const #cir.fp<0.000000e+00> : !cir.double +// CIR-AFTER-NEXT: %{{.+}} = cir.complex.create %[[#REAL]], %[[#IMAG]] : !cir.double -> !cir.complex<!cir.double> + +// LLVM: %[[#REAL:]] = sitofp i32 %{{.+}} to double +// LLVM-NEXT: %[[#A:]] = insertvalue { double, double } {{.*}}, double %[[#REAL]], 0 +// LLVM-NEXT: %{{.+}} = insertvalue { double, double } %[[#A]], double 0.000000e+00, 1 + +// CIR-BEFORE: %[[#A:]] = cir.cast(float_to_int, %{{.+}} : !cir.double), !s32i +// CIR-BEFORE-NEXT: %{{.+}} = cir.cast(int_to_complex, %[[#A]] : !s32i), !cir.complex<!s32i> + +// CIR-AFTER: %[[#REAL:]] = cir.cast(float_to_int, %{{.+}} : !cir.double), !s32i +// CIR-AFTER-NEXT: %[[#IMAG:]] = cir.const #cir.int<0> : !s32i +// CIR-AFTER-NEXT: %{{.+}} = cir.complex.create %[[#REAL]], %[[#IMAG]] : !s32i -> !cir.complex<!s32i> + +// LLVM: %[[#REAL:]] = fptosi double %{{.+}} to i32 +// LLVM-NEXT: %[[#A:]] = insertvalue { i32, i32 } {{.*}}, i32 %[[#REAL]], 0 +// LLVM-NEXT: %{{.+}} = insertvalue { i32, i32 } %[[#A]], i32 0, 1 + +// CHECK: } + +void complex_to_scalar() { + sd = (double)cd; + si = (int)ci; + sd = (double)ci; + si = (int)cd; +} + +// CHECK-LABEL: @complex_to_scalar() + +// CIR-BEFORE: %{{.+}} = cir.cast(float_complex_to_real, %{{.+}} : !cir.complex<!cir.double>), !cir.double + +// CIR-AFTER: %{{.+}} = cir.complex.real %{{.+}} : !cir.complex<!cir.double> -> !cir.double + +// LLVM: %{{.+}} = extractvalue { double, double } %{{.+}}, 0 + +// CIR-BEFORE: %{{.+}} = cir.cast(int_complex_to_real, %{{.+}} : !cir.complex<!s32i>), !s32i + +// CIR-AFTER: %{{.+}} = cir.complex.real %{{.+}} : !cir.complex<!s32i> -> !s32i + +// LLVM: %{{.+}} = extractvalue { i32, i32 } %{{.+}}, 0 + +// CIR-BEFORE: %[[#A:]] = cir.cast(int_complex_to_real, %{{.+}} : !cir.complex<!s32i>), !s32i +// CIR-BEFORE-NEXT: %{{.+}} = cir.cast(int_to_float, %[[#A]] : !s32i), !cir.double + +// CIR-AFTER: %[[#A:]] = cir.complex.real %{{.+}} : !cir.complex<!s32i> -> !s32i +// CIR-AFTER-NEXT: %{{.+}} = cir.cast(int_to_float, %[[#A]] : !s32i), !cir.double + +// LLVM: %[[#A:]] = extractvalue { i32, i32 } %{{.+}}, 0 +// LLVM-NEXT: %{{.+}} = sitofp i32 %[[#A]] to double + +// CIR-BEFORE: %[[#A:]] = cir.cast(float_complex_to_real, %{{.+}} : !cir.complex<!cir.double>), !cir.double +// CIR-BEFORE-NEXT: %{{.+}} = cir.cast(float_to_int, %[[#A]] : !cir.double), !s32i + +// CIR-AFTER: %[[#A:]] = cir.complex.real %{{.+}} : !cir.complex<!cir.double> -> !cir.double +// CIR-AFTER-NEXT: %{{.+}} = cir.cast(float_to_int, %[[#A]] : !cir.double), !s32i + +// LLVM: %[[#A:]] = extractvalue { double, double } %{{.+}}, 0 +// LLVM-NEXT: %{{.+}} = fptosi double %[[#A]] to i32 + +// CHECK: } + +void complex_to_bool() { + b = (bool)cd; + b = (bool)ci; +} + +// CHECK-LABEL: @complex_to_bool() + +// CIR-BEFORE: %{{.+}} = cir.cast(float_complex_to_bool, %{{.+}} : !cir.complex<!cir.double>), !cir.bool + +// CIR-AFTER: %[[#REAL:]] = cir.complex.real %{{.+}} : !cir.complex<!cir.double> -> !cir.double +// CIR-AFTER-NEXT: %[[#IMAG:]] = cir.complex.imag %{{.+}} : !cir.complex<!cir.double> -> !cir.double +// CIR-AFTER-NEXT: %[[#RB:]] = cir.cast(float_to_bool, %[[#REAL]] : !cir.double), !cir.bool +// CIR-AFTER-NEXT: %[[#IB:]] = cir.cast(float_to_bool, %[[#IMAG]] : !cir.double), !cir.bool +// CIR-AFTER-NEXT: %[[#A:]] = cir.const #true +// CIR-AFTER-NEXT: %{{.+}} = cir.select if %[[#RB]] then %[[#A]] else %[[#IB]] : (!cir.bool, !cir.bool, !cir.bool) -> !cir.bool + +// LLVM: %[[#REAL:]] = extractvalue { double, double } %{{.+}}, 0 +// LLVM-NEXT: %[[#IMAG:]] = extractvalue { double, double } %{{.+}}, 1 +// LLVM-NEXT: %[[#RB:]] = fcmp une double %[[#REAL]], 0.000000e+00 +// LLVM-NEXT: %[[#IB:]] = fcmp une double %[[#IMAG]], 0.000000e+00 +// LLVM-NEXT: %{{.+}} = or i1 %[[#RB]], %[[#IB]] + +// CIR-BEFORE: %{{.+}} = cir.cast(int_complex_to_bool, %{{.+}} : !cir.complex<!s32i>), !cir.bool + +// CIR-AFTER: %[[#REAL:]] = cir.complex.real %{{.+}} : !cir.complex<!s32i> -> !s32i +// CIR-AFTER-NEXT: %[[#IMAG:]] = cir.complex.imag %{{.+}} : !cir.complex<!s32i> -> !s32i +// CIR-AFTER-NEXT: %[[#RB:]] = cir.cast(int_to_bool, %[[#REAL]] : !s32i), !cir.bool +// CIR-AFTER-NEXT: %[[#IB:]] = cir.cast(int_to_bool, %[[#IMAG]] : !s32i), !cir.bool +// CIR-AFTER-NEXT: %[[#A:]] = cir.const #true +// CIR-AFTER-NEXT: %{{.+}} = cir.select if %[[#RB]] then %[[#A]] else %[[#IB]] : (!cir.bool, !cir.bool, !cir.bool) -> !cir.bool + +// LLVM: %[[#REAL:]] = extractvalue { i32, i32 } %{{.+}}, 0 +// LLVM-NEXT: %[[#IMAG:]] = extractvalue { i32, i32 } %{{.+}}, 1 +// LLVM-NEXT: %[[#RB:]] = icmp ne i32 %[[#REAL]], 0 +// LLVM-NEXT: %[[#IB:]] = icmp ne i32 %[[#IMAG]], 0 +// LLVM-NEXT: %{{.+}} = or i1 %[[#RB]], %[[#IB]] + +// CHECK: } + +struct CX { + double real; + double imag; +}; + +void lvalue_to_rvalue_bitcast() { + struct CX a; + double _Complex b = __builtin_bit_cast(double _Complex, a); +} + +// CHECK-LABEL: @lvalue_to_rvalue_bitcast() + +// CIR-BEFORE: %{{.+}} = cir.cast(bitcast, %{{.+}} : !cir.ptr<!rec_CX>), !cir.ptr<!cir.complex<!cir.double>> + +// CIR-AFTER: %{{.+}} = cir.cast(bitcast, %{{.+}} : !cir.ptr<!rec_CX>), !cir.ptr<!cir.complex<!cir.double>> + +// LLVM: %[[PTR_ADDR:.*]] = alloca %struct.CX, i64 1, align 8 +// LLVM: %[[COMPLEX_ADDR:.*]] = alloca { double, double }, i64 1, align 8 +// LLVM: %[[PTR_TO_COMPLEX:.*]] = load { double, double }, ptr %[[PTR_ADDR]], align 8 +// LLVM: store { double, double } %[[PTR_TO_COMPLEX]], ptr %[[COMPLEX_ADDR]], align 8 + +// CHECK: } + +void complex_to_complex_cast() { + cd = cf; + ci = cs; +} + +// CIR-BEFORE: %[[TMP:.*]] = cir.load{{.*}} %{{.*}} : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float> +// CIR-BEFORE: %[[FP_COMPLEX:.*]] = cir.cast(float_complex, %[[TMP]] : !cir.complex<!cir.float>), !cir.complex<!cir.double> + +// CIR-AFTER: %[[#REAL:]] = cir.complex.real %{{.*}} : !cir.complex<!cir.float> -> !cir.float +// CIR-AFTER: %[[#IMAG:]] = cir.complex.imag %{{.*}} : !cir.complex<!cir.float> -> !cir.float +// CIR-AFTER: %[[#REAL_FP_CAST:]] = cir.cast(floating, %[[#REAL]] : !cir.float), !cir.double +// CIR-AFTER: %[[#IMAG_FP_CAST:]] = cir.cast(floating, %[[#IMAG]] : !cir.float), !cir.double +// CIR-AFTER: %{{.*}} = cir.complex.create %[[#REAL_FP_CAST]], %[[#IMAG_FP_CAST]] : !cir.double -> !cir.complex<!cir.double> + +// LLVM: %[[#REAL:]] = extractvalue { float, float } %{{.*}}, 0 +// LLVM: %[[#IMAG:]] = extractvalue { float, float } %{{.*}}, 1 +// LLVM: %[[#REAL_FP_CAST:]] = fpext float %[[#REAL]] to double +// LLVM: %[[#IMAG_FP_CAST:]] = fpext float %[[#IMAG]] to double +// LLVM: %[[TMP:.*]] = insertvalue { double, double } {{.*}}, double %[[#REAL_FP_CAST]], 0 +// LLVM: %{{.*}} = insertvalue { double, double } %[[TMP]], double %[[#IMAG_FP_CAST]], 1 + +// CIR-BEFORE: %[[TMP:.*]] = cir.load{{.*}} %{{.*}} : !cir.ptr<!cir.complex<!s16i>>, !cir.complex<!s16i> +// CIR-BEFORE: %[[INT_COMPLEX:.*]] = cir.cast(int_complex, %[[TMP]] : !cir.complex<!s16i>), !cir.complex<!s32i> + +// CIR-AFTER: %[[#REAL:]] = cir.complex.real %{{.*}} : !cir.complex<!s16i> -> !s16i +// CIR-AFTER: %[[#IMAG:]] = cir.complex.imag %{{.*}} : !cir.complex<!s16i> -> !s16i +// CIR-AFTER: %[[#REAL_INT_CAST:]] = cir.cast(integral, %[[#REAL]] : !s16i), !s32i +// CIR-AFTER: %[[#IMAG_INT_CAST:]] = cir.cast(integral, %[[#IMAG]] : !s16i), !s32i +// CIR-AFTER: %{{.*}} = cir.complex.create %[[#REAL_INT_CAST]], %[[#IMAG_INT_CAST]] : !s32i -> !cir.complex<!s32i> + +// LLVM: %[[#REAL:]] = extractvalue { i16, i16 } %{{.*}}, 0 +// LLVM: %[[#IMAG:]] = extractvalue { i16, i16 } %{{.*}}, 1 +// LLVM: %[[#REAL_INT_CAST:]] = sext i16 %[[#REAL]] to i32 +// LLVM: %[[#IMAG_INT_CAST:]] = sext i16 %[[#IMAG]] to i32 +// LLVM: %[[TMP:.*]] = insertvalue { i32, i32 } {{.*}}, i32 %[[#REAL_INT_CAST]], 0 +// LLVM: %{{.*}} = insertvalue { i32, i32 } %[[TMP]], i32 %[[#IMAG_INT_CAST]], 1 + +void promotion() { + cd = cf + cf; +} diff --git a/clang/test/CIR/CodeGen/compound-literal-empty.c b/clang/test/CIR/CodeGen/compound-literal-empty.c new file mode 100644 index 0000000000000..b0007d96b4cb2 --- /dev/null +++ b/clang/test/CIR/CodeGen/compound-literal-empty.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s +// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -fclangir -emit-llvm %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM + +short b() { return (short){}; } + +// CIR-LABEL: b +// CIR: {{%.*}} = cir.alloca !s16i, !cir.ptr<!s16i>, [".compoundliteral"] {alignment = 2 : i64} + +// LLVM-LABEL: b +// LLVM: [[RET_P:%.*]] = alloca i16, i64 1, align 2 +// LLVM: [[LITERAL:%.*]] = alloca i16, i64 1, align 2 +// LLVM: store i16 0, ptr [[LITERAL]], align 2 +// LLVM: [[T0:%.*]] = load i16, ptr [[LITERAL]], align 2 +// LLVM: store i16 [[T0]], ptr [[RET_P]], align 2 +// LLVM: [[T1:%.*]] = load i16, ptr [[RET_P]], align 2 +// LLVM: ret i16 [[T1]] diff --git a/clang/test/CIR/CodeGen/expressions.cpp b/clang/test/CIR/CodeGen/expressions.cpp new file mode 100644 index 0000000000000..7324c1357f8ab --- /dev/null +++ b/clang/test/CIR/CodeGen/expressions.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +void test(int a) { +// CHECK: cir.func dso_local @{{.+}}test + + // Should generate LValue parenthesis expression. + (a) = 1; + // CHECK: %[[#C:]] = cir.const #cir.int<1> : !s32i + // CHECK: cir.store{{.*}} %[[#C]], %{{.+}} : !s32i, !cir.ptr<!s32i> +} diff --git a/clang/test/CIR/CodeGen/func_dsolocal_pie.c b/clang/test/CIR/CodeGen/func_dsolocal_pie.c new file mode 100644 index 0000000000000..f3e524ce2fdb3 --- /dev/null +++ b/clang/test/CIR/CodeGen/func_dsolocal_pie.c @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -fclangir -emit-cir -pic-is-pie -pic-level 1 %s -o %t1.cir +// RUN: FileCheck --input-file=%t1.cir %s -check-prefix=CIR +// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -fclangir -emit-llvm -pic-is-pie -pic-level 1 %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM + +void foo(int i) { + +} + +int main() { + foo(2); + return 0; +} + +// CIR: cir.func dso_local @foo(%arg0: !s32i +// CIR-NEXT: [[TMP0:%.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init] {alignment = 4 : i64} +// CIR-NEXT: cir.store %arg0, [[TMP0]] : !s32i, !cir.ptr<!s32i> +// CIR-NEXT: cir.return + +// CIR: cir.func no_proto dso_local @main() -> !s32i +// CIR: [[TMP1:%.*]] = cir.const #cir.int<2> : !s32i +// CIR: cir.call @foo([[TMP1]]) : (!s32i) -> () + +// LLVM: define dso_local void @foo(i32 [[TMP3:%.*]]) +// LLVM: [[ARG_STACK:%.*]] = alloca i32, i64 1, align 4 +// LLVM: store i32 [[TMP3]], ptr [[ARG_STACK]], align 4 +// LLVM: ret void + +// LLVM: define dso_local i32 @main() +// LLVM: [[TMP4:%.*]] = alloca i32, i64 1, align 4 +// LLVM: call void @foo(i32 2) +// LLVM: store i32 0, ptr [[TMP4]], align 4 +// LLVM: [[RET_VAL:%.*]] = load i32, ptr [[TMP4]], align 4 +// LLVM: ret i32 [[RET_VAL]] diff --git a/clang/test/CIR/CodeGen/gnu89.c b/clang/test/CIR/CodeGen/gnu89.c new file mode 100644 index 0000000000000..5254576779aa1 --- /dev/null +++ b/clang/test/CIR/CodeGen/gnu89.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -std=gnu89 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +void foo() {} +//CHECK: cir.func {{.*@foo}} \ No newline at end of file diff --git a/clang/test/CIR/CodeGen/if-constexpr.cpp b/clang/test/CIR/CodeGen/if-constexpr.cpp new file mode 100644 index 0000000000000..dd13591be17f4 --- /dev/null +++ b/clang/test/CIR/CodeGen/if-constexpr.cpp @@ -0,0 +1,92 @@ +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +void if0() { + int x = 0; + if constexpr (0 == 0) { + // Declare a variable with same name to be sure we handle the + // scopes correctly + int x = 2; + } else { + int x = 3; + } + if constexpr (0 == 1) { + int x = 4; + } else { + int x = 5; + } + if constexpr (int x = 7; 8 == 8) { + int y = x; + } else { + int y = 2*x; + } + if constexpr (int x = 9; 8 == 10) { + int y = x; + } else { + int y = 3*x; + } + if constexpr (10 == 10) { + int x = 20; + } + if constexpr (10 == 11) { + int x = 30; + } + if constexpr (int x = 70; 80 == 80) { + int y = 10*x; + } + if constexpr (int x = 90; 80 == 100) { + int y = 11*x; + } +} + +// CHECK: cir.func dso_local @_Z3if0v() {{.*}} +// CHECK: cir.store{{.*}} %1, %0 : !s32i, !cir.ptr<!s32i> loc({{.*}}) +// CHECK-NEXT: cir.scope { +// CHECK-NEXT: %2 = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] {{.*}} +// CHECK-NEXT: %3 = cir.const #cir.int<2> : !s32i loc({{.*}}) +// CHECK-NEXT: cir.store{{.*}} %3, %2 : !s32i, !cir.ptr<!s32i> loc({{.*}}) +// CHECK-NEXT: } loc({{.*}}) +// CHECK-NEXT: cir.scope { +// CHECK-NEXT: %2 = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] {{.*}} +// CHECK-NEXT: %3 = cir.const #cir.int<5> : !s32i loc({{.*}}) +// CHECK-NEXT: cir.store{{.*}} %3, %2 : !s32i, !cir.ptr<!s32i> loc({{.*}}) +// CHECK-NEXT: } loc({{.*}}) +// CHECK-NEXT: cir.scope { +// CHECK-NEXT: %2 = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] {{.*}} +// CHECK-NEXT: %3 = cir.alloca !s32i, !cir.ptr<!s32i>, ["y", init] {{.*}} +// CHECK-NEXT: %4 = cir.const #cir.int<7> : !s32i loc({{.*}}) +// CHECK-NEXT: cir.store{{.*}} %4, %2 : !s32i, !cir.ptr<!s32i> loc({{.*}}) +// CHECK-NEXT: %5 = cir.load{{.*}} %2 : !cir.ptr<!s32i>, !s32i loc({{.*}}) +// CHECK-NEXT: cir.store{{.*}} %5, %3 : !s32i, !cir.ptr<!s32i> loc({{.*}}) +// CHECK-NEXT: } loc({{.*}}) +// CHECK-NEXT: cir.scope { +// CHECK-NEXT: %2 = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] {{.*}} +// CHECK-NEXT: %3 = cir.alloca !s32i, !cir.ptr<!s32i>, ["y", init] {{.*}} +// CHECK-NEXT: %4 = cir.const #cir.int<9> : !s32i loc({{.*}}) +// CHECK-NEXT: cir.store{{.*}} %4, %2 : !s32i, !cir.ptr<!s32i> loc({{.*}}) +// CHECK-NEXT: %5 = cir.const #cir.int<3> : !s32i loc({{.*}}) +// CHECK-NEXT: %6 = cir.load{{.*}} %2 : !cir.ptr<!s32i>, !s32i loc({{.*}}) +// CHECK-NEXT: %7 = cir.binop(mul, %5, %6) nsw : !s32i loc({{.*}}) +// CHECK-NEXT: cir.store{{.*}} %7, %3 : !s32i, !cir.ptr<!s32i> loc({{.*}}) +// CHECK-NEXT: } loc({{.*}}) +// CHECK-NEXT: cir.scope { +// CHECK-NEXT: %2 = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] {{.*}} +// CHECK-NEXT: %3 = cir.const #cir.int<20> : !s32i loc({{.*}}) +// CHECK-NEXT: cir.store{{.*}} %3, %2 : !s32i, !cir.ptr<!s32i> loc({{.*}}) +// CHECK-NEXT: } loc({{.*}}) +// CHECK-NEXT: cir.scope { +// CHECK-NEXT: %2 = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] {{.*}} +// CHECK-NEXT: %3 = cir.alloca !s32i, !cir.ptr<!s32i>, ["y", init] {{.*}} +// CHECK-NEXT: %4 = cir.const #cir.int<70> : !s32i loc({{.*}}) +// CHECK-NEXT: cir.store{{.*}} %4, %2 : !s32i, !cir.ptr<!s32i> loc({{.*}}) +// CHECK-NEXT: %5 = cir.const #cir.int<10> : !s32i loc({{.*}}) +// CHECK-NEXT: %6 = cir.load{{.*}} %2 : !cir.ptr<!s32i>, !s32i loc({{.*}}) +// CHECK-NEXT: %7 = cir.binop(mul, %5, %6) nsw : !s32i loc({{.*}}) +// CHECK-NEXT: cir.store{{.*}} %7, %3 : !s32i, !cir.ptr<!s32i> loc({{.*}}) +// CHECK-NEXT: } loc({{.*}}) +// CHECK-NEXT: cir.scope { +// CHECK-NEXT: %2 = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] {{.*}} +// CHECK-NEXT: %3 = cir.const #cir.int<90> : !s32i loc({{.*}}) +// CHECK-NEXT: cir.store{{.*}} %3, %2 : !s32i, !cir.ptr<!s32i> loc({{.*}}) +// CHECK-NEXT: } loc({{.*}}) +// CHECK-NEXT: cir.return loc({{.*}}) diff --git a/clang/test/CIR/CodeGen/implicit-return.cpp b/clang/test/CIR/CodeGen/implicit-return.cpp new file mode 100644 index 0000000000000..d53568d522de0 --- /dev/null +++ b/clang/test/CIR/CodeGen/implicit-return.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -O0 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CHECK-O0 +// RUN: %clang_cc1 -O2 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CHECK-O2 + +void ret_void() {} + +// CHECK-O0: cir.func dso_local @_Z8ret_voidv() +// CHECK-O0-NEXT: cir.return +// CHECK-O0-NEXT: } + +// CHECK-O2: cir.func dso_local @_Z8ret_voidv() +// CHECK-O2-NEXT: cir.return +// CHECK-O2-NEXT: } + +int ret_non_void() {} + +// CHECK-O0: cir.func dso_local @_Z12ret_non_voidv() -> !s32i +// CHECK-O0-NEXT: %0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"] +// CHECK-O0-NEXT: cir.trap +// CHECK-O0-NEXT: } + +// CHECK-O2: cir.func dso_local @_Z12ret_non_voidv() -> !s32i +// CHECK-O2-NEXT: %0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"] +// CHECK-O2-NEXT: cir.unreachable +// CHECK-O2-NEXT: } diff --git a/clang/test/CIR/CodeGen/inc-bool.cpp b/clang/test/CIR/CodeGen/inc-bool.cpp new file mode 100644 index 0000000000000..17557d338ce0a --- /dev/null +++ b/clang/test/CIR/CodeGen/inc-bool.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++14 -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +void foo(bool x) { + x++; +} + +// CHECK: cir.func dso_local @_Z3foob(%arg0: !cir.bool loc({{.*}})) +// CHECK: [[ALLOC_X:%.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["x", init] {alignment = 1 : i64} +// CHECK: cir.store{{.*}} %arg0, [[ALLOC_X]] : !cir.bool, !cir.ptr<!cir.bool> +// CHECK: {{.*}} = cir.load{{.*}} [[ALLOC_X]] : !cir.ptr<!cir.bool>, !cir.bool +// CHECK: [[TRUE:%.*]] = cir.const #true +// CHECK: cir.store{{.*}} [[TRUE]], [[ALLOC_X]] : !cir.bool, !cir.ptr<!cir.bool> +// CHECK: cir.return diff --git a/clang/test/CIR/CodeGen/inc-dec.cpp b/clang/test/CIR/CodeGen/inc-dec.cpp new file mode 100644 index 0000000000000..c8aa62198c819 --- /dev/null +++ b/clang/test/CIR/CodeGen/inc-dec.cpp @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -Wno-unused-value -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +unsigned id0() { + unsigned a = 1; + return ++a; +} + +// CHECK: cir.func dso_local @_Z3id0v() -> !u32i +// CHECK: %[[#RET:]] = cir.alloca !u32i, !cir.ptr<!u32i>, ["__retval"] +// CHECK: %[[#A:]] = cir.alloca !u32i, !cir.ptr<!u32i>, ["a", init] +// CHECK: %[[#BEFORE_A:]] = cir.load{{.*}} %[[#A]] +// CHECK: %[[#AFTER_A:]] = cir.unary(inc, %[[#BEFORE_A]]) +// CHECK: cir.store{{.*}} %[[#AFTER_A]], %[[#A]] +// CHECK: cir.store{{.*}} %[[#AFTER_A]], %[[#RET]] + + +unsigned id1() { + unsigned a = 1; + return --a; +} + +// CHECK: cir.func dso_local @_Z3id1v() -> !u32i +// CHECK: %[[#RET:]] = cir.alloca !u32i, !cir.ptr<!u32i>, ["__retval"] +// CHECK: %[[#A:]] = cir.alloca !u32i, !cir.ptr<!u32i>, ["a", init] +// CHECK: %[[#BEFORE_A:]] = cir.load{{.*}} %[[#A]] +// CHECK: %[[#AFTER_A:]] = cir.unary(dec, %[[#BEFORE_A]]) +// CHECK: cir.store{{.*}} %[[#AFTER_A]], %[[#A]] +// CHECK: cir.store{{.*}} %[[#AFTER_A]], %[[#RET]] + +unsigned id2() { + unsigned a = 1; + return a++; +} + +// CHECK: cir.func dso_local @_Z3id2v() -> !u32i +// CHECK: %[[#RET:]] = cir.alloca !u32i, !cir.ptr<!u32i>, ["__retval"] +// CHECK: %[[#A:]] = cir.alloca !u32i, !cir.ptr<!u32i>, ["a", init] +// CHECK: %[[#BEFORE_A:]] = cir.load{{.*}} %[[#A]] +// CHECK: %[[#AFTER_A:]] = cir.unary(inc, %[[#BEFORE_A]]) +// CHECK: cir.store{{.*}} %[[#AFTER_A]], %[[#A]] +// CHECK: cir.store{{.*}} %[[#BEFORE_A]], %[[#RET]] + +unsigned id3() { + unsigned a = 1; + return a--; +} + +// CHECK: cir.func dso_local @_Z3id3v() -> !u32i +// CHECK: %[[#RET:]] = cir.alloca !u32i, !cir.ptr<!u32i>, ["__retval"] +// CHECK: %[[#A:]] = cir.alloca !u32i, !cir.ptr<!u32i>, ["a", init] +// CHECK: %[[#BEFORE_A:]] = cir.load{{.*}} %[[#A]] +// CHECK: %[[#AFTER_A:]] = cir.unary(dec, %[[#BEFORE_A]]) +// CHECK: cir.store{{.*}} %[[#AFTER_A]], %[[#A]] +// CHECK: cir.store{{.*}} %[[#BEFORE_A]], %[[#RET]] diff --git a/clang/test/CIR/CodeGen/lalg.c b/clang/test/CIR/CodeGen/lalg.c new file mode 100644 index 0000000000000..7a086e9d059d1 --- /dev/null +++ b/clang/test/CIR/CodeGen/lalg.c @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o - | FileCheck %s + +double dot() { + double x = 0.0; + double y = 0.0f; + double result = x * y; + return result; +} + +// CHECK: %1 = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["x", init] +// CHECK-NEXT: %2 = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["y", init] +// CHECK-NEXT: %3 = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["result", init] +// CHECK-NEXT: %4 = cir.const #cir.fp<0.000000e+00> : !cir.double +// CHECK-NEXT: cir.store{{.*}} %4, %1 : !cir.double, !cir.ptr<!cir.double> +// CHECK-NEXT: %5 = cir.const #cir.fp<0.000000e+00> : !cir.float +// CHECK-NEXT: %6 = cir.cast(floating, %5 : !cir.float), !cir.double +// CHECK-NEXT: cir.store{{.*}} %6, %2 : !cir.double, !cir.ptr<!cir.double> +// CHECK-NEXT: %7 = cir.load{{.*}} %1 : !cir.ptr<!cir.double>, !cir.double +// CHECK-NEXT: %8 = cir.load{{.*}} %2 : !cir.ptr<!cir.double>, !cir.double +// CHECK-NEXT: %9 = cir.binop(mul, %7, %8) : !cir.double diff --git a/clang/test/CIR/CodeGen/literals.c b/clang/test/CIR/CodeGen/literals.c new file mode 100644 index 0000000000000..b8a33ad115599 --- /dev/null +++ b/clang/test/CIR/CodeGen/literals.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - | FileCheck %s + +int literals(void) { + char a = 'a'; // char literals are int in C + // CHECK: %[[RES:[0-9]+]] = cir.const #cir.int<97> : !s32i + // CHECK: %{{[0-9]+}} = cir.cast(integral, %[[RES]] : !s32i), !s8i + + return 0; +} diff --git a/clang/test/CIR/CodeGen/literals.cpp b/clang/test/CIR/CodeGen/literals.cpp new file mode 100644 index 0000000000000..87290b888185e --- /dev/null +++ b/clang/test/CIR/CodeGen/literals.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - | FileCheck %s + +int literals() { + char a = 'a'; // char literals have char type in C++ + // CHECK: %{{[0-9]+}} = cir.const #cir.int<97> : !s8i + + return 0; +} diff --git a/clang/test/CIR/CodeGen/loop-scope.cpp b/clang/test/CIR/CodeGen/loop-scope.cpp new file mode 100644 index 0000000000000..cd2cc76426c1f --- /dev/null +++ b/clang/test/CIR/CodeGen/loop-scope.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cpp.cir +// RUN: FileCheck --input-file=%t.cpp.cir %s --check-prefix=CPPSCOPE +// RUN: %clang_cc1 -x c -std=c11 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.c.cir +// RUN: FileCheck --input-file=%t.c.cir %s --check-prefix=CSCOPE + +void l0(void) { + for (int i = 0;;) { + int j = 0; + } +} + +// CPPSCOPE: cir.func dso_local @_Z2l0v() +// CPPSCOPE-NEXT: cir.scope { +// CPPSCOPE-NEXT: %0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init] {alignment = 4 : i64} +// CPPSCOPE-NEXT: %1 = cir.const #cir.int<0> : !s32i +// CPPSCOPE-NEXT: cir.store{{.*}} %1, %0 : !s32i, !cir.ptr<!s32i> +// CPPSCOPE-NEXT: cir.for : cond { + +// CPPSCOPE: } body { +// CPPSCOPE-NEXT: cir.scope { +// CPPSCOPE-NEXT: %2 = cir.alloca !s32i, !cir.ptr<!s32i>, ["j", init] {alignment = 4 : i64} + +// CSCOPE: cir.func dso_local @l0() +// CSCOPE-NEXT: cir.scope { +// CSCOPE-NEXT: %0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init] {alignment = 4 : i64} +// CSCOPE-NEXT: %1 = cir.const #cir.int<0> : !s32i +// CSCOPE-NEXT: cir.store{{.*}} %1, %0 : !s32i, !cir.ptr<!s32i> +// CSCOPE-NEXT: cir.for : cond { + +// CSCOPE: } body { +// CSCOPE-NEXT: cir.scope { +// CSCOPE-NEXT: %2 = cir.alloca !s32i, !cir.ptr<!s32i>, ["j", init] {alignment = 4 : i64} diff --git a/clang/test/CIR/CodeGen/lvalue-refs.cpp b/clang/test/CIR/CodeGen/lvalue-refs.cpp new file mode 100644 index 0000000000000..82799987aaca7 --- /dev/null +++ b/clang/test/CIR/CodeGen/lvalue-refs.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - | FileCheck %s + +struct String { + long size; +}; + +void split(String &S) {} + +// CHECK: cir.func dso_local @_Z5splitR6String(%arg0: !cir.ptr<!rec_String> +// CHECK: %0 = cir.alloca !cir.ptr<!rec_String>, !cir.ptr<!cir.ptr<!rec_String>>, ["S", init, const] + +void foo() { + String s; + split(s); +} + +// CHECK: cir.func dso_local @_Z3foov() +// CHECK: %0 = cir.alloca !rec_String, !cir.ptr<!rec_String>, ["s"] +// CHECK: cir.call @_Z5splitR6String(%0) : (!cir.ptr<!rec_String>) -> () diff --git a/clang/test/CIR/CodeGen/ms-intrinsics-other.c b/clang/test/CIR/CodeGen/ms-intrinsics-other.c new file mode 100644 index 0000000000000..d5c9164c6a4ed --- /dev/null +++ b/clang/test/CIR/CodeGen/ms-intrinsics-other.c @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -ffreestanding -fms-extensions -Wno-implicit-function-declaration -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck %s --check-prefix=CIR --input-file=%t.cir +// RUN: %clang_cc1 -ffreestanding -fms-extensions -Wno-implicit-function-declaration -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll +// RUN: FileCheck %s --check-prefix=LLVM --input-file=%t.ll + +// This test mimics clang/test/CodeGen/ms-intrinsics-other.c, which eventually +// CIR shall be able to support fully. + +unsigned short test__lzcnt16(unsigned short x) { + return __lzcnt16(x); +} +// CIR-LABEL: test__lzcnt16 +// CIR: {{%.*}} = cir.clz {{%.*}} : !u16i +// LLVM-LABEL: test__lzcnt16 +// LLVM: {{%.*}} = call i16 @llvm.ctlz.i16(i16 {{%.*}}, i1 false) + +unsigned int test__lzcnt(unsigned int x) { + return __lzcnt(x); +} +// CIR-LABEL: test__lzcnt +// CIR: {{%.*}} = cir.clz {{%.*}} : !u32i +// LLVM-LABEL: test__lzcnt +// LLVM: {{%.*}} = call i32 @llvm.ctlz.i32(i32 {{%.*}}, i1 false) + +unsigned __int64 test__lzcnt64(unsigned __int64 x) { + return __lzcnt64(x); +} +// CIR-LABEL: test__lzcnt64 +// CIR: {{%.*}} = cir.clz {{%.*}} : !u64i +// LLVM-LABEL: test__lzcnt64 +// LLVM: {{%.*}} = call i64 @llvm.ctlz.i64(i64 {{%.*}}, i1 false) + +unsigned short test__popcnt16(unsigned short x) { + return __popcnt16(x); +} +// CIR-LABEL: test__popcnt16 +// CIR: {{%.*}} = cir.popcount {{%.*}} : !u16i +// LLVM-LABEL: test__popcnt16 +// LLVM: {{%.*}} = call i16 @llvm.ctpop.i16(i16 {{%.*}}) + +unsigned int test__popcnt(unsigned int x) { + return __popcnt(x); +} +// CIR-LABEL: test__popcnt +// CIR: {{%.*}} = cir.popcount {{%.*}} : !u32i +// LLVM-LABEL: test__popcnt +// LLVM: {{%.*}} = call i32 @llvm.ctpop.i32(i32 {{%.*}}) + +unsigned __int64 test__popcnt64(unsigned __int64 x) { + return __popcnt64(x); +} +// CIR-LABEL: test__popcnt64 +// CIR: {{%.*}} = cir.popcount {{%.*}} : !u64i +// LLVM-LABEL: test__popcnt64 +// LLVM: {{%.*}} = call i64 @llvm.ctpop.i64(i64 {{%.*}}) diff --git a/clang/test/CIR/CodeGen/no-pie.c b/clang/test/CIR/CodeGen/no-pie.c new file mode 100644 index 0000000000000..0639fd34c3633 --- /dev/null +++ b/clang/test/CIR/CodeGen/no-pie.c @@ -0,0 +1,11 @@ +// RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -fno-PIE -S -Xclang -emit-cir %s -o %t1.cir +// RUN: FileCheck --input-file=%t1.cir %s -check-prefix=CIR +// RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -fno-PIE -S -Xclang -emit-llvm %s -o %t1.ll +// RUN: FileCheck --input-file=%t1.ll %s -check-prefix=LLVM + +extern int var; +int get() { + return var; +} +// CIR: cir.global "private" external dso_local @var : !s32i {alignment = 4 : i64} +// LLVM: @var = external dso_local global i32 diff --git a/clang/test/CIR/CodeGen/no-proto-fun-ptr.c b/clang/test/CIR/CodeGen/no-proto-fun-ptr.c new file mode 100644 index 0000000000000..0dcf79f68c0f2 --- /dev/null +++ b/clang/test/CIR/CodeGen/no-proto-fun-ptr.c @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - | FileCheck %s + +void empty(); + +void check_noproto_ptr() { + void (*fun)(void) = empty; +} + +// CHECK: cir.func no_proto dso_local @check_noproto_ptr() +// CHECK: [[ALLOC:%.*]] = cir.alloca !cir.ptr<!cir.func<()>>, !cir.ptr<!cir.ptr<!cir.func<()>>>, ["fun", init] {alignment = 8 : i64} +// CHECK: [[GGO:%.*]] = cir.get_global @empty : !cir.ptr<!cir.func<()>> +// CHECK: cir.store{{.*}} [[GGO]], [[ALLOC]] : !cir.ptr<!cir.func<()>>, !cir.ptr<!cir.ptr<!cir.func<()>>> +// CHECK: cir.return + +void empty(void) {} + +void buz() { + void (*func)(); + (*func)(); +} + +// CHECK: cir.func no_proto dso_local @buz() +// CHECK: [[FNPTR_ALLOC:%.*]] = cir.alloca !cir.ptr<!cir.func<(...)>>, !cir.ptr<!cir.ptr<!cir.func<(...)>>>, ["func"] {alignment = 8 : i64} +// CHECK: [[FNPTR:%.*]] = cir.load deref{{.*}} [[FNPTR_ALLOC]] : !cir.ptr<!cir.ptr<!cir.func<(...)>>>, !cir.ptr<!cir.func<(...)>> +// CHECK: [[CAST:%.*]] = cir.cast(bitcast, %1 : !cir.ptr<!cir.func<(...)>>), !cir.ptr<!cir.func<()>> +// CHECK: cir.call [[CAST]]() : (!cir.ptr<!cir.func<()>>) -> () +// CHECK: cir.return diff --git a/clang/test/CIR/CodeGen/no-proto-is-void.cpp b/clang/test/CIR/CodeGen/no-proto-is-void.cpp new file mode 100644 index 0000000000000..ca917b7f90886 --- /dev/null +++ b/clang/test/CIR/CodeGen/no-proto-is-void.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s +// RUN: %clang_cc1 -x c -std=c2x -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +// Both CXX and C2X don't support no-prototype functions. They default to void. +int noProto(); +// CHECK: cir.func dso_local @{{.*}}noProto{{.*}}() -> !s32i +int test(int x) { + return noProto(); + // CHECK {{.+}} = cir.call @{{.*}}noProto{{.*}}() : () -> !s32i +} +int noProto() { return 0; } diff --git a/clang/test/CIR/CodeGen/null-arithmatic-expression.c b/clang/test/CIR/CodeGen/null-arithmatic-expression.c new file mode 100644 index 0000000000000..a59a89e151f7c --- /dev/null +++ b/clang/test/CIR/CodeGen/null-arithmatic-expression.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-cir %s -o - | FileCheck %s + +#define NULL ((void *)0) + +char *foo() { + return (char*)NULL + 1; +} + +// CHECK: cir.func no_proto dso_local @foo() +// CHECK: [[CONST_1:%[0-9]+]] = cir.const #cir.int<1> : !s32i +// CHECK: {{.*}} = cir.cast(int_to_ptr, [[CONST_1]] : !s32i) +// CHECK: cir.return diff --git a/clang/test/CIR/CodeGen/operators.cpp b/clang/test/CIR/CodeGen/operators.cpp new file mode 100644 index 0000000000000..1d900188f1cee --- /dev/null +++ b/clang/test/CIR/CodeGen/operators.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +class __attribute__((__visibility__("default"))) exception_ptr +{ + void* __ptr_; +public: + explicit operator bool() const noexcept {return __ptr_ != nullptr;} +}; + +// TODO: for now only check that this doesn't crash, in the future check operator +// bool codegen. + +// CHECK: module \ No newline at end of file diff --git a/clang/test/CIR/CodeGen/optimization-attr.cpp b/clang/test/CIR/CodeGen/optimization-attr.cpp new file mode 100644 index 0000000000000..6af62bff6b35b --- /dev/null +++ b/clang/test/CIR/CodeGen/optimization-attr.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O0 -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir --check-prefix=CHECK-O0 %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O1 -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir --check-prefix=CHECK-O1 %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir --check-prefix=CHECK-O2 %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O3 -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir --check-prefix=CHECK-O3 %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Os -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir --check-prefix=CHECK-Os %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Oz -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir --check-prefix=CHECK-Oz %s + +void foo() {} + +// CHECK-O0: module +// CHECK-O0-NOT: cir.opt_info + +// CHECK-O1: module +// CHECK-O1: cir.opt_info = #cir.opt_info<level = 1, size = 0> + +// CHECK-O2: module +// CHECK-O2: cir.opt_info = #cir.opt_info<level = 2, size = 0> + +// CHECK-O3: module +// CHECK-O3: cir.opt_info = #cir.opt_info<level = 3, size = 0> + +// CHECK-Os: module +// CHECK-Os: cir.opt_info = #cir.opt_info<level = 2, size = 1> + +// CHECK-Oz: module +// CHECK-Oz: cir.opt_info = #cir.opt_info<level = 2, size = 2> diff --git a/clang/test/CIR/CodeGen/pointer.cpp b/clang/test/CIR/CodeGen/pointer.cpp new file mode 100644 index 0000000000000..bdf0e2103192b --- /dev/null +++ b/clang/test/CIR/CodeGen/pointer.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +// Global pointer should be zero initialized by default. +int *ptr; +// CHECK: cir.global external @ptr = #cir.ptr<null> : !cir.ptr<!s32i> diff --git a/clang/test/CIR/CodeGen/return.cpp b/clang/test/CIR/CodeGen/return.cpp new file mode 100644 index 0000000000000..e77dd5e1ac04a --- /dev/null +++ b/clang/test/CIR/CodeGen/return.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - | FileCheck %s + +int &ret0(int &x) { + return x; +} + +// CHECK: cir.func dso_local @_Z4ret0Ri +// CHECK: %0 = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["x", init, const] {alignment = 8 : i64} +// CHECK: %1 = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["__retval"] {alignment = 8 : i64} +// CHECK: cir.store{{.*}} %arg0, %0 : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>> +// CHECK: %2 = cir.load %0 : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i> +// CHECK: cir.store{{.*}} %2, %1 : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>> +// CHECK: %3 = cir.load %1 : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i> +// CHECK: cir.return %3 : !cir.ptr<!s32i> + +int unreachable_after_return() { + return 0; + return 1; +} + +// CHECK: cir.func dso_local @_Z24unreachable_after_returnv +// CHECK-NEXT: %0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"] {alignment = 4 : i64} +// CHECK-NEXT: %1 = cir.const #cir.int<0> : !s32i +// CHECK-NEXT: cir.store{{.*}} %1, %0 : !s32i, !cir.ptr<!s32i> +// CHECK-NEXT: cir.br ^bb1 +// CHECK-NEXT: ^bb1: // 2 preds: ^bb0, ^bb2 +// CHECK-NEXT: %2 = cir.load %0 : !cir.ptr<!s32i>, !s32i +// CHECK-NEXT: cir.return %2 : !s32i +// CHECK-NEXT: ^bb2: // no predecessors +// CHECK-NEXT: %3 = cir.const #cir.int<1> : !s32i +// CHECK-NEXT: cir.store{{.*}} %3, %0 : !s32i, !cir.ptr<!s32i> +// CHECK-NEXT: cir.br ^bb1 +// CHECK-NEXT: } diff --git a/clang/test/CIR/CodeGen/shift.cpp b/clang/test/CIR/CodeGen/shift.cpp new file mode 100644 index 0000000000000..6f6a10d34ab08 --- /dev/null +++ b/clang/test/CIR/CodeGen/shift.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +unsigned long s(int i, unsigned long x) { + return x << i; +} + +// CHECK: cir.shift(left, %3 : !u64i, %4 : !s32i) -> !u64i \ No newline at end of file diff --git a/clang/test/CIR/CodeGen/spelling-locations.cpp b/clang/test/CIR/CodeGen/spelling-locations.cpp new file mode 100644 index 0000000000000..66c09c88a029c --- /dev/null +++ b/clang/test/CIR/CodeGen/spelling-locations.cpp @@ -0,0 +1,100 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s +#define multiline_if_macro(c, t) \ +if (c) { \ + return t; \ +} + +int testMacroLocations(void) { + + // Expanded macros will use the location of the expansion site. + multiline_if_macro(1, 3); + // CHECK: cir.scope { + // CHECK: cir.if %{{.+}} { + // CHECK: cir.return %{{.+}} : !s32i loc(#loc[[#LOC:]]) + // CHECK: } loc(#loc[[#LOC]]) + // CHECK: } loc(#loc[[#LOC]]) + + // Regular if statements should use different locations. + if (1) { + return 3; + } + // CHECK: cir.scope { + // CHECK: cir.if %{{.+}} { + // CHECK: cir.return %{{.+}} : !s32i loc(#loc[[#LOC:]]) + // CHECK-NOT: } loc(#loc[[#LOC]]) + // CHECK-NOT: } loc(#loc[[#LOC]]) + + return 0; +} + +void testIfStmtLocations(int f) { + if (f) + ; + else + ; + + if (f) + ++f; + else + ; + + if (f) + ; + else + --f; + + if (f) + ++f; + else + --f; +} + +// CHECK: cir.if %{{.+}} { +// CHECK: } else { +// CHECK: } loc(#loc[[#LOC1:]]) + +// CHECK: cir.if %{{.+}} { +// CHECK: %{{.+}} = cir.load +// CHECK: %{{.+}} = cir.unary(inc +// CHECK: cir.store +// CHECK: } else { +// CHECK: } loc(#loc[[#LOC2:]]) + +// CHECK: cir.if %{{.+}} { +// CHECK: } else { +// CHECK: %{{.+}} = cir.load +// CHECK: %{{.+}} = cir.unary(dec +// CHECK: cir.store +// CHECK: } loc(#loc[[#LOC3:]]) + +// CHECK: cir.if %{{.+}} { +// CHECK: %{{.+}} = cir.load +// CHECK: %{{.+}} = cir.unary(inc +// CHECK: cir.store +// CHECK: } else { +// CHECK: %{{.+}} = cir.load +// CHECK: %{{.+}} = cir.unary(dec +// CHECK: cir.store +// CHECK: } loc(#loc[[#LOC4:]]) + +// CHECK: #loc[[#LOC12:]] = loc({{.+}}:35:5) +// CHECK: #loc[[#LOC11:]] = loc({{.+}}:33:5) + +// CHECK: #loc[[#LOC23:]] = loc({{.+}}:40:5) +// CHECK: #loc[[#LOC21:]] = loc({{.+}}:38:5) +// CHECK: #loc[[#LOC22:]] = loc({{.+}}:38:7) + +// CHECK: #loc[[#LOC33:]] = loc({{.+}}:45:7) +// CHECK: #loc[[#LOC31:]] = loc({{.+}}:43:5) +// CHECK: #loc[[#LOC32:]] = loc({{.+}}:45:5) + +// CHECK: #loc[[#LOC44:]] = loc({{.+}}:50:7) +// CHECK: #loc[[#LOC41:]] = loc({{.+}}:48:5) +// CHECK: #loc[[#LOC42:]] = loc({{.+}}:48:7) +// CHECK: #loc[[#LOC43:]] = loc({{.+}}:50:5) + +// CHECK: #loc[[#LOC1]] = loc(fused[#loc[[#LOC11]], #loc[[#LOC12]]]) +// CHECK: #loc[[#LOC2]] = loc(fused[#loc[[#LOC21]], #loc[[#LOC22]], #loc[[#LOC23]]]) +// CHECK: #loc[[#LOC3]] = loc(fused[#loc[[#LOC31]], #loc[[#LOC32]], #loc[[#LOC33]]]) +// CHECK: #loc[[#LOC4]] = loc(fused[#loc[[#LOC41]], #loc[[#LOC42]], #loc[[#LOC43]], #loc[[#LOC44]]]) diff --git a/clang/test/CIR/CodeGen/std-array.cpp b/clang/test/CIR/CodeGen/std-array.cpp new file mode 100644 index 0000000000000..cd9cc37a93367 --- /dev/null +++ b/clang/test/CIR/CodeGen/std-array.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -I%S/../Inputs -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +#include "std-cxx.h" + +void t() { + std::array<unsigned char, 9> v = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + (void)v.end(); +} + +// CHECK: ![[array:.*]] = !cir.record<struct "std::array<unsigned char, 9U>" + +// CHECK: cir.call @_ZNSt5arrayIhLj9EE3endEv diff --git a/clang/test/CIR/CodeGen/stmt-expr.c b/clang/test/CIR/CodeGen/stmt-expr.c new file mode 100644 index 0000000000000..cad7fc7eb1d6f --- /dev/null +++ b/clang/test/CIR/CodeGen/stmt-expr.c @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +// Yields void. +void test1() { ({ }); } +// CHECK: @test1 +// CHECK-NEXT: cir.return + + +// Yields an out-of-scope scalar. +void test2() { ({int x = 3; x; }); } +// CHECK: @test2 +// CHECK: %[[#RETVAL:]] = cir.alloca !s32i, !cir.ptr<!s32i> +// CHECK: cir.scope { +// CHECK: %[[#VAR:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] +// [...] +// CHECK: %[[#TMP:]] = cir.load{{.*}} %[[#VAR]] : !cir.ptr<!s32i>, !s32i +// CHECK: cir.store{{.*}} %[[#TMP]], %[[#RETVAL]] : !s32i, !cir.ptr<!s32i> +// CHECK: } +// CHECK: %{{.+}} = cir.load{{.*}} %[[#RETVAL]] : !cir.ptr<!s32i>, !s32i + +// Yields an aggregate. +struct S { int x; }; +int test3() { return ({ struct S s = {1}; s; }).x; } +// CHECK: @test3 +// CHECK: cir.scope { +// CHECK: %[[#REF_TMP:]] = cir.alloca !rec_S, !cir.ptr<!rec_S>, ["ref.tmp0"] +// CHECK: cir.scope { +// CHECK: %[[#VAR:]] = cir.alloca !rec_S, !cir.ptr<!rec_S> +// [...] +// CHECK: cir.copy %[[#VAR]] to %[[#REF_TMP]] : !cir.ptr<!rec_S> +// CHECK: } +// CHECK: %[[#RETADDR:]] = cir.get_member %[[#REF_TMP]][0] {name = "x"} : !cir.ptr<!rec_S> -> !cir.ptr<!s32i> +// CHECK: %{{.+}} = cir.load{{.*}} %[[#RETADDR]] : !cir.ptr<!s32i>, !s32i + +// Expression is wrapped in an expression attribute (just ensure it does not crash). +void test4(int x) { ({[[gsl::suppress("foo")]] x;}); } +// CHECK: @test4 + +// TODO(cir): Missing label support. +// // Expression is wrapped in a label. +// // void test5(int x) { x = ({ label: x; }); } diff --git a/clang/test/CIR/CodeGen/store.c b/clang/test/CIR/CodeGen/store.c new file mode 100644 index 0000000000000..7bf64773396ff --- /dev/null +++ b/clang/test/CIR/CodeGen/store.c @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +void foo(void) { + int a = 0; + a = 1; +} + +// CHECK: cir.func dso_local @foo() +// CHECK-NEXT: %0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init] {alignment = 4 : i64} +// CHECK-NEXT: %1 = cir.const #cir.int<0> : !s32i +// CHECK-NEXT: cir.store{{.*}} %1, %0 : !s32i, !cir.ptr<!s32i> +// CHECK-NEXT: %2 = cir.const #cir.int<1> : !s32i +// CHECK-NEXT: cir.store{{.*}} %2, %0 : !s32i, !cir.ptr<!s32i> +// CHECK-NEXT: cir.return +// CHECK-NEXT: } + +typedef int (*fn_t)(); +int get42() { return 42; } + +void storeNoArgsFn() { + fn_t f = get42; +} + +// CHECK: cir.func {{.*@storeNoArgsFn}} +// CHECK: %0 = cir.alloca +// CHECK: %1 = cir.get_global @get42 : !cir.ptr<!cir.func<() -> !s32i>> +// CHECK: %2 = cir.cast(bitcast, %1 : !cir.ptr<!cir.func<() -> !s32i>>), !cir.ptr<!cir.func<(...) -> !s32i>> +// CHECK: cir.store{{.*}} %2, %0 : !cir.ptr<!cir.func<(...) -> !s32i>>, !cir.ptr<!cir.ptr<!cir.func<(...) -> !s32i>>> diff --git a/clang/test/CIR/CodeGen/switch-unreachable-after-break.cpp b/clang/test/CIR/CodeGen/switch-unreachable-after-break.cpp new file mode 100644 index 0000000000000..5b72b3a02b9b5 --- /dev/null +++ b/clang/test/CIR/CodeGen/switch-unreachable-after-break.cpp @@ -0,0 +1,49 @@ +// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +// CHECK: _Z23unreachable_after_breaki +void unreachable_after_break(int a) { + switch(a) { + case 0: + break; + break; + int x = 1; + } + // cir.switch + // cir.case(equal, [#cir.int<0> : !s32i]) { + // cir.break + // ^bb{{.*}}: // no predecessors + // cir.break + // ^bb{{.*}}: // no predecessors + // %[[CONST:.*]] = cir.const #cir.int<1> : !s32i + // cir.store align(4) {{.*}}, %[[CONST]] + // cir.yield +} + +// CHECK: _Z24unreachable_after_returni +int unreachable_after_return(int a) { + switch (a) { + case 0: + return 0; + return 1; + int x = 3; + } + return 2; + // cir.switch + // cir.case(equal, [#cir.int<0> : !s32i]) { + // %[[CONST_ZERO:.*]] = cir.const #cir.int<0> : !s32i + // cir.store {{.*}}, %[[CONST_ZERO]] + // cir.br ^bb1 + // ^bb1: // 2 preds: ^bb0, ^bb2 + // cir.load + // cir.return + // ^bb2: // no predecessors + // %[[CONST_ONE:.*]] = cir.const #cir.int<1> : !s32i + // cir.store %[[CONST_ONE]] + // cir.br ^bb1 + // ^bb3: // no predecessors + // %[[CONST_THREE:.*]] = cir.const #cir.int<3> : !s32i + // cir.store align(4) %[[CONST_THREE]] + // cir.yield + // } +} diff --git a/clang/test/CIR/CodeGen/trap.cpp b/clang/test/CIR/CodeGen/trap.cpp new file mode 100644 index 0000000000000..83e9be7230d2b --- /dev/null +++ b/clang/test/CIR/CodeGen/trap.cpp @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +void foo(); + +void basic() { + foo(); + __builtin_trap(); +} + +// CHECK: cir.func dso_local @_Z5basicv() +// CHECK-NEXT: cir.call @_Z3foov() : () -> () +// CHECK-NEXT: cir.trap +// CHECK-NEXT: } + +void code_after_unreachable() { + foo(); + __builtin_trap(); + foo(); +} + +// CHECK: cir.func dso_local @_Z22code_after_unreachablev() +// CHECK-NEXT: cir.call @_Z3foov() : () -> () +// CHECK-NEXT: cir.trap +// CHECK-NEXT: ^bb1: +// CHECK-NEXT: cir.call @_Z3foov() : () -> () +// CHECK-NEXT: cir.return +// CHECK-NEXT: } diff --git a/clang/test/CIR/CodeGen/types-IEEE-quad.c b/clang/test/CIR/CodeGen/types-IEEE-quad.c new file mode 100644 index 0000000000000..c56b3e7ca6d2b --- /dev/null +++ b/clang/test/CIR/CodeGen/types-IEEE-quad.c @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir --check-prefix=CIR %s +// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -emit-llvm %s -o %t.ll +// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s + +long double i = 0; +long double t2(long double i2) { + return i2 + i ; +} + +// CIR: cir.global external @i = #cir.fp<0.000000e+00> : !cir.long_double<!cir.f128> {alignment = 16 : i64} loc({{.*}}) +// CIR-LABEL: cir.func dso_local @t2(%arg0: !cir.long_double<!cir.f128> loc({{.*}})) -> !cir.long_double<!cir.f128> +// CIR-NEXT: %[[#I2:]] = cir.alloca !cir.long_double<!cir.f128>, !cir.ptr<!cir.long_double<!cir.f128>>, ["i2", init] {alignment = 16 : i64} +// CIR-NEXT: %[[#RETVAL:]] = cir.alloca !cir.long_double<!cir.f128>, !cir.ptr<!cir.long_double<!cir.f128>>, ["__retval"] {alignment = 16 : i64} +// CIR-NEXT: cir.store %arg0, %[[#I2]] : !cir.long_double<!cir.f128>, !cir.ptr<!cir.long_double<!cir.f128>> +// CIR-NEXT: %[[#I2_LOAD:]] = cir.load{{.*}} %[[#I2]] : !cir.ptr<!cir.long_double<!cir.f128>>, !cir.long_double<!cir.f128> +// CIR-NEXT: %[[#I:]] = cir.get_global @i : !cir.ptr<!cir.long_double<!cir.f128>> +// CIR-NEXT: %[[#I_LOAD:]] = cir.load{{.*}} %[[#I]] : !cir.ptr<!cir.long_double<!cir.f128>>, !cir.long_double<!cir.f128> +// CIR-NEXT: %[[#ADD:]] = cir.binop(add, %[[#I2_LOAD]], %[[#I_LOAD]]) : !cir.long_double<!cir.f128> +// CIR-NEXT: cir.store %[[#ADD]], %[[#RETVAL]] : !cir.long_double<!cir.f128>, !cir.ptr<!cir.long_double<!cir.f128>> +// CIR-NEXT: %[[#RETVAL_LOAD:]] = cir.load{{.*}} %[[#RETVAL]] : !cir.ptr<!cir.long_double<!cir.f128>>, !cir.long_double<!cir.f128> +// CIR-NEXT: cir.return %[[#RETVAL_LOAD]] : !cir.long_double<!cir.f128> + +//LLVM: @i = global fp128 0xL00000000000000000000000000000000, align 16 +//LLVM-LABEL: define dso_local fp128 @t2(fp128 noundef %i2) +//LLVM-NEXT : entry: +//LLVM-NEXT : %[[#I2_ADDR:]]= alloca fp128, align 16 +//LLVM-NEXT : store fp128 %i2, ptr %[[#I2_ADDR]], align 16 +//LLVM-NEXT : %[[#I2_LOAD:]] = load fp128, ptr %[[#I2_ADDR]], align 16 +//LLVM-NEXT : %[[#I_LOAD:]] = load fp128, ptr @i, align 16 +//LLVM-NEXT : %[[#RETVAL:]] = fadd fp128 %[[#I2_LOAD]], %[[#I_LOAD]] +//LLVM-NEXT : ret fp128 %[[#RETVAL]] diff --git a/clang/test/CIR/CodeGen/types-nullptr.cpp b/clang/test/CIR/CodeGen/types-nullptr.cpp new file mode 100644 index 0000000000000..a598a1a724f6e --- /dev/null +++ b/clang/test/CIR/CodeGen/types-nullptr.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +typedef decltype(nullptr) nullptr_t; +void f() { nullptr_t t = nullptr; } + +// CHECK: %0 = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> +// CHECK: %1 = cir.const #cir.ptr<null> : !cir.ptr<!void> +// CHECK: cir.store{{.*}} %1, %0 : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> diff --git a/clang/test/CIR/CodeGen/types.c b/clang/test/CIR/CodeGen/types.c new file mode 100644 index 0000000000000..d409514a81d56 --- /dev/null +++ b/clang/test/CIR/CodeGen/types.c @@ -0,0 +1,46 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s +// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cpp.cir +// RUN: FileCheck --input-file=%t.cpp.cir --check-prefix=CHECK-CPP %s + +int t0(int i) { return i; } +unsigned int t1(unsigned int i) { return i; } + +char t2(char i) { return i; } +unsigned char t3(unsigned char i) { return i; } + +short t4(short i) { return i; } +unsigned short t5(unsigned short i) { return i; } + +float t6(float i) { return i; } +double t7(double i) { return i; } +long double t10(long double i) { return i; } + +void t8(void) {} + +#ifdef __cplusplus +bool t9(bool b) { return b; } +#endif + +// CHECK: cir.func dso_local @t0(%arg0: !s32i loc({{.*}})) -> !s32i +// CHECK: cir.func dso_local @t1(%arg0: !u32i loc({{.*}})) -> !u32i +// CHECK: cir.func dso_local @t2(%arg0: !s8i loc({{.*}})) -> !s8i +// CHECK: cir.func dso_local @t3(%arg0: !u8i loc({{.*}})) -> !u8i +// CHECK: cir.func dso_local @t4(%arg0: !s16i loc({{.*}})) -> !s16i +// CHECK: cir.func dso_local @t5(%arg0: !u16i loc({{.*}})) -> !u16i +// CHECK: cir.func dso_local @t6(%arg0: !cir.float loc({{.*}})) -> !cir.float +// CHECK: cir.func dso_local @t7(%arg0: !cir.double loc({{.*}})) -> !cir.double +// CHECK: cir.func dso_local @t10(%arg0: !cir.long_double<!cir.f80> loc({{.*}})) -> !cir.long_double<!cir.f80> +// CHECK: cir.func dso_local @t8() + +// CHECK-CPP: cir.func dso_local @_Z2t0i(%arg0: !s32i loc({{.*}})) -> !s32i +// CHECK-CPP: cir.func dso_local @_Z2t1j(%arg0: !u32i loc({{.*}})) -> !u32i +// CHECK-CPP: cir.func dso_local @_Z2t2c(%arg0: !s8i loc({{.*}})) -> !s8i +// CHECK-CPP: cir.func dso_local @_Z2t3h(%arg0: !u8i loc({{.*}})) -> !u8i +// CHECK-CPP: cir.func dso_local @_Z2t4s(%arg0: !s16i loc({{.*}})) -> !s16i +// CHECK-CPP: cir.func dso_local @_Z2t5t(%arg0: !u16i loc({{.*}})) -> !u16i +// CHECK-CPP: cir.func dso_local @_Z2t6f(%arg0: !cir.float loc({{.*}})) -> !cir.float +// CHECK-CPP: cir.func dso_local @_Z2t7d(%arg0: !cir.double loc({{.*}})) -> !cir.double +// CHECK-CPP: cir.func dso_local @{{.+}}t10{{.+}}(%arg0: !cir.long_double<!cir.f80> loc({{.*}})) -> !cir.long_double<!cir.f80> +// CHECK-CPP: cir.func dso_local @_Z2t8v() +// CHECK-CPP: cir.func dso_local @_Z2t9b(%arg0: !cir.bool loc({{.*}})) -> !cir.bool diff --git a/clang/test/CIR/CodeGen/unary.c b/clang/test/CIR/CodeGen/unary.c new file mode 100644 index 0000000000000..ebcae89e2bdb0 --- /dev/null +++ b/clang/test/CIR/CodeGen/unary.c @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -Wno-unused-value -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +int valueNegationInt(int i) { +// CHECK: cir.func dso_local @valueNegationInt( + return !i; + // CHECK: %[[#INT:]] = cir.load{{.*}} %{{[0-9]+}} : !cir.ptr<!s32i>, !s32i + // CHECK: %[[#INT_TO_BOOL:]] = cir.cast(int_to_bool, %[[#INT]] : !s32i), !cir.bool + // CHECK: = cir.unary(not, %[[#INT_TO_BOOL]]) : !cir.bool, !cir.bool +} + +short valueNegationShort(short s) { +// CHECK: cir.func dso_local @valueNegationShort( + return !s; + // CHECK: %[[#SHORT:]] = cir.load{{.*}} %{{[0-9]+}} : !cir.ptr<!s16i>, !s16i + // CHECK: %[[#SHORT_TO_BOOL:]] = cir.cast(int_to_bool, %[[#SHORT]] : !s16i), !cir.bool + // CHECK: = cir.unary(not, %[[#SHORT_TO_BOOL]]) : !cir.bool, !cir.bool +} + +long valueNegationLong(long l) { +// CHECK: cir.func dso_local @valueNegationLong( + return !l; + // CHECK: %[[#LONG:]] = cir.load{{.*}} %{{[0-9]+}} : !cir.ptr<!s64i>, !s64i + // CHECK: %[[#LONG_TO_BOOL:]] = cir.cast(int_to_bool, %[[#LONG]] : !s64i), !cir.bool + // CHECK: = cir.unary(not, %[[#LONG_TO_BOOL]]) : !cir.bool, !cir.bool +} + +float valueNegationFloat(float f) { +// CHECK: cir.func dso_local @valueNegationFloat( + return !f; + // CHECK: %[[#FLOAT:]] = cir.load{{.*}} %{{[0-9]+}} : !cir.ptr<!cir.float>, !cir.float + // CHECK: %[[#FLOAT_TO_BOOL:]] = cir.cast(float_to_bool, %[[#FLOAT]] : !cir.float), !cir.bool + // CHECK: %[[#FLOAT_NOT:]] = cir.unary(not, %[[#FLOAT_TO_BOOL]]) : !cir.bool, !cir.bool + // CHECK: = cir.cast(bool_to_int, %[[#FLOAT_NOT]] : !cir.bool), !s32i +} + +double valueNegationDouble(double d) { +// CHECK: cir.func dso_local @valueNegationDouble( + return !d; + // CHECK: %[[#DOUBLE:]] = cir.load{{.*}} %{{[0-9]+}} : !cir.ptr<!cir.double>, !cir.double + // CHECK: %[[#DOUBLE_TO_BOOL:]] = cir.cast(float_to_bool, %[[#DOUBLE]] : !cir.double), !cir.bool + // CHECK: %[[#DOUBLE_NOT:]] = cir.unary(not, %[[#DOUBLE_TO_BOOL]]) : !cir.bool, !cir.bool + // CHECK: = cir.cast(bool_to_int, %[[#DOUBLE_NOT]] : !cir.bool), !s32i +} diff --git a/clang/test/CIR/CodeGen/unreachable.cpp b/clang/test/CIR/CodeGen/unreachable.cpp new file mode 100644 index 0000000000000..07c4fc434e4ee --- /dev/null +++ b/clang/test/CIR/CodeGen/unreachable.cpp @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +void foo(); + +void basic() { + foo(); + __builtin_unreachable(); +} + +// CHECK: cir.func dso_local @_Z5basicv() +// CHECK-NEXT: cir.call @_Z3foov() : () -> () +// CHECK-NEXT: cir.unreachable +// CHECK-NEXT: } + +void code_after_unreachable() { + foo(); + __builtin_unreachable(); + foo(); +} + +// CHECK: cir.func dso_local @_Z22code_after_unreachablev() +// CHECK: cir.call @_Z3foov() : () -> () +// CHECK: cir.unreachable +// CHECK: ^{{.+}}: +// CHECK: cir.call @_Z3foov() : () -> () +// CHECK: cir.return +// CHECK: } diff --git a/clang/test/CIR/Lowering/bitfieils.c b/clang/test/CIR/Lowering/bitfieils.c new file mode 100644 index 0000000000000..19de2ab194d41 --- /dev/null +++ b/clang/test/CIR/Lowering/bitfieils.c @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM + +typedef struct { + int a : 4; +} B; + +// LLVM: define dso_local void @set_signed +// LLVM: [[TMP0:%.*]] = load ptr +// LLVM: [[TMP1:%.*]] = getelementptr %struct.B, ptr [[TMP0]], i32 0, i32 0 +// LLVM: [[TMP2:%.*]] = load i8, ptr [[TMP1]] +// LLVM: [[TMP3:%.*]] = and i8 [[TMP2]], -16 +// LLVM: [[TMP4:%.*]] = or i8 [[TMP3]], 14 +// LLVM: store i8 [[TMP4]], ptr [[TMP1]] +void set_signed(B* b) { + b->a = -2; +} + +// LLVM: define dso_local i32 @get_signed +// LLVM: [[TMP0:%.*]] = alloca i32 +// LLVM: [[TMP1:%.*]] = load ptr +// LLVM: [[TMP2:%.*]] = getelementptr %struct.B, ptr [[TMP1]], i32 0, i32 0 +// LLVM: [[TMP3:%.*]] = load i8, ptr [[TMP2]] +// LLVM: [[TMP4:%.*]] = shl i8 [[TMP3]], 4 +// LLVM: [[TMP5:%.*]] = ashr i8 [[TMP4]], 4 +// LLVM: [[TMP6:%.*]] = sext i8 [[TMP5]] to i32 +// LLVM: store i32 [[TMP6]], ptr [[TMP0]] +// LLVM: [[TMP7:%.*]] = load i32, ptr [[TMP0]] +// LLVM: ret i32 [[TMP7]] +int get_signed(B* b) { + return b->a; +} diff --git a/clang/test/CIR/Lowering/global-ptr.c b/clang/test/CIR/Lowering/global-ptr.c new file mode 100644 index 0000000000000..a283ba0389524 --- /dev/null +++ b/clang/test/CIR/Lowering/global-ptr.c @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM + +// LLVM: %struct.S1 = type { [3200 x double], [3200 x double] } +// LLVM: %struct.S2 = type { [10 x ptr] } +// LLVM: %struct.S3 = type { [2000 x i32], [2000 x i32], [2000 x i32] } +// LLVM: %struct.S4 = type { i32, i32, i32 } +// LLVM: %union.U1 = type { [2000 x i32] } + +// Note: GEP emitted by cir might not be the same as LLVM, due to constant folding. +// LLVM: @s1 = global %struct.S1 zeroinitializer, align 8 +// LLVM: @b1 = global ptr getelementptr inbounds nuw (i8, ptr @s1, i64 25600), align 8 +// LLVM: @s2 = global %struct.S2 zeroinitializer, align 8 +// LLVM: @b2 = global ptr @s2, align 8 +// LLVM: @s3 = global %struct.S3 zeroinitializer, align 4 +// LLVM: @b3 = global ptr getelementptr inbounds nuw (i8, ptr @s3, i64 16000), align 8 +// LLVM: @s4 = global %struct.S4 zeroinitializer, align 4 +// LLVM: @b4 = global ptr getelementptr inbounds nuw (i8, ptr @s4, i64 8), align 8 +// LLVM: @u1 = global %union.U1 zeroinitializer, align 4 +// LLVM: @b5 = global ptr @u1, align 8 + +struct S1 { + double a[3200]; + double b[3200]; +} s1; + +double *b1 = s1.b; + +struct S2 { + double* a[10]; +} s2; + +double **b2 = s2.a; + +struct S3 { + int a[2000]; + int b[2000]; + int c[2000]; +} s3; + +double *b3 = s3.c; + +struct S4 { + int a, b, c; +} s4; + +int* b4 = &s4.c; + +union U1 { + int a[2000]; + int b[2000]; + int c[2000]; +} u1; + +double *b5 = u1.a; diff --git a/clang/test/CIR/Lowering/nested-switch.cpp b/clang/test/CIR/Lowering/nested-switch.cpp new file mode 100644 index 0000000000000..5f6961a84018f --- /dev/null +++ b/clang/test/CIR/Lowering/nested-switch.cpp @@ -0,0 +1,69 @@ +// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s + +int nested_switch(int a) { + switch (int b = 1; a) { + case 0: + b = b + 1; + case 1: + return b; + case 2: { + b = b + 1; + if (a > 1000) { + case 9: + b += a; + } + if (a > 500) { + case 7: + return a + b; + } + break; + } + } + + return 0; +} + +// CHECK: define {{.*}}@_Z13nested_switchi( +// CHECK: switch i32 %6, label %[[DEFAULT_BB:[0-9]+]] [ +// CHECK: i32 0, label %[[ZERO_BB:[0-9]+]] +// CHECK: i32 1, label %[[ONE_BB:[0-9]+]] +// CHECK: i32 2, label %[[TWO_BB:[0-9]+]] +// CHECK: i32 9, label %[[NINE_BB:[0-9]+]] +// CHECK: i32 7, label %[[SEVEN_BB:[0-9]+]] +// CHECK: ] +// +// CHECK: [[ZERO_BB]]: +// CHECK: add {{.*}}, 1 +// CHECK: br label %[[ONE_BB]] +// +// CHECK: [[ONE_BB]]: +// CHECK: ret +// +// CHECK: [[TWO_BB]]: +// CHECK: add {{.*}}, 1 +// CHECK: br label %[[IF_BB:[0-9]+]] +// +// CHECK: [[IF_BB]]: +// CHECK: %[[CMP:.+]] = icmp sgt i32 %{{.*}}, 1000 +// CHECK: br i1 %[[CMP]], label %[[IF_TRUE_BB:[0-9]+]], label %[[IF_FALSE_BB:[0-9]+]] +// +// CHECK: [[IF_TRUE_BB]]: +// CHECK: br label %[[NINE_BB]] +// +// CHECK: [[NINE_BB]]: +// CHECK: %[[A_VALUE:.+]] = load i32 +// CHECK: %[[B_VALUE:.+]] = load i32 +// CHECK: add nsw i32 %[[B_VALUE]], %[[A_VALUE]] +// +// CHECK: %[[CMP2:.+]] = icmp sgt i32 %{{.*}}, 500 +// CHECK: br i1 %[[CMP2]], label %[[IF2_TRUE_BB:[0-9]+]], label %[[IF2_FALSE_BB:[0-9]+]] +// +// CHECK: [[IF2_TRUE_BB]]: +// CHECK: br label %[[SEVEN_BB]] +// +// CHECK: [[SEVEN_BB]]: +// CHECK: ret +// +// CHECK: [[DEFAULT_BB]]: +// CHECK: ret diff --git a/clang/test/CIR/Lowering/str.c b/clang/test/CIR/Lowering/str.c new file mode 100644 index 0000000000000..cc393daee884f --- /dev/null +++ b/clang/test/CIR/Lowering/str.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM + +void f(char *fmt, ...); +void test() { + f("test\0"); +} + +// LLVM: @.str = {{.*}}[6 x i8] c"test\00\00" diff --git a/clang/test/CIR/Lowering/switch-while.c b/clang/test/CIR/Lowering/switch-while.c new file mode 100644 index 0000000000000..9123d55329607 --- /dev/null +++ b/clang/test/CIR/Lowering/switch-while.c @@ -0,0 +1,84 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s +void func100(); +int f(int a, int cond) { + int b = 1; + switch (a) + while (1) { + b++; + + default: + if (cond) + return a; + + a = a + b; + + case 2: + a++; + + case 3: + continue; + + case 5: + break; + + case 100: + func100(); + } + + return a; +} + +// CHECK: switch i32 %[[A:.+]], label %[[DEFAULT_BB:.+]] [ +// CHECK: i32 2, label %[[TWO_BB:.+]] +// CHECK: i32 3, label %[[THREE_BB:.+]] +// CHECK: i32 5, label %[[FIVE_BB:.+]] +// CHECK: i32 100, label %[[HUNDRED_BB:.+]] +// CHECK: ] +// +// CHECK: [[UNREACHABLE_BB:.+]]: {{.*}}; No predecessors! +// +// CHECK: [[LOOP_ENTRY:.+]]: +// CHECK: br label %[[LOOP_HEADER:.+]] +// +// CHECK: [[LOOP_HEADER]]: +// CHECK: add nsw i32 %{{.*}}, 1 +// CHECK: br label %[[DEFAULT_BB:.+]] +// +// CHECK: [[DEFAULT_BB]]: +// CHECK: br label %[[IF_BB:.+]] +// +// CHECK: [[IF_BB]]: +// CHECK: %[[CMP:.+]] = icmp ne i32 %[[COND:.+]], 0 +// CHECK: br i1 %[[CMP]], label %[[IF_TRUE_BB:.+]], label %[[IF_FALSE_BB:.+]] +// +// CHECK: [[IF_TRUE_BB]]: +// CHECK: ret +// +// CHECK: [[IF_FALSE_BB]]: +// CHECK: %[[V1:.+]] = load i32 +// CHECK: %[[V2:.+]] = load i32 +// CHECK: add nsw i32 %[[V1]], %[[V2]] +// +// CHECK: [[TWO_BB]]: +// CHECK: add nsw i32 %{{.*}}, 1 +// CHECK: br label %[[FALLTHOUGH_BB:.+]] +// +// CHECK: [[FALLTHOUGH_BB]]: +// CHECK: br label %[[LOOP_HEADER]] +// +// CHECK: [[FIVE_BB]]: +// CHECK: br label %[[LOOP_EXIT_BB:.+]] +// +// CHECK: [[HUNDRED_BB]]: +// CHECK: call {{.*}}@func100() +// CHECK: br label %[[CONTINUE_BB:.+]] +// +// CHECK: [[CONTINUE_BB]]: +// CHECK: br label %[[LOOP_HEADER]] +// +// CHECK: [[LOOP_EXIT_BB]]: +// CHECK: br label %[[RET_BB:.+]] +// +// CHECK: [[RET_BB]]: +// CHECK: ret diff --git a/clang/test/CIR/hello.c b/clang/test/CIR/hello.c new file mode 100644 index 0000000000000..077f5c6ac908f --- /dev/null +++ b/clang/test/CIR/hello.c @@ -0,0 +1,5 @@ +// Smoke test for ClangIR code generation +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - | FileCheck %s + +void foo() {} +// CHECK: cir.func no_proto dso_local @foo diff --git a/clang/test/CIR/test.c b/clang/test/CIR/test.c new file mode 100644 index 0000000000000..5c1031cccc41a --- /dev/null +++ b/clang/test/CIR/test.c @@ -0,0 +1 @@ +// RUN: true From 57dbc230e896b187b42d13b628ab130a2d9ba509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burhan=20S=C3=B6=C4=9F=C3=BCt?= <burhan.sog...@gmail.com> Date: Tue, 9 Sep 2025 09:29:58 +0300 Subject: [PATCH 2/9] Update clang/test/CIR/CodeGen/binassign.cpp Co-authored-by: Andy Kaylor <akay...@nvidia.com> --- clang/test/CIR/CodeGen/binassign.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/CIR/CodeGen/binassign.cpp b/clang/test/CIR/CodeGen/binassign.cpp index 934742d13404a..567c259dfc6b9 100644 --- a/clang/test/CIR/CodeGen/binassign.cpp +++ b/clang/test/CIR/CodeGen/binassign.cpp @@ -16,7 +16,7 @@ int foo(int a, int b) { return x; } -// CHECK: [[Value:%[0-9]+]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] {alignment = 4 : i64} +// CHECK: [[Value:%[0-9]+]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] // CHECK: = cir.binop(mul, // CHECK: = cir.load {{.*}}[[Value]] // CHECK: = cir.binop(mul, From 813e014bc0f60527f7b7d93753bd0fbc4670534f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burhan=20S=C3=B6=C4=9F=C3=BCt?= <burhan.sog...@gmail.com> Date: Tue, 9 Sep 2025 09:30:32 +0300 Subject: [PATCH 3/9] Update clang/test/CIR/CodeGen/binassign.cpp Co-authored-by: Andy Kaylor <akay...@nvidia.com> --- clang/test/CIR/CodeGen/binassign.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/CIR/CodeGen/binassign.cpp b/clang/test/CIR/CodeGen/binassign.cpp index 567c259dfc6b9..ab5dab7797c6e 100644 --- a/clang/test/CIR/CodeGen/binassign.cpp +++ b/clang/test/CIR/CodeGen/binassign.cpp @@ -25,7 +25,7 @@ int foo(int a, int b) { // CHECK: cir.binop(div, // CHECK: cir.store{{.*}} {{.*}}[[Value]] // CHECK: = cir.load {{.*}}[[Value]] -// CHECK: = cir.binop(rem, {{.*}} loc([[SourceLocation:#loc[0-9]+]]) +// CHECK: = cir.binop(rem, // CHECK: cir.store{{.*}} {{.*}}[[Value]] // CHECK: = cir.load {{.*}}[[Value]] // CHECK: = cir.binop(add, From cdceaa317a90602b7da28642184df5dd6f946edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burhan=20S=C3=B6=C4=9F=C3=BCt?= <burhan.sog...@gmail.com> Date: Tue, 9 Sep 2025 10:20:19 +0300 Subject: [PATCH 4/9] Delete clang/test/CIR/CodeGen/OpenMP/taskwait.cpp --- clang/test/CIR/CodeGen/OpenMP/taskwait.cpp | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 clang/test/CIR/CodeGen/OpenMP/taskwait.cpp diff --git a/clang/test/CIR/CodeGen/OpenMP/taskwait.cpp b/clang/test/CIR/CodeGen/OpenMP/taskwait.cpp deleted file mode 100644 index 3b2059a8b9655..0000000000000 --- a/clang/test/CIR/CodeGen/OpenMP/taskwait.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// TODO: fix crash in emitTaskWaitCall -// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fopenmp-enable-irbuilder -fopenmp -fclangir -emit-cir %s -o %t.cir -// RUN: FileCheck --input-file=%t.cir %s - -// CHECK: cir.func -void omp_taskwait_1(){ -// CHECK-DISABLE: omp.taskwait -// #pragma omp taskwait -} From 7591d38f707a34756ccf7c5707b10c5d84f8b51d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burhan=20S=C3=B6=C4=9F=C3=BCt?= <burhan.sog...@gmail.com> Date: Tue, 9 Sep 2025 10:20:46 +0300 Subject: [PATCH 5/9] Delete clang/test/CIR/CodeGen/StringExample.cpp --- clang/test/CIR/CodeGen/StringExample.cpp | 34 ------------------------ 1 file changed, 34 deletions(-) delete mode 100644 clang/test/CIR/CodeGen/StringExample.cpp diff --git a/clang/test/CIR/CodeGen/StringExample.cpp b/clang/test/CIR/CodeGen/StringExample.cpp deleted file mode 100644 index a2c0ef374f1ca..0000000000000 --- a/clang/test/CIR/CodeGen/StringExample.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// RUN: true - -int strlen(char const *); -void puts(char const *); - -struct String { - long size; - long capacity; - char *storage; - - String() : size{0}, capacity{0}, storage{nullptr} {} - String(char const *s) : size{strlen(s)}, capacity{size}, - storage{new char[capacity]} {} -}; - -struct StringView { - long size; - char *storage; - - StringView(const String &s) : size{s.size}, storage{s.storage} {} - StringView() : size{0}, storage{nullptr} {} -}; - -int main() { - StringView sv; - { - String s = "Hi"; - sv = s; - - puts(sv.storage); - } - - puts(sv.storage); -} From bca917d010f8f74224f9437240bf3bb463416b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burhan=20S=C3=B6=C4=9F=C3=BCt?= <burhan.sog...@gmail.com> Date: Tue, 9 Sep 2025 10:22:17 +0300 Subject: [PATCH 6/9] Update binassign.cpp --- clang/test/CIR/CodeGen/binassign.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/CIR/CodeGen/binassign.cpp b/clang/test/CIR/CodeGen/binassign.cpp index ab5dab7797c6e..fc60da8687f56 100644 --- a/clang/test/CIR/CodeGen/binassign.cpp +++ b/clang/test/CIR/CodeGen/binassign.cpp @@ -61,7 +61,7 @@ void exec() { } // CHECK: cir.func dso_local @_Z4execv() -// CHECK: %0 = cir.alloca !u32i, !cir.ptr<!u32i>, ["r"] {alignment = 4 : i64} +// CHECK: %0 = cir.alloca !u32i, !cir.ptr<!u32i>, ["r"] // CHECK: cir.scope { // CHECK: %1 = cir.call @_Z5gettyv() : () -> !u32i // CHECK: cir.store{{.*}} %1, %0 : !u32i, !cir.ptr<!u32i> From 39ce12f168b5bfc9b6b11591e88dc89511a65df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burhan=20S=C3=B6=C4=9F=C3=BCt?= <burhan.sog...@gmail.com> Date: Tue, 9 Sep 2025 10:23:46 +0300 Subject: [PATCH 7/9] Update binassign.cpp --- clang/test/CIR/CodeGen/binassign.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/clang/test/CIR/CodeGen/binassign.cpp b/clang/test/CIR/CodeGen/binassign.cpp index fc60da8687f56..c33cdfd228871 100644 --- a/clang/test/CIR/CodeGen/binassign.cpp +++ b/clang/test/CIR/CodeGen/binassign.cpp @@ -69,7 +69,3 @@ void exec() { // CHECK: %3 = cir.const #cir.int<0> : !s32i // CHECK: %4 = cir.cmp(lt, %2, %3) : !s32i, !cir.bool // CHECK: cir.if %4 { - -// CHECK: [[SourceLocationB:#loc[0-9]+]] = loc("{{.*}}binassign.cpp":8:8) -// CHECK: [[SourceLocationA:#loc[0-9]+]] = loc("{{.*}}binassign.cpp":8:3) -// CHECK: [[SourceLocation]] = loc(fused[[[SourceLocationA]], [[SourceLocationB]]]) From 0ffceff70b7c919b7a798e0c451a8cf9b6a37024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burhan=20S=C3=B6=C4=9F=C3=BCt?= <burhan.sog...@gmail.com> Date: Tue, 9 Sep 2025 10:25:46 +0300 Subject: [PATCH 8/9] Delete clang/test/CIR/CodeGen/bswap.cpp --- clang/test/CIR/CodeGen/bswap.cpp | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 clang/test/CIR/CodeGen/bswap.cpp diff --git a/clang/test/CIR/CodeGen/bswap.cpp b/clang/test/CIR/CodeGen/bswap.cpp deleted file mode 100644 index 3473b64ac7228..0000000000000 --- a/clang/test/CIR/CodeGen/bswap.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -emit-cir %s -o %t.cir -// RUN: FileCheck --input-file=%t.cir %s - -using u16 = unsigned short; -using u32 = unsigned int; -using u64 = unsigned long long; - -u16 bswap_u16(u16 x) { - return __builtin_bswap16(x); -} - -// CHECK: cir.func dso_local @_Z9bswap_u16t -// CHECK: %{{.+}} = cir.byte_swap %{{.+}} : !u16i -// CHECK: } - -u32 bswap_u32(u32 x) { - return __builtin_bswap32(x); -} - -// CHECK: cir.func dso_local @_Z9bswap_u32j -// CHECK: %{{.+}} = cir.byte_swap %{{.+}} : !u32i -// CHECK: } - -u64 bswap_u64(u64 x) { - return __builtin_bswap64(x); -} - -// CHECK: cir.func dso_local @_Z9bswap_u64y -// CHECK: %{{.+}} = cir.byte_swap %{{.+}} : !u64i -// CHECK: } From c977bca98f69ad64b5ddf3ae6b656a87b6cb3c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burhan=20S=C3=B6=C4=9F=C3=BCt?= <burhan.sog...@gmail.com> Date: Tue, 9 Sep 2025 10:27:49 +0300 Subject: [PATCH 9/9] Update if-constexpr.cpp --- clang/test/CIR/CodeGen/if-constexpr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/CIR/CodeGen/if-constexpr.cpp b/clang/test/CIR/CodeGen/if-constexpr.cpp index dd13591be17f4..4ce44bfa6cba0 100644 --- a/clang/test/CIR/CodeGen/if-constexpr.cpp +++ b/clang/test/CIR/CodeGen/if-constexpr.cpp @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir -// RUN: FileCheck --input-file=%t.cir %s +// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR void if0() { int x = 0; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits