[flang-commits] [flang] Revert "[flang][debug] Emit debug info for named constants" (PR #214813)
via flang-commits
flang-commits at lists.llvm.org
Fri Aug 7 11:56:52 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Eugene Epshteyn (eugeneepshteyn)
<details>
<summary>Changes</summary>
Reverts llvm/llvm-project#<!-- -->213974 due to issue https://github.com/llvm/llvm-project/issues/214777
---
Full diff: https://github.com/llvm/llvm-project/pull/214813.diff
6 Files Affected:
- (modified) flang/lib/Optimizer/Transforms/AddDebugInfo.cpp (+11-45)
- (removed) flang/test/Integration/debug-local-storage.f90 (-20)
- (removed) flang/test/Integration/debug-module-constant.f90 (-42)
- (removed) flang/test/Transforms/debug-local-constant.fir (-41)
- (modified) flang/test/Transforms/debug-local-global-storage-1.fir (+4-7)
- (removed) flang/test/Transforms/debug-module-constant.fir (-22)
``````````diff
diff --git a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
index a9a0d74912524..82e9466c0a056 100644
--- a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
+++ b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
@@ -179,22 +179,11 @@ mlir::StringAttr getTargetFunctionName(mlir::MLIRContext *context,
} // namespace
-// Check if a name is that of a data object, which in Fortran is a variable or
-// a named constant.
-static bool isDataObjectName(fir::NameUniquer::NameKind kind) {
- return kind == fir::NameUniquer::NameKind::VARIABLE ||
- kind == fir::NameUniquer::NameKind::CONSTANT;
-}
-
-// Check if a name belongs to a module rather than to a procedure.
-static bool isModuleLevelName(const fir::NameUniquer::DeconstructedName &name) {
- return name.procs.empty() && !name.modules.empty();
-}
-
-// Check if a global represents a data object declared in a module.
-static bool isModuleDataObject(fir::GlobalOp globalOp) {
+// Check if a global represents a module variable
+static bool isModuleVariable(fir::GlobalOp globalOp) {
std::pair result = fir::NameUniquer::deconstruct(globalOp.getSymName());
- return isDataObjectName(result.first) && isModuleLevelName(result.second);
+ return result.first == fir::NameUniquer::NameKind::VARIABLE &&
+ result.second.procs.empty() && !result.second.modules.empty();
}
// Look up DIGlobalVariable from a global symbol
@@ -388,7 +377,7 @@ void AddDebugInfoPass::handleDeclareOp(fir::cg::XDeclareOp declOp,
mlir::Value dummyScope) {
auto result = fir::NameUniquer::deconstruct(declOp.getUniqName());
- if (!isDataObjectName(result.first))
+ if (result.first != fir::NameUniquer::NameKind::VARIABLE)
return;
if (createCommonBlockGlobal(declOp, result.second.name, fileAttr, scopeAttr,
@@ -521,23 +510,8 @@ void AddDebugInfoPass::handleGlobalOp(fir::GlobalOp globalOp,
mlir::OpBuilder builder(context);
std::pair result = fir::NameUniquer::deconstruct(globalOp.getSymName());
- switch (result.first) {
- case fir::NameUniquer::NameKind::VARIABLE:
- break;
- case fir::NameUniquer::NameKind::CONSTANT:
- // A constant local to a procedure is described while walking that
- // procedure, where `scope` is its DISubprogramAttr. Reaching here with any
- // other scope means the procedure is not in the IR, typically because it
- // was never called and got removed while its constant survived. There is
- // no procedure to attach the constant to, and describing it at compile
- // unit scope would wrongly make it visible everywhere.
- if (!isModuleLevelName(result.second) &&
- !mlir::isa<mlir::LLVM::DISubprogramAttr>(scope))
- return;
- break;
- default:
+ if (result.first != fir::NameUniquer::NameKind::VARIABLE)
return;
- }
if (fir::NameUniquer::isSpecialSymbol(result.second.name))
return;
@@ -548,20 +522,12 @@ void AddDebugInfoPass::handleGlobalOp(fir::GlobalOp globalOp,
if (modOpt)
scope = *modOpt;
- // An entity with internal linkage, such as a constant or a SAVE variable
- // declared inside a procedure, is not visible outside this compilation unit.
- // It also needs no linkage name because there is no external symbol for a
- // debugger to match it against.
- const bool isLocalToUnit = globalOp.getLinkName() == "internal";
- mlir::StringAttr linkageName =
- isLocalToUnit ? mlir::StringAttr()
- : mlir::StringAttr::get(context, globalOp.getName());
-
mlir::LLVM::DITypeAttr diType =
typeGen.convertType(globalOp.getType(), fileAttr, scope, declOp);
auto gvAttr = mlir::LLVM::DIGlobalVariableAttr::get(
context, scope, mlir::StringAttr::get(context, result.second.name),
- linkageName, fileAttr, line, diType, isLocalToUnit,
+ mlir::StringAttr::get(context, globalOp.getName()), fileAttr, line,
+ diType, /*isLocalToUnit*/ false,
/*isDefinition*/ globalOp.isInitialized(), /* alignInBits*/ 0);
auto dbgExpr = mlir::LLVM::DIGlobalVariableExpressionAttr::get(
globalOp.getContext(), gvAttr, nullptr);
@@ -1075,7 +1041,7 @@ void AddDebugInfoPass::runOnOperation() {
// Process module globals early.
// Walk through all DeclareOps in functions and process globals that are
- // module data objects. This ensures that when we process USE statements,
+ // module variables. This ensures that when we process USE statements,
// the DIGlobalVariable lookups will succeed.
if (debugLevel == mlir::LLVM::DIEmissionKind::Full) {
module.walk([&](fir::cg::XDeclareOp declOp) {
@@ -1083,8 +1049,8 @@ void AddDebugInfoPass::runOnOperation() {
if (defOp && llvm::isa<fir::AddrOfOp>(defOp)) {
if (auto globalOp =
symbolTable.lookup<fir::GlobalOp>(declOp.getUniqName())) {
- // Only process module data objects here, not SAVE variables
- if (isModuleDataObject(globalOp)) {
+ // Only process module variables here, not SAVE variables
+ if (isModuleVariable(globalOp)) {
handleGlobalOp(globalOp, fileAttr, cuAttr, typeGen, &symbolTable,
declOp);
}
diff --git a/flang/test/Integration/debug-local-storage.f90 b/flang/test/Integration/debug-local-storage.f90
deleted file mode 100644
index 71fe2d212f80d..0000000000000
--- a/flang/test/Integration/debug-local-storage.f90
+++ /dev/null
@@ -1,20 +0,0 @@
-! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s
-
-! A named constant and a SAVE variable declared inside a procedure both have
-! internal linkage. They are described in the scope of that procedure, are
-! local to the compile unit and carry no linkage name. The `name` field being
-! followed directly by `scope` is what checks that no linkage name is emitted.
-
-! CHECK-DAG: ![[I4:.*]] = !DIBasicType(name: "integer(kind=4)", size: 32, encoding: DW_ATE_signed)
-! CHECK-DAG: ![[SUB:.*]] = distinct !DISubprogram(name: "counter_fn"{{.*}})
-
-integer function counter_fn()
-! CHECK-DAG: ![[Q:.*]] = distinct !DIGlobalVariable(name: "q", scope: ![[SUB]], file: !{{[0-9]+}}, line: [[@LINE+2]], type: ![[I4]], isLocal: true, isDefinition: true)
-! CHECK-DAG: !DIGlobalVariableExpression(var: ![[Q]], expr: !DIExpression())
- integer, parameter :: q = 7
-! CHECK-DAG: ![[COUNT:.*]] = distinct !DIGlobalVariable(name: "counter", scope: ![[SUB]], file: !{{[0-9]+}}, line: [[@LINE+2]], type: ![[I4]], isLocal: true, isDefinition: true)
-! CHECK-DAG: !DIGlobalVariableExpression(var: ![[COUNT]], expr: !DIExpression())
- integer, save :: counter = 0
- counter = counter + 1
- counter_fn = q + counter
-end function counter_fn
diff --git a/flang/test/Integration/debug-module-constant.f90 b/flang/test/Integration/debug-module-constant.f90
deleted file mode 100644
index 5e48029adc6c8..0000000000000
--- a/flang/test/Integration/debug-module-constant.f90
+++ /dev/null
@@ -1,42 +0,0 @@
-! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s
-! RUN: %flang_fc1 -emit-llvm -debug-info-kind=line-tables-only %s -o - | FileCheck --check-prefix=LINEONLY %s
-
-! A named constant declared in a module is described like a module variable: in
-! the scope of the module, with a linkage name, and visible outside this compile
-! unit.
-
-! CHECK-DAG: ![[FILE:.*]] = !DIFile(filename: {{.*}}debug-module-constant.f90{{.*}})
-! CHECK-DAG: ![[CU:.*]] = distinct !DICompileUnit({{.*}}file: ![[FILE]]{{.*}})
-! CHECK-DAG: ![[MOD:.*]] = !DIModule(scope: ![[CU]], name: "helper"{{.*}})
-! CHECK-DAG: ![[I4:.*]] = !DIBasicType(name: "integer(kind=4)", size: 32, encoding: DW_ATE_signed)
-! CHECK-DAG: ![[R4:.*]] = !DIBasicType(name: "real(kind=4)", size: 32, encoding: DW_ATE_float)
-
-module helper
-! CHECK-DAG: ![[MAX:.*]] = distinct !DIGlobalVariable(name: "max_size", linkageName: "_QMhelperECmax_size", scope: ![[MOD]], file: ![[FILE]], line: [[@LINE+2]], type: ![[I4]], isLocal: false, isDefinition: true)
-! CHECK-DAG: !DIGlobalVariableExpression(var: ![[MAX]], expr: !DIExpression())
- integer, parameter :: max_size = 100
-
-! CHECK-DAG: ![[PI:.*]] = distinct !DIGlobalVariable(name: "pi", linkageName: "_QMhelperECpi", scope: ![[MOD]], file: ![[FILE]], line: [[@LINE+2]], type: ![[R4]], isLocal: false, isDefinition: true)
-! CHECK-DAG: !DIGlobalVariableExpression(var: ![[PI]], expr: !DIExpression())
- real, parameter :: pi = 3.14159274
-
-! CHECK-DAG: ![[PRIMES:.*]] = distinct !DIGlobalVariable(name: "primes", linkageName: "_QMhelperECprimes", scope: ![[MOD]], file: ![[FILE]], line: [[@LINE+3]], type: ![[ARR:.*]], isLocal: false, isDefinition: true)
-! CHECK-DAG: ![[ARR]] = !DICompositeType(tag: DW_TAG_array_type, baseType: ![[I4]]{{.*}})
-! CHECK-DAG: !DIGlobalVariableExpression(var: ![[PRIMES]], expr: !DIExpression())
- integer, parameter :: primes(3) = [2, 3, 5]
-
-! CHECK-DAG: ![[TAG:.*]] = distinct !DIGlobalVariable(name: "tag", linkageName: "_QMhelperECtag", scope: ![[MOD]], file: ![[FILE]], line: [[@LINE+3]], type: ![[STR:.*]], isLocal: false, isDefinition: true)
-! CHECK-DAG: ![[STR]] = !DIStringType(size: 40, encoding: DW_ATE_ASCII)
-! CHECK-DAG: !DIGlobalVariableExpression(var: ![[TAG]], expr: !DIExpression())
- character(len=5), parameter :: tag = "hello"
-end module helper
-
-program test
- use helper
- implicit none
- integer :: n
- n = max_size + primes(2)
- print *, pi, tag, n
-end program test
-
-! LINEONLY-NOT: DIGlobalVariable
diff --git a/flang/test/Transforms/debug-local-constant.fir b/flang/test/Transforms/debug-local-constant.fir
deleted file mode 100644
index 7c70637b1f2a4..0000000000000
--- a/flang/test/Transforms/debug-local-constant.fir
+++ /dev/null
@@ -1,41 +0,0 @@
-// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
-
-// Test that a named constant (Fortran PARAMETER) declared inside a procedure is
-// described in the scope of that procedure. Two procedures declaring the same
-// name must produce entries in distinct scopes, otherwise a debugger cannot
-// tell them apart. Such a constant has internal linkage, so it is local to the
-// compile unit and carries no linkage name.
-
-module {
- func.func @_QPone() {
- %0 = fir.address_of(@_QFoneECq) : !fir.ref<i32>
- %1 = fircg.ext_declare %0 {uniq_name = "_QFoneECq"} : (!fir.ref<i32>) -> !fir.ref<i32> loc(#loc2)
- return
- } loc(#loc1)
- func.func @_QPtwo() {
- %0 = fir.address_of(@_QFtwoECq) : !fir.ref<i32>
- %1 = fircg.ext_declare %0 {uniq_name = "_QFtwoECq"} : (!fir.ref<i32>) -> !fir.ref<i32> loc(#loc4)
- return
- } loc(#loc3)
- fir.global internal @_QFoneECq constant : i32 {
- %c111_i32 = arith.constant 111 : i32
- fir.has_value %c111_i32 : i32
- } loc(#loc2)
- fir.global internal @_QFtwoECq constant : i32 {
- %c777_i32 = arith.constant 777 : i32
- fir.has_value %c777_i32 : i32
- } loc(#loc4)
-}
-#loc1 = loc("test.f90":1:1)
-#loc2 = loc("test.f90":3:3)
-#loc3 = loc("test.f90":7:1)
-#loc4 = loc("test.f90":9:3)
-
-// CHECK-DAG: #[[I4:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "integer(kind=4)", sizeInBits = 32, encoding = DW_ATE_signed>
-// CHECK-DAG: #[[ONE:.*]] = #llvm.di_subprogram<{{.*}}name = "one"{{.*}}>
-// CHECK-DAG: #[[TWO:.*]] = #llvm.di_subprogram<{{.*}}name = "two"{{.*}}>
-
-// Each constant is scoped to its own procedure and, having internal linkage,
-// is local to the unit and has no linkage name.
-// CHECK-DAG: #llvm.di_global_variable<scope = #[[ONE]], name = "q", file = {{.*}}, line = 3, type = #[[I4]], isLocalToUnit = true, isDefined = true>
-// CHECK-DAG: #llvm.di_global_variable<scope = #[[TWO]], name = "q", file = {{.*}}, line = 9, type = #[[I4]], isLocalToUnit = true, isDefined = true>
diff --git a/flang/test/Transforms/debug-local-global-storage-1.fir b/flang/test/Transforms/debug-local-global-storage-1.fir
index 4a50626981d6b..6b9ea5b9dbb2d 100644
--- a/flang/test/Transforms/debug-local-global-storage-1.fir
+++ b/flang/test/Transforms/debug-local-global-storage-1.fir
@@ -47,10 +47,7 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<i64, dense<64> :
// CHECK-DAG: #[[MOD:.*]] = #llvm.di_module<{{.*}}scope = #[[CU]]{{.*}}name = "example"{{.*}}>
// CHECK-DAG: #[[SP:.*]] = #llvm.di_subprogram<{{.*}}name = "test"{{.*}}>
// CHECK-DAG: #[[MOD_SP:.*]] = #llvm.di_subprogram<{{.*}}name = "mod_sub"{{.*}}retainedNodes = {{.*}}>
-// A variable with the SAVE attribute inside a procedure has internal linkage,
-// so it is local to the compile unit and has no linkage name. A module
-// variable is visible to other compilation units and keeps its linkage name.
-// CHECK-DAG: #llvm.di_global_variable<scope = #[[SP]], name = "arr", file = {{.*}}, line = 22, type = {{.*}}, isLocalToUnit = true, isDefined = true>
-// CHECK-DAG: #llvm.di_global_variable<scope = #[[SP]], name = "s", file = {{.*}}, line = 23, type = {{.*}}, isLocalToUnit = true, isDefined = true>
-// CHECK-DAG: #llvm.di_global_variable<scope = #[[MOD_SP]], name = "ss", file = {{.*}}, line = 12, type = {{.*}}, isLocalToUnit = true, isDefined = true>
-// CHECK-DAG: #llvm.di_global_variable<scope = #[[MOD]], name = "mod_arr", linkageName = "_QMexampleEmod_arr"{{.*}}line = 5{{.*}}>
+// CHECK-DAG: #llvm.di_global_variable<scope = #[[SP]], name = "arr"{{.*}}line = 22{{.*}}>
+// CHECK-DAG: #llvm.di_global_variable<scope = #[[SP]], name = "s"{{.*}}line = 23{{.*}}>
+// CHECK-DAG: #llvm.di_global_variable<scope = #[[MOD_SP]], name = "ss"{{.*}}line = 12{{.*}}>
+// CHECK-DAG: #llvm.di_global_variable<scope = #[[MOD]], name = "mod_arr"{{.*}}line = 5{{.*}}>
diff --git a/flang/test/Transforms/debug-module-constant.fir b/flang/test/Transforms/debug-module-constant.fir
deleted file mode 100644
index 0202b7cfa1350..0000000000000
--- a/flang/test/Transforms/debug-module-constant.fir
+++ /dev/null
@@ -1,22 +0,0 @@
-// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
-
-// Test that a named constant (Fortran PARAMETER) declared in a module is
-// described in the scope of that module.
-
-module {
- fir.global @_QMhelperECpi constant : f32 {
- %cst = arith.constant 3.14159274 : f32
- fir.has_value %cst : f32
- } loc(#loc1)
- func.func @_QMhelperPtest() {
- return
- } loc(#loc2)
-}
-#loc1 = loc("test.f90":8:26)
-#loc2 = loc("test.f90":12:5)
-
-// CHECK-DAG: #[[R4:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "real(kind=4)", sizeInBits = 32, encoding = DW_ATE_float>
-// CHECK-DAG: #[[CU:.*]] = #llvm.di_compile_unit<{{.*}}>
-// CHECK-DAG: #[[MOD:.*]] = #llvm.di_module<{{.*}}scope = #[[CU]], name = "helper"{{.*}}>
-// CHECK-DAG: #[[PI:.*]] = #llvm.di_global_variable<scope = #[[MOD]], name = "pi", linkageName = "_QMhelperECpi"{{.*}}line = 8, type = #[[R4]], isDefined = true>
-// CHECK-DAG: #[[PIE:.*]] = #llvm.di_global_variable_expression<var = #[[PI]]>
``````````
</details>
https://github.com/llvm/llvm-project/pull/214813
More information about the flang-commits
mailing list