108 lines · plain
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 %s4 5 6// Test `fir.shape` conversion failure because the op has uses.7 8func.func @shape_not_dead(%arg0: !fir.ref<!fir.array<?x?xf32>>, %i: index, %j: index) {9 %c0 = arith.constant 1 : index10 // 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 return14}15 16// -----17 18// Test `fir.slice` conversion failure because the op has uses.19 20func.func @slice_not_dead(%arg0: !fir.ref<!fir.array<?x?xf32>>, %i: index, %j: index) {21 %c0 = arith.constant 1 : index22 // 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 return26}27 28// -----29 30// Test `fir.shift` conversion failure because the op has uses.31 32func.func @shift_not_dead(%arg0: !fir.box<!fir.array<?xf32>>, %i: index) {33 %c0 = arith.constant 1 : index34 // 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 return38}39 40// -----41 42// Test `fir.shape_shift` conversion failure because the op has uses.43 44func.func @shape_shift_not_dead(%arg0: !fir.ref<!fir.array<?x?xf32>>, %i: index, %j: index) {45 %c0 = arith.constant 1 : index46 // 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 return50}51 52// -----53 54// Test `fir.select_type` conversion to llvm.55// Should have been converted.56 57func.func @bar_select_type(%arg : !fir.class<!fir.type<derivedst{a:f32}>>) -> i32 {58 %0 = arith.constant 1 : i3259 %2 = arith.constant 3 : i3260 // 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 : i3268^bb2(%b : i32) :69 return %b : i3270^bb5 :71 %zero = arith.constant 0 : i3272 return %zero : i3273}74 75// -----76 77// Verify that `fir.dt_entry` requires a parent op78 79// expected-error@+1{{'fir.dt_entry' op expects parent op 'fir.type_info'}}80fir.dt_entry "method", @method_impl81 82// -----83 84// expected-error@+1{{'fir.type_info' op type must be a fir.type}}85fir.type_info @bad : i3286 87// -----88 89// expected-error@+1{{'fir.type_info' op parent_type must be a fir.type}}90fir.type_info @bad extends f32 : !fir.type<t1{i:i32}>91 92// -----93 94fir.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 : i3297}98 99// -----100 101// `fir.coordinate_of` - dynamically sized arrays are not supported102func.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 return107}108