1 // Test FIR to LLVM IR conversion invalid cases and diagnostics.
3 // RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" --verify-diagnostics %s
6 // Test `fir.shape` conversion failure because the op has uses.
8 func.func @shape_not_dead(%arg0: !fir.ref<!fir.array<?x?xf32>>, %i: index, %j: index) {
9 %c0 = arith.constant 1 : index
10 // expected-error@+1{{failed to legalize operation 'fir.shape'}}
11 %0 = fir.shape %c0, %c0 : (index, index) -> !fir.shape<2>
12 %1 = fir.array_coor %arg0(%0) %i, %j : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>, index, index) -> !fir.ref<f32>
18 // Test `fir.slice` conversion failure because the op has uses.
20 func.func @slice_not_dead(%arg0: !fir.ref<!fir.array<?x?xf32>>, %i: index, %j: index) {
21 %c0 = arith.constant 1 : index
22 // expected-error@+1{{failed to legalize operation 'fir.slice'}}
23 %0 = fir.slice %c0, %c0, %c0, %c0, %c0, %c0 : (index, index, index, index, index, index) -> !fir.slice<2>
24 %1 = fir.array_coor %arg0[%0] %i, %j : (!fir.ref<!fir.array<?x?xf32>>, !fir.slice<2>, index, index) -> !fir.ref<f32>
30 // Test `fir.shift` conversion failure because the op has uses.
32 func.func @shift_not_dead(%arg0: !fir.box<!fir.array<?xf32>>, %i: index) {
33 %c0 = arith.constant 1 : index
34 // expected-error@+1{{failed to legalize operation 'fir.shift'}}
35 %0 = fir.shift %c0 : (index) -> !fir.shift<1>
36 %1 = fir.array_coor %arg0(%0) %i : (!fir.box<!fir.array<?xf32>>, !fir.shift<1>, index) -> !fir.ref<f32>
42 // Test `fir.shape_shift` conversion failure because the op has uses.
44 func.func @shape_shift_not_dead(%arg0: !fir.ref<!fir.array<?x?xf32>>, %i: index, %j: index) {
45 %c0 = arith.constant 1 : index
46 // expected-error@+1{{failed to legalize operation 'fir.shape_shift'}}
47 %0 = fir.shape_shift %c0, %c0, %c0, %c0 : (index, index, index, index) -> !fir.shapeshift<2>
48 %1 = fir.array_coor %arg0(%0) %i, %j : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>, index, index) -> !fir.ref<f32>
54 // Test `fir.select_type` conversion to llvm.
55 // Should have been converted.
57 func.func @bar_select_type(%arg : !fir.class<!fir.type<derivedst{a:f32}>>) -> i32 {
58 %0 = arith.constant 1 : i32
59 %2 = arith.constant 3 : i32
60 // expected-error@+2{{fir.select_type should have already been converted}}
61 // expected-error@+1{{failed to legalize operation 'fir.select_type'}}
62 fir.select_type %arg : !fir.class<!fir.type<derivedst{a:f32}>> [
63 #fir.type_is<!fir.int<4>>,^bb1(%0:i32),
64 #fir.type_is<!fir.int<8>>,^bb2(%2:i32),
71 %zero = arith.constant 0 : i32
77 // Verify that `fir.dt_entry` requires a parent op
79 // expected-error@+1{{'fir.dt_entry' op expects parent op 'fir.type_info'}}
80 fir.dt_entry "method", @method_impl
84 // expected-error@+1{{'fir.type_info' op type must be a fir.type}}
85 fir.type_info @bad : i32
89 // expected-error@+1{{'fir.type_info' op parent_type must be a fir.type}}
90 fir.type_info @bad extends f32 : !fir.type<t1{i:i32}>
94 fir.type_info @bad : !fir.type<bad{i:i32}> dispatch_table {
95 // expected-error@+1{{dispatch table must contain dt_entry}}
96 %zero = arith.constant 0 : i32
101 // `fir.coordinate_of` - dynamically sized arrays are not supported
102 func.func @coordinate_of_dynamic_array(%arg0: !fir.ref<!fir.array<1x!fir.char<4,?>>>, %arg1: index) {
103 // expected-error@+2{{fir.coordinate_of with a dynamic element size is unsupported}}
104 // expected-error@+1{{failed to legalize operation 'fir.coordinate_of'}}
105 %p = fir.coordinate_of %arg0, %arg1 : (!fir.ref<!fir.array<1x!fir.char<4,?>>>, index) -> !fir.ref<f32>