| 1 |
// Test FIR to LLVM IR conversion invalid cases and diagnostics. |
| 2 |
|
| 3 |
// RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" --verify-diagnostics %s |
| 4 |
|
| 5 |
|
| 6 |
// Test `fir.shape` conversion failure because the op has uses. |
| 7 |
|
| 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> |
| 13 |
return |
| 14 |
} |
| 15 |
|
| 16 |
// ----- |
| 17 |
|
| 18 |
// Test `fir.slice` conversion failure because the op has uses. |
| 19 |
|
| 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> |
| 25 |
return |
| 26 |
} |
| 27 |
|
| 28 |
// ----- |
| 29 |
|
| 30 |
// Test `fir.shift` conversion failure because the op has uses. |
| 31 |
|
| 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> |
| 37 |
return |
| 38 |
} |
| 39 |
|
| 40 |
// ----- |
| 41 |
|
| 42 |
// Test `fir.shape_shift` conversion failure because the op has uses. |
| 43 |
|
| 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> |
| 49 |
return |
| 50 |
} |
| 51 |
|
| 52 |
// ----- |
| 53 |
|
| 54 |
// Test `fir.select_type` conversion to llvm. |
| 55 |
// Should have been converted. |
| 56 |
|
| 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), |
| 65 |
unit,^bb5 ] |
| 66 |
^bb1(%a : i32) : |
| 67 |
return %a : i32 |
| 68 |
^bb2(%b : i32) : |
| 69 |
return %b : i32 |
| 70 |
^bb5 : |
| 71 |
%zero = arith.constant 0 : i32 |
| 72 |
return %zero : i32 |
| 73 |
} |
| 74 |
|
| 75 |
// ----- |
| 76 |
|
| 77 |
// Verify that `fir.dt_entry` requires a parent op |
| 78 |
|
| 79 |
// expected-error@+1{{'fir.dt_entry' op expects parent op 'fir.type_info'}} |
| 80 |
fir.dt_entry "method", @method_impl |
| 81 |
|
| 82 |
// ----- |
| 83 |
|
| 84 |
// expected-error@+1{{'fir.type_info' op type must be a fir.type}} |
| 85 |
fir.type_info @bad : i32 |
| 86 |
|
| 87 |
// ----- |
| 88 |
|
| 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}> |
| 91 |
|
| 92 |
// ----- |
| 93 |
|
| 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 |
| 97 |
} |
| 98 |
|
| 99 |
// ----- |
| 100 |
|
| 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> |
| 106 |
return |
| 107 |
} |