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
5 // Test `fir.zero` conversion failure with aggregate type.
6 // Not implemented yet.
8 func.func @zero_aggregate() {
9 // expected-error@+1{{failed to legalize operation 'fir.zero_bits'}}
10 %a = fir.zero_bits !fir.array<10xf32>
16 // Verify that `fir.dt_entry` requires a parent op
18 // expected-error@+1{{'fir.dt_entry' op expects parent op 'fir.dispatch_table'}}
19 fir.dt_entry "method", @method_impl
23 // Test `fir.shape` conversion failure because the op has uses.
25 func.func @shape_not_dead(%arg0: !fir.ref<!fir.array<?x?xf32>>, %i: index, %j: index) {
26 %c0 = arith.constant 1 : index
27 // expected-error@+1{{failed to legalize operation 'fir.shape'}}
28 %0 = fir.shape %c0, %c0 : (index, index) -> !fir.shape<2>
29 %1 = fir.array_coor %arg0(%0) %i, %j : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>, index, index) -> !fir.ref<f32>
35 // Test `fir.slice` conversion failure because the op has uses.
37 func.func @slice_not_dead(%arg0: !fir.ref<!fir.array<?x?xf32>>, %i: index, %j: index) {
38 %c0 = arith.constant 1 : index
39 // expected-error@+1{{failed to legalize operation 'fir.slice'}}
40 %0 = fir.slice %c0, %c0, %c0, %c0, %c0, %c0 : (index, index, index, index, index, index) -> !fir.slice<2>
41 %1 = fir.array_coor %arg0[%0] %i, %j : (!fir.ref<!fir.array<?x?xf32>>, !fir.slice<2>, index, index) -> !fir.ref<f32>
47 // Test `fir.shift` conversion failure because the op has uses.
49 func.func @shift_not_dead(%arg0: !fir.box<!fir.array<?xf32>>, %i: index) {
50 %c0 = arith.constant 1 : index
51 // expected-error@+1{{failed to legalize operation 'fir.shift'}}
52 %0 = fir.shift %c0 : (index) -> !fir.shift<1>
53 %1 = fir.array_coor %arg0(%0) %i : (!fir.box<!fir.array<?xf32>>, !fir.shift<1>, index) -> !fir.ref<f32>
59 // Test `fir.shape_shift` conversion failure because the op has uses.
61 func.func @shape_shift_not_dead(%arg0: !fir.ref<!fir.array<?x?xf32>>, %i: index, %j: index) {
62 %c0 = arith.constant 1 : index
63 // expected-error@+1{{failed to legalize operation 'fir.shape_shift'}}
64 %0 = fir.shape_shift %c0, %c0, %c0, %c0 : (index, index, index, index) -> !fir.shapeshift<2>
65 %1 = fir.array_coor %arg0(%0) %i, %j : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>, index, index) -> !fir.ref<f32>
71 // Test `fir.select_type` conversion to llvm.
72 // Should have been converted.
74 func.func @bar_select_type(%arg : !fir.class<!fir.type<derivedst{a:f32}>>) -> i32 {
75 %0 = arith.constant 1 : i32
76 %2 = arith.constant 3 : i32
77 // expected-error@+2{{fir.select_type should have already been converted}}
78 // expected-error@+1{{failed to legalize operation 'fir.select_type'}}
79 fir.select_type %arg : !fir.class<!fir.type<derivedst{a:f32}>> [
80 #fir.type_is<!fir.int<4>>,^bb1(%0:i32),
81 #fir.type_is<!fir.int<8>>,^bb2(%2:i32),
88 %zero = arith.constant 0 : i32
94 // Verify that `fir.dt_entry` requires a parent op
96 // expected-error@+1{{'fir.dt_entry' op expects parent op 'fir.dispatch_table'}}
97 fir.dt_entry "method", @method_impl
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>