Skip to content

Commit 6419496

Browse files
authored
[flang][OMPIRBuilder] Keep debug location in sync with insert point. (#89953)
A customer reported an issue which I have reduced to the test in the PR. If built with debug info enabled, the build fails with the following error in the verifier. !dbg attachment points at wrong subprogram for function The problem happened because some of the functions in OMPIRBuilder.cpp updated the insertion point with the passed in location but did not change the current debug location. This caused a stale debug location to be attached to the instruction. I have solved it by replacing restoreIP with updateToLocation which updates both the insertion point and debug location. The updateToLocation is used in many places already, so this PR brings functions that I have changed in line with rest of the file. Slight issue is that I am not checking the return type of updateToLocation as there is no good value I could return in that case. But if we have a condition where updateToLocation will return false, these functions will fail in any case. I have added a test that checks that build does not fail. I was not sure what is the correct location for the test should be. Happy to move it to more appropriate location.
1 parent e6d29be commit 6419496

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
!RUN: %flang_fc1 -emit-llvm -debug-info-kind=line-tables-only -fopenmp %s -o - | FileCheck %s
2+
3+
! Test that this file builds without an error.
4+
5+
module debugloc
6+
contains
7+
subroutine test1
8+
implicit none
9+
integer :: i
10+
real, save :: var
11+
12+
! CHECK: DILocation(line: [[@LINE+1]], {{.*}})
13+
!$omp parallel do
14+
do i=1,100
15+
var = var + 0.1
16+
end do
17+
!$omp end parallel do
18+
19+
end subroutine test1
20+
21+
subroutine test2
22+
23+
real, save :: tp
24+
!$omp threadprivate (tp)
25+
! CHECK: DILocation(line: [[@LINE+1]], {{.*}})
26+
tp = tp + 1
27+
28+
end subroutine test2
29+
30+
end module debugloc

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4401,7 +4401,7 @@ CallInst *OpenMPIRBuilder::createOMPAlloc(const LocationDescription &Loc,
44014401
Value *Size, Value *Allocator,
44024402
std::string Name) {
44034403
IRBuilder<>::InsertPointGuard IPG(Builder);
4404-
Builder.restoreIP(Loc.IP);
4404+
updateToLocation(Loc);
44054405

44064406
uint32_t SrcLocStrSize;
44074407
Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize);
@@ -4418,7 +4418,7 @@ CallInst *OpenMPIRBuilder::createOMPFree(const LocationDescription &Loc,
44184418
Value *Addr, Value *Allocator,
44194419
std::string Name) {
44204420
IRBuilder<>::InsertPointGuard IPG(Builder);
4421-
Builder.restoreIP(Loc.IP);
4421+
updateToLocation(Loc);
44224422

44234423
uint32_t SrcLocStrSize;
44244424
Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize);
@@ -4434,7 +4434,7 @@ CallInst *OpenMPIRBuilder::createOMPInteropInit(
44344434
omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,
44354435
Value *DependenceAddress, bool HaveNowaitClause) {
44364436
IRBuilder<>::InsertPointGuard IPG(Builder);
4437-
Builder.restoreIP(Loc.IP);
4437+
updateToLocation(Loc);
44384438

44394439
uint32_t SrcLocStrSize;
44404440
Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize);
@@ -4462,7 +4462,7 @@ CallInst *OpenMPIRBuilder::createOMPInteropDestroy(
44624462
const LocationDescription &Loc, Value *InteropVar, Value *Device,
44634463
Value *NumDependences, Value *DependenceAddress, bool HaveNowaitClause) {
44644464
IRBuilder<>::InsertPointGuard IPG(Builder);
4465-
Builder.restoreIP(Loc.IP);
4465+
updateToLocation(Loc);
44664466

44674467
uint32_t SrcLocStrSize;
44684468
Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize);
@@ -4491,7 +4491,7 @@ CallInst *OpenMPIRBuilder::createOMPInteropUse(const LocationDescription &Loc,
44914491
Value *DependenceAddress,
44924492
bool HaveNowaitClause) {
44934493
IRBuilder<>::InsertPointGuard IPG(Builder);
4494-
Builder.restoreIP(Loc.IP);
4494+
updateToLocation(Loc);
44954495
uint32_t SrcLocStrSize;
44964496
Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize);
44974497
Value *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize);
@@ -4517,7 +4517,7 @@ CallInst *OpenMPIRBuilder::createCachedThreadPrivate(
45174517
const LocationDescription &Loc, llvm::Value *Pointer,
45184518
llvm::ConstantInt *Size, const llvm::Twine &Name) {
45194519
IRBuilder<>::InsertPointGuard IPG(Builder);
4520-
Builder.restoreIP(Loc.IP);
4520+
updateToLocation(Loc);
45214521

45224522
uint32_t SrcLocStrSize;
45234523
Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize);

0 commit comments

Comments
 (0)