Skip to content

Commit 95b4128

Browse files
authored
[flang][debug] Don't generate debug for compiler-generated variables (#112423)
Flang generates many globals to handle derived types. There was a check in debug info to filter them based on the information that their names start with a period. This changed since PR#104859 where 'X' is being used instead of '.'. This PR fixes this issue by also adding 'X' in that list. As user variables gets lower cased by the NameUniquer, there is no risk that those will be filtered out. I added a test for that to be sure.
1 parent 159f253 commit 95b4128

File tree

6 files changed

+49
-4
lines changed

6 files changed

+49
-4
lines changed

flang/include/flang/Optimizer/Support/InternalNames.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ struct NameUniquer {
184184

185185
static std::string replaceSpecialSymbols(const std::string &name);
186186

187+
/// Returns true if the passed name denotes a special symbol (e.g. global
188+
/// symbol generated for derived type description).
189+
static bool isSpecialSymbol(llvm::StringRef name);
190+
187191
private:
188192
static std::string intAsString(std::int64_t i);
189193
static std::string doKind(std::int64_t kind);

flang/lib/Optimizer/Support/InternalNames.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,7 @@ fir::NameUniquer::dropTypeConversionMarkers(llvm::StringRef mangledTypeName) {
411411
std::string fir::NameUniquer::replaceSpecialSymbols(const std::string &name) {
412412
return std::regex_replace(name, std::regex{"\\."}, "X");
413413
}
414+
415+
bool fir::NameUniquer::isSpecialSymbol(llvm::StringRef name) {
416+
return !name.empty() && (name[0] == '.' || name[0] == 'X');
417+
}

flang/lib/Optimizer/Transforms/AddDebugInfo.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,7 @@ void AddDebugInfoPass::handleGlobalOp(fir::GlobalOp globalOp,
211211
if (result.first != fir::NameUniquer::NameKind::VARIABLE)
212212
return;
213213

214-
// Discard entries that describe a derived type. Usually start with '.c.',
215-
// '.dt.' or '.n.'. It would be better if result of the deconstruct had a flag
216-
// for such values so that we dont have to look at string values.
217-
if (!result.second.name.empty() && result.second.name[0] == '.')
214+
if (fir::NameUniquer::isSpecialSymbol(result.second.name))
218215
return;
219216

220217
unsigned line = getLineFromLoc(globalOp.getLoc());
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s
2+
3+
module m
4+
integer XcX
5+
end
6+
7+
! Test that global starting with 'X' don't get filtered.
8+
! CHECK: !DIGlobalVariable(name: "xcx", linkageName: "_QMmExcx"{{.*}})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s
2+
3+
program test
4+
type t1
5+
integer :: XcX
6+
integer :: xdtx
7+
end type
8+
type(t1) :: var
9+
var%XcX = 2
10+
var%xdtx = 3
11+
end
12+
13+
! Test that there is no debug info for compiler generated globals.
14+
! CHECK-NOT: DIGlobalVariable
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
2+
3+
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
4+
fir.global linkonce_odr @_QFEXnXxcx constant target : !fir.char<1,3> {
5+
%0 = fir.string_lit "xcx"(3) : !fir.char<1,3>
6+
fir.has_value %0 : !fir.char<1,3>
7+
} loc(#loc1)
8+
fir.global linkonce_odr @_QFEXnXxdtx constant target : !fir.char<1,4> {
9+
%0 = fir.string_lit "xdtx"(4) : !fir.char<1,4>
10+
fir.has_value %0 : !fir.char<1,4>
11+
} loc(#loc1)
12+
}
13+
#loc1 = loc("derived.f90":24:1)
14+
15+
// Test that no di_global_variable gets created for these compile generated
16+
// globals.
17+
18+
// CHECK-NOT: #di_global_variable

0 commit comments

Comments
 (0)