llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Burhan Söğüt (bursot) <details> <summary>Changes</summary> These tests were migrated from `clang/test/CIR-Incubator` to `clang/test/CIR` without modification. - Only tests that pass under the current configuration were moved. - No refactors, no removals, no CMake or lit changes were made. - This is part of the incremental upstreaming effort. Test discovery and migration were semi-automated based on lit output. cc: @<!-- -->AndyNZhang --- Patch is 72.49 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/157333.diff 48 Files Affected: - (added) clang/test/CIR/CodeGen/OpenMP/taskwait.cpp (+9) - (added) clang/test/CIR/CodeGen/StringExample.cpp (+34) - (added) clang/test/CIR/CodeGen/binassign.cpp (+75) - (added) clang/test/CIR/CodeGen/bswap.cpp (+30) - (added) clang/test/CIR/CodeGen/c89-implicit-int.c (+10) - (added) clang/test/CIR/CodeGen/comma.cpp (+30) - (added) clang/test/CIR/CodeGen/complex-cast.c (+264) - (added) clang/test/CIR/CodeGen/compound-literal-empty.c (+18) - (added) clang/test/CIR/CodeGen/expressions.cpp (+11) - (added) clang/test/CIR/CodeGen/func_dsolocal_pie.c (+34) - (added) clang/test/CIR/CodeGen/gnu89.c (+5) - (added) clang/test/CIR/CodeGen/if-constexpr.cpp (+92) - (added) clang/test/CIR/CodeGen/implicit-return.cpp (+26) - (added) clang/test/CIR/CodeGen/inc-bool.cpp (+14) - (added) clang/test/CIR/CodeGen/inc-dec.cpp (+55) - (added) clang/test/CIR/CodeGen/lalg.c (+20) - (added) clang/test/CIR/CodeGen/literals.c (+9) - (added) clang/test/CIR/CodeGen/literals.cpp (+8) - (added) clang/test/CIR/CodeGen/loop-scope.cpp (+32) - (added) clang/test/CIR/CodeGen/lvalue-refs.cpp (+19) - (added) clang/test/CIR/CodeGen/ms-intrinsics-other.c (+55) - (added) clang/test/CIR/CodeGen/no-pie.c (+11) - (added) clang/test/CIR/CodeGen/no-proto-fun-ptr.c (+27) - (added) clang/test/CIR/CodeGen/no-proto-is-void.cpp (+13) - (added) clang/test/CIR/CodeGen/null-arithmatic-expression.c (+12) - (added) clang/test/CIR/CodeGen/operators.cpp (+14) - (added) clang/test/CIR/CodeGen/optimization-attr.cpp (+32) - (added) clang/test/CIR/CodeGen/pointer.cpp (+6) - (added) clang/test/CIR/CodeGen/return.cpp (+33) - (added) clang/test/CIR/CodeGen/shift.cpp (+8) - (added) clang/test/CIR/CodeGen/spelling-locations.cpp (+100) - (added) clang/test/CIR/CodeGen/std-array.cpp (+13) - (added) clang/test/CIR/CodeGen/stmt-expr.c (+42) - (added) clang/test/CIR/CodeGen/store.c (+29) - (added) clang/test/CIR/CodeGen/switch-unreachable-after-break.cpp (+49) - (added) clang/test/CIR/CodeGen/trap.cpp (+28) - (added) clang/test/CIR/CodeGen/types-IEEE-quad.c (+32) - (added) clang/test/CIR/CodeGen/types-nullptr.cpp (+9) - (added) clang/test/CIR/CodeGen/types.c (+46) - (added) clang/test/CIR/CodeGen/unary.c (+44) - (added) clang/test/CIR/CodeGen/unreachable.cpp (+28) - (added) clang/test/CIR/Lowering/bitfieils.c (+32) - (added) clang/test/CIR/Lowering/global-ptr.c (+55) - (added) clang/test/CIR/Lowering/nested-switch.cpp (+69) - (added) clang/test/CIR/Lowering/str.c (+9) - (added) clang/test/CIR/Lowering/switch-while.c (+84) - (added) clang/test/CIR/hello.c (+5) - (added) clang/test/CIR/test.c (+1) ``````````diff 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 aar... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/157333 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits