Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,13 @@ void AddDebugInfoPass::handleGlobalOp(fir::GlobalOp globalOp,
if (result.first != fir::NameUniquer::NameKind::VARIABLE)
return;

// Discard entries that describe a derived type. Usually start with '.c.',
// '.dt.' or '.n.'. It would be better if result of the deconstruct had a flag
// for such values so that we dont have to look at string values.
if (!result.second.name.empty() && result.second.name[0] == '.')
// Discard entries that describe a derived type. They start with either '.' or
// 'X'. We filter both of them out. Note that NameUniquer makes the name lower
// case so user variables should be safe. It would be better if result of the
// deconstruct had a flag for such values so that we dont have to look at
// string values.
if (!result.second.name.empty() &&
(result.second.name[0] == '.' || result.second.name[0] == 'X'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the result.second.name[0] == '.' || result.second.name[0] == 'X' part into some static fir::NameUniquer::isSpecialSymbol(llvm::StringRef name) helper in Optimizer/Support/InternalNames so that the usages of these delimiters are better centralized and advertise.

Long term, it may be better to have some compiler generated flag attributes on the global/declare for such variables (and others) rather than relying on the names.
In semantics, these variables are tagged with the CompilerCreated symbol attribute, but it is currently not represented in FIR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I have moved the code into a separate function.

return;

unsigned line = getLineFromLoc(globalOp.getLoc());
Expand Down
8 changes: 8 additions & 0 deletions flang/test/Integration/debug-extra-global-2.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s

module m
integer XcX
end

! Test that global starting with 'X' don't get filtered.
CHECK: !DIGlobalVariable(name: "xcx", linkageName: "_QMmExcx"{{.*}})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CHECK: !DIGlobalVariable(name: "xcx", linkageName: "_QMmExcx"{{.*}})
! CHECK: !DIGlobalVariable(name: "xcx", linkageName: "_QMmExcx"{{.*}})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. Fixed.

14 changes: 14 additions & 0 deletions flang/test/Integration/debug-extra-global.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s

program test
type t1
integer :: XcX
integer :: xdtx
end type
type(t1) :: var
var%XcX = 2
var%xdtx = 3
end

! Test that there is no debug info for compiler generated globals.
! CHECK-NOT: DIGlobalVariable
18 changes: 18 additions & 0 deletions flang/test/Transforms/debug-extra-global.fir
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s

module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
fir.global linkonce_odr @_QFEXnXxcx constant target : !fir.char<1,3> {
%0 = fir.string_lit "xcx"(3) : !fir.char<1,3>
fir.has_value %0 : !fir.char<1,3>
} loc(#loc1)
fir.global linkonce_odr @_QFEXnXxdtx constant target : !fir.char<1,4> {
%0 = fir.string_lit "xdtx"(4) : !fir.char<1,4>
fir.has_value %0 : !fir.char<1,4>
} loc(#loc1)
}
#loc1 = loc("derived.f90":24:1)

// Test that no di_global_variable gets created for these compile generated
// globals.

// CHECK-NOT: #di_global_variable
Loading