|
| 1 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir |
| 2 | +// RUN: FileCheck --input-file=%t.cir %s |
| 3 | + |
| 4 | +// Test CK_AtomicToNonAtomic and CK_NonAtomicToAtomic casts |
| 5 | +// Note: Full atomic load/store support is NYI - this tests just the casts |
| 6 | + |
| 7 | +// Test NonAtomicToAtomic cast (assigning non-atomic to atomic) |
| 8 | +void test_non_atomic_to_atomic() { |
| 9 | + int x = 50; |
| 10 | + _Atomic int y = x; // Implicit NonAtomicToAtomic cast |
| 11 | + // CHECK: cir.func{{.*}}test_non_atomic_to_atomicv |
| 12 | + // CHECK: cir.alloca !s32i, !cir.ptr<!s32i>, ["x" |
| 13 | + // CHECK: cir.alloca !s32i, !cir.ptr<!s32i>, ["y" |
| 14 | + // CHECK: cir.load |
| 15 | + // CHECK: cir.store |
| 16 | +} |
| 17 | + |
| 18 | +// Test that atomic type casts don't crash the compiler |
| 19 | +void test_atomic_cast_exists() { |
| 20 | + int regular = 42; |
| 21 | + _Atomic int atomic_val = regular; |
| 22 | + // Just verify this compiles - the cast infrastructure exists |
| 23 | + // CHECK: cir.func{{.*}}test_atomic_cast_existsv |
| 24 | + // CHECK: cir.alloca !s32i, !cir.ptr<!s32i>, ["regular" |
| 25 | + // CHECK: cir.alloca !s32i, !cir.ptr<!s32i>, ["atomic_val" |
| 26 | +} |
| 27 | + |
| 28 | +// Test with different types |
| 29 | +void test_atomic_float_cast() { |
| 30 | + float f = 3.14f; |
| 31 | + _Atomic float g = f; |
| 32 | + // CHECK: cir.func{{.*}}test_atomic_float_castv |
| 33 | + // CHECK: cir.alloca !cir.float |
| 34 | + // CHECK: cir.alloca !cir.float |
| 35 | +} |
| 36 | + |
| 37 | +// Test that cast infrastructure is in place for pointers |
| 38 | +void test_atomic_pointer_cast() { |
| 39 | + int val = 42; |
| 40 | + int* ptr = &val; |
| 41 | + _Atomic(int*) atomic_ptr = ptr; |
| 42 | + // CHECK: cir.func{{.*}}test_atomic_pointer_castv |
| 43 | + // CHECK: cir.alloca !cir.ptr<!s32i> |
| 44 | + // CHECK: cir.alloca !cir.ptr<!s32i> |
| 45 | +} |
0 commit comments