Skip to content

Commit e214fd6

Browse files
committed
Improve handling of privatized variables.
1 parent 4faa1d4 commit e214fd6

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6822,20 +6822,23 @@ static void FixupDebugInfoForOutlinedFunction(
68226822
auto GetUpdatedDIVariable = [&](DILocalVariable *OldVar, unsigned arg) {
68236823
auto NewSP = Func->getSubprogram();
68246824
DILocalVariable *&NewVar = RemappedVariables[OldVar];
6825-
if (!NewVar) {
6826-
DILocalScope *NewScope = DILocalScope::cloneScopeForSubprogram(
6827-
*OldVar->getScope(), *NewSP, Builder.getContext(), Cache);
6828-
NewVar = llvm::DILocalVariable::get(
6829-
Builder.getContext(), NewScope, OldVar->getName(), OldVar->getFile(),
6830-
OldVar->getLine(), OldVar->getType(), arg, OldVar->getFlags(),
6831-
OldVar->getAlignInBits(), OldVar->getAnnotations());
6832-
}
6825+
// Only use cached variable if the arg number matches. This is important
6826+
// so that DIVariable created for privatized variables are not discarded.
6827+
if (NewVar && (arg == NewVar->getArg()))
6828+
return NewVar;
6829+
6830+
DILocalScope *NewScope = DILocalScope::cloneScopeForSubprogram(
6831+
*OldVar->getScope(), *NewSP, Builder.getContext(), Cache);
6832+
NewVar = llvm::DILocalVariable::get(
6833+
Builder.getContext(), NewScope, OldVar->getName(), OldVar->getFile(),
6834+
OldVar->getLine(), OldVar->getType(), arg, OldVar->getFlags(),
6835+
OldVar->getAlignInBits(), OldVar->getAnnotations());
68336836
return NewVar;
68346837
};
68356838

68366839
auto UpdateDebugRecord = [&](auto *DR) {
68376840
DILocalVariable *OldVar = DR->getVariable();
6838-
unsigned ArgNo = OldVar->getArg();
6841+
unsigned ArgNo = 0;
68396842
for (auto Loc : DR->location_ops()) {
68406843
auto Iter = ValueReplacementMap.find(Loc);
68416844
if (Iter != ValueReplacementMap.end()) {

0 commit comments

Comments
 (0)