Skip to content

Commit 510cb67

Browse files
committed
[KeyInstr][Clang] Reset atomGroup number for each function
CGDebugInfo::completeFunction was added previously but mistakenly not called (dropped through the cracks while putting together the patch stack). Moved out of #134652 and #134654.
1 parent 8b9448e commit 510cb67

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "clang/CodeGen/CGFunctionInfo.h"
3737
#include "clang/Frontend/FrontendDiagnostic.h"
3838
#include "llvm/ADT/ArrayRef.h"
39+
#include "llvm/ADT/ScopeExit.h"
3940
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
4041
#include "llvm/IR/DataLayout.h"
4142
#include "llvm/IR/Dominators.h"
@@ -1506,6 +1507,11 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
15061507
// Disable debug info indefinitely for this function
15071508
DebugInfo = nullptr;
15081509
}
1510+
// Finalize function debug info on exit.
1511+
auto Cleanup = llvm::make_scope_exit([this] {
1512+
if (CGDebugInfo *DI = getDebugInfo())
1513+
DI->completeFunction();
1514+
});
15091515

15101516
// The function might not have a body if we're generating thunks for a
15111517
// function declaration.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -gkey-instructions -gno-column-info -x c++ %s -debug-info-kind=line-tables-only -emit-llvm -o - \
2+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
3+
4+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -gkey-instructions -gno-column-info -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - \
5+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
6+
7+
// Check atomGroup is reset to start at 1 in each function.
8+
9+
int g;
10+
// CHECK: store{{.*}}, !dbg [[AG:!.*]]
11+
void a() { g = 0; }
12+
13+
// CHECK: store{{.*}}, !dbg [[BG:!.*]]
14+
void b() { g = 0; }
15+
16+
// CHECK: [[A:!.*]] = distinct !DISubprogram(name: "a",
17+
// CHECK: [[AG]] = !DILocation(line: 11, scope: [[A]], atomGroup: 1, atomRank: 1)
18+
// CHECK: [[B:!.*]] = distinct !DISubprogram(name: "b",
19+
// CHECK: [[BG]] = !DILocation(line: 14, scope: [[B]], atomGroup: 1, atomRank: 1)

0 commit comments

Comments
 (0)