diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index dd621a279efd..cadf1a36ffaa 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -1710,7 +1710,6 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *CE) { CGF, Visit(E), SrcAS, DestAS, convertType(DestTy)); } case CK_AtomicToNonAtomic: - llvm_unreachable("NYI"); case CK_NonAtomicToAtomic: case CK_UserDefinedConversion: return Visit(const_cast(E)); diff --git a/clang/test/CIR/CodeGen/atomic-type-casts.cpp b/clang/test/CIR/CodeGen/atomic-type-casts.cpp new file mode 100644 index 000000000000..fa890879d922 --- /dev/null +++ b/clang/test/CIR/CodeGen/atomic-type-casts.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +// Test CK_AtomicToNonAtomic and CK_NonAtomicToAtomic casts +// Note: Full atomic load/store support is NYI - this tests just the casts + +// Test NonAtomicToAtomic cast (assigning non-atomic to atomic) +void test_non_atomic_to_atomic() { + int x = 50; + _Atomic int y = x; // Implicit NonAtomicToAtomic cast + // CHECK: cir.func{{.*}}test_non_atomic_to_atomicv + // CHECK: cir.alloca !s32i, !cir.ptr, ["x" + // CHECK: cir.alloca !s32i, !cir.ptr, ["y" + // CHECK: cir.load + // CHECK: cir.store +} + +// Test that atomic type casts don't crash the compiler +void test_atomic_cast_exists() { + int regular = 42; + _Atomic int atomic_val = regular; + // Just verify this compiles - the cast infrastructure exists + // CHECK: cir.func{{.*}}test_atomic_cast_existsv + // CHECK: cir.alloca !s32i, !cir.ptr, ["regular" + // CHECK: cir.alloca !s32i, !cir.ptr, ["atomic_val" +} + +// Test with different types +void test_atomic_float_cast() { + float f = 3.14f; + _Atomic float g = f; + // CHECK: cir.func{{.*}}test_atomic_float_castv + // CHECK: cir.alloca !cir.float + // CHECK: cir.alloca !cir.float +} + +// Test that cast infrastructure is in place for pointers +void test_atomic_pointer_cast() { + int val = 42; + int* ptr = &val; + _Atomic(int*) atomic_ptr = ptr; + // CHECK: cir.func{{.*}}test_atomic_pointer_castv + // CHECK: cir.alloca !cir.ptr + // CHECK: cir.alloca !cir.ptr +}