Skip to content

Commit c4d0d95

Browse files
authored
[KeyInstr][Clang] Reset atomGroup number for each function (#141607)
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. This patch is part of a stack that teaches Clang to generate Key Instructions metadata for C and C++. RFC: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668 The feature is only functional in LLVM if LLVM is built with CMake flag LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.
1 parent 63de20c commit c4d0d95

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"
@@ -1507,6 +1508,11 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
15071508
// Disable debug info indefinitely for this function
15081509
DebugInfo = nullptr;
15091510
}
1511+
// Finalize function debug info on exit.
1512+
auto Cleanup = llvm::make_scope_exit([this] {
1513+
if (CGDebugInfo *DI = getDebugInfo())
1514+
DI->completeFunction();
1515+
});
15101516

15111517
// The function might not have a body if we're generating thunks for a
15121518
// 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)