Skip to content

Commit 6c40c76

Browse files
authored
[flang][debug] Avoid redundant module info. (#161542)
Fixes llvm/llvm-project#160907. When a module is just being used and not defined, we generate it with decl=true. But if the file/line fields are valid, the module is not merged with the original and is considered different. This patch avoids setting file/line/scope in such cases.
1 parent cc9c64d commit 6c40c76

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

flang/lib/Optimizer/Transforms/AddDebugInfo.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,16 @@ mlir::LLVM::DIModuleAttr AddDebugInfoPass::getOrCreateModuleAttr(
285285
if (auto iter{moduleMap.find(name)}; iter != moduleMap.end()) {
286286
modAttr = iter->getValue();
287287
} else {
288+
// When decl is true, it means that module is only being used in this
289+
// compilation unit and it is defined elsewhere. But if the file/line/scope
290+
// fields are valid, the module is not merged with its definition and is
291+
// considered different. So we only set those fields when decl is false.
288292
modAttr = mlir::LLVM::DIModuleAttr::get(
289-
context, fileAttr, scope, mlir::StringAttr::get(context, name),
293+
context, decl ? nullptr : fileAttr, decl ? nullptr : scope,
294+
mlir::StringAttr::get(context, name),
290295
/* configMacros */ mlir::StringAttr(),
291296
/* includePath */ mlir::StringAttr(),
292-
/* apinotes */ mlir::StringAttr(), line, decl);
297+
/* apinotes */ mlir::StringAttr(), decl ? 0 : line, decl);
293298
moduleMap[name] = modAttr;
294299
}
295300
return modAttr;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
2+
3+
module {
4+
func.func @_QQmain() {
5+
%2 = fir.address_of(@_QMmodEvar1) : !fir.ref<i32> loc(#loc1)
6+
%3 = fircg.ext_declare %2 {uniq_name = "_QMmodEvar1"} : (!fir.ref<i32>) -> !fir.ref<i32> loc(#loc1)
7+
return
8+
} loc(#loc1)
9+
fir.global @_QMmodEvar1 : i32 loc(#loc1)
10+
}
11+
#loc1 = loc("test1.f90":1:0)
12+
13+
// CHECK: #llvm.di_module<name = "mod", isDecl = true>

0 commit comments

Comments
 (0)