Skip to content

Commit 91d6e77

Browse files
authored
[flang][debug] set DW_AT_main_subprogram for fortran main function (#111350)
Requested here #111022 (comment)
1 parent e7174a8 commit 91d6e77

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

flang/lib/Optimizer/Transforms/AddDebugInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ void AddDebugInfoPass::handleFuncOp(mlir::func::FuncOp funcOp,
267267
funcName = mlir::StringAttr::get(context, result.second.name);
268268

269269
// try to use a better function name than _QQmain for the program statement
270+
bool isMain = false;
270271
if (funcName == fir::NameUniquer::doProgramEntry()) {
272+
isMain = true;
271273
mlir::StringAttr bindcName =
272274
funcOp->getAttrOfType<mlir::StringAttr>(fir::getSymbolAttrName());
273275
if (bindcName)
@@ -302,6 +304,9 @@ void AddDebugInfoPass::handleFuncOp(mlir::func::FuncOp funcOp,
302304
mlir::LLVM::DISubprogramFlags{};
303305
if (isOptimized)
304306
subprogramFlags = mlir::LLVM::DISubprogramFlags::Optimized;
307+
if (isMain)
308+
subprogramFlags =
309+
subprogramFlags | mlir::LLVM::DISubprogramFlags::MainSubprogram;
305310
if (!funcOp.isExternal()) {
306311
// Place holder and final function have to have different IDs, otherwise
307312
// translation code will reject one of them.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
7676
// CHECK: #[[TY3:.*]] = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #di_null_type, #[[INT4]]>
7777

7878
// Line numbers should match the number in corresponding loc entry.
79-
// CHECK: #llvm.di_subprogram<{{.*}}name = "mn", linkageName = "_QQmain", file = {{.*}}, line = 15, scopeLine = 15, subprogramFlags = Definition, type = #[[TY0]]>
79+
// CHECK: #llvm.di_subprogram<{{.*}}name = "mn", linkageName = "_QQmain", file = {{.*}}, line = 15, scopeLine = 15, subprogramFlags = "Definition|MainSubprogram", type = #[[TY0]]>
8080
// CHECK: #llvm.di_subprogram<{{.*}}name = "fn1", linkageName = "_QFPfn1", file = {{.*}}, line = 26, scopeLine = 26, subprogramFlags = Definition, type = #[[TY1]]>
8181
// CHECK: #llvm.di_subprogram<{{.*}}name = "fn2", linkageName = "_QFPfn2", file = {{.*}}, line = 43, scopeLine = 43, subprogramFlags = Definition, type = #[[TY2]]>
8282
// CHECK: #llvm.di_subprogram<{{.*}}name = "fn3", linkageName = "_QFPfn3", file = {{.*}}, line = 53, scopeLine = 53, subprogramFlags = Definition, type = #[[TY3]]>

0 commit comments

Comments
 (0)