Skip to content

Commit b6f72fc

Browse files
authored
[flang][debug] Generate correct subroutine type. (#108605)
We pass a list of types when creating a subroutine type. The first one is supposed to be return type and the rest are the argument types. A subroutine does not have a return type so an argument type could be confused as a return type. To fix this, if there is no return type, we generate a null type as a place holder. Fixes #108564.
1 parent b1d7694 commit b6f72fc

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

flang/lib/Optimizer/Transforms/AddDebugInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ void AddDebugInfoPass::handleFuncOp(mlir::func::FuncOp funcOp,
271271
typeGen.convertType(resTy, fileAttr, cuAttr, /*declOp=*/nullptr);
272272
types.push_back(tyAttr);
273273
}
274+
// If no return type then add a null type as a place holder for that.
275+
if (types.empty())
276+
types.push_back(mlir::LLVM::DINullTypeAttr::get(context));
274277
for (auto inTy : funcOp.getArgumentTypes()) {
275278
auto tyAttr = typeGen.convertType(fir::unwrapRefType(inTy), fileAttr,
276279
cuAttr, /*declOp=*/nullptr);

flang/test/Transforms/debug-fn-info.fir

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
5252
%11 = fir.load %5 : !fir.ref<i32>
5353
return %11 : i32
5454
} loc(#loc3)
55+
func.func private @_QFPfn3(%arg0: !fir.ref<i32> {fir.bindc_name = "abc"}) attributes {fir.host_symbol = @_QQmain, llvm.linkage = #llvm.linkage<internal>} {
56+
%0 = fir.undefined !fir.dscope
57+
%1 = fircg.ext_declare %arg0 dummy_scope %0 {uniq_name = "_QFFfn3Eabc"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
58+
return
59+
} loc(#loc4)
5560
}
5661
#loc1 = loc("test.f90":15:1)
5762
#loc2 = loc("test.f90":26:22)
5863
#loc3 = loc("test2.f90":43:22)
64+
#loc4 = loc("test2.f90":53:22)
5965

6066

6167
// CHECK-DAG: #[[INT8:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer", sizeInBits = 64, encoding = DW_ATE_signed>
@@ -64,12 +70,14 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
6470
// CHECK-DAG: #[[LOG1:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "logical", sizeInBits = 8, encoding = DW_ATE_boolean>
6571
// CHECK-DAG: #[[REAL4:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "real", sizeInBits = 32, encoding = DW_ATE_float>
6672
// CHECK-DAG: #[[LOG4:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "logical", sizeInBits = 32, encoding = DW_ATE_boolean>
67-
// CHECK: #[[TY0:.*]] = #llvm.di_subroutine_type<callingConvention = DW_CC_program>
73+
// CHECK: #[[TY0:.*]] = #llvm.di_subroutine_type<callingConvention = DW_CC_program, types = #di_null_type>
6874
// CHECK: #[[TY1:.*]] = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #[[INT8]], #[[INT4]], #[[REAL8]], #[[LOG1]]>
6975
// CHECK: #[[TY2:.*]] = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #[[INT4]], #[[INT8]], #[[REAL4]], #[[LOG4]]>
76+
// CHECK: #[[TY3:.*]] = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #di_null_type, #[[INT4]]>
7077

7178
// Line numbers should match the number in corresponding loc entry.
7279
// CHECK: #llvm.di_subprogram<{{.*}}name = "_QQmain", linkageName = "_QQmain", file = {{.*}}, line = 15, scopeLine = 15, subprogramFlags = Definition, type = #[[TY0]]>
7380
// CHECK: #llvm.di_subprogram<{{.*}}name = "fn1", linkageName = "_QFPfn1", file = {{.*}}, line = 26, scopeLine = 26, subprogramFlags = Definition, type = #[[TY1]]>
7481
// CHECK: #llvm.di_subprogram<{{.*}}name = "fn2", linkageName = "_QFPfn2", file = {{.*}}, line = 43, scopeLine = 43, subprogramFlags = Definition, type = #[[TY2]]>
82+
// CHECK: #llvm.di_subprogram<{{.*}}name = "fn3", linkageName = "_QFPfn3", file = {{.*}}, line = 53, scopeLine = 53, subprogramFlags = Definition, type = #[[TY3]]>
7583

0 commit comments

Comments
 (0)