1 // Test fir.field_index llvm code generation
2 // RUN: fir-opt %s | tco | FileCheck %s
5 // CHECK-DAG: %[[a:.*]] = type { float, i32 }
6 // CHECK-DAG: %[[b:.*]] = type { float, i32 }
7 // CHECK-DAG: %[[c:.*]] = type { float, %[[b]] }
9 // CHECK-LABEL: @simple_field
10 // CHECK-SAME: (ptr nocapture %[[arg0:.*]])
11 func.func @simple_field(%arg0: !fir.ref<!fir.type<a{x:f32,i:i32}>>) -> i32 {
12 %1 = fir.field_index i, !fir.type<a{x:f32,i:i32}>
13 // CHECK: %[[GEP:.*]] = getelementptr %a, ptr %[[arg0]], i32 0, i32 1
14 %2 = fir.coordinate_of %arg0, %1 : (!fir.ref<!fir.type<a{x:f32,i:i32}>>, !fir.field) -> !fir.ref<i32>
15 // CHECK: load i32, ptr %[[GEP]]
16 %3 = fir.load %2 : !fir.ref<i32>
20 // CHECK-LABEL: @derived_field
21 // CHECK-SAME: (ptr nocapture %[[arg0:.*]])
22 func.func @derived_field(%arg0: !fir.ref<!fir.type<c{x:f32,some_b:!fir.type<b{x:f32,i:i32}>}>>) -> i32 {
23 %1 = fir.field_index some_b, !fir.type<c{x:f32,some_b:!fir.type<b{x:f32,i:i32}>}>
24 %2 = fir.field_index i, !fir.type<b{x:f32,i:i32}>
25 // CHECK: %[[GEP:.*]] = getelementptr %c, ptr %[[arg0]], i32 0, i32 1, i32 1
26 %3 = fir.coordinate_of %arg0, %1, %2 : (!fir.ref<!fir.type<c{x:f32,some_b:!fir.type<b{x:f32,i:i32}>}>>, !fir.field, !fir.field) -> !fir.ref<i32>
27 // CHECK: load i32, ptr %[[GEP]]
28 %4 = fir.load %3 : !fir.ref<i32>