Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][debug] Don't generate debug for compiler-generated variables #112423

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions flang/include/flang/Optimizer/Support/InternalNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ struct NameUniquer {

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

/// Returns true if the passed name denotes a special symbol (e.g. global
/// symbol generated for derived type description).
static bool isSpecialSymbol(llvm::StringRef name);

private:
static std::string intAsString(std::int64_t i);
static std::string doKind(std::int64_t kind);
Expand Down
4 changes: 4 additions & 0 deletions flang/lib/Optimizer/Support/InternalNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,7 @@ fir::NameUniquer::dropTypeConversionMarkers(llvm::StringRef mangledTypeName) {
std::string fir::NameUniquer::replaceSpecialSymbols(const std::string &name) {
return std::regex_replace(name, std::regex{"\\."}, "X");
}

bool fir::NameUniquer::isSpecialSymbol(llvm::StringRef name) {
return !name.empty() && (name[0] == '.' || name[0] == 'X');
}
5 changes: 1 addition & 4 deletions flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ 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] == '.')
if (fir::NameUniquer::isSpecialSymbol(result.second.name))
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"{{.*}})
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