Skip to content

Commit 24cbf9e

Browse files
committed
Check DebugLoc is valid before using it.
1 parent c4ee7d9 commit 24cbf9e

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6601,25 +6601,27 @@ static Function *createOutlinedFunction(
66016601
DICompileUnit *CU = SP->getUnit();
66026602
DIBuilder DB(*M, true, CU);
66036603
DebugLoc DL = Builder.getCurrentDebugLocation();
6604-
// TODO: We are using nullopt for arguments at the moment. This will need
6605-
// to be updated when debug data is being generated for variables.
6606-
DISubroutineType *Ty =
6607-
DB.createSubroutineType(DB.getOrCreateTypeArray(std::nullopt));
6608-
DISubprogram::DISPFlags SPFlags = DISubprogram::SPFlagDefinition |
6609-
DISubprogram::SPFlagOptimized |
6610-
DISubprogram::SPFlagLocalToUnit;
6611-
6612-
DISubprogram *OutlinedSP = DB.createFunction(
6613-
CU, FuncName, FuncName, SP->getFile(), DL.getLine(), Ty, DL.getLine(),
6614-
DINode::DIFlags::FlagArtificial, SPFlags);
6615-
6616-
// Attach subprogram to the function.
6617-
Func->setSubprogram(OutlinedSP);
6618-
// Update the CurrentDebugLocation in the builder so that right scope
6619-
// is used for things inside outlined function.
6620-
Builder.SetCurrentDebugLocation(
6621-
DILocation::get(Func->getContext(), DL.getLine(), DL.getCol(),
6622-
OutlinedSP, DL.getInlinedAt()));
6604+
if (DL) {
6605+
// TODO: We are using nullopt for arguments at the moment. This will
6606+
// need to be updated when debug data is being generated for variables.
6607+
DISubroutineType *Ty =
6608+
DB.createSubroutineType(DB.getOrCreateTypeArray(std::nullopt));
6609+
DISubprogram::DISPFlags SPFlags = DISubprogram::SPFlagDefinition |
6610+
DISubprogram::SPFlagOptimized |
6611+
DISubprogram::SPFlagLocalToUnit;
6612+
6613+
DISubprogram *OutlinedSP = DB.createFunction(
6614+
CU, FuncName, FuncName, SP->getFile(), DL.getLine(), Ty,
6615+
DL.getLine(), DINode::DIFlags::FlagArtificial, SPFlags);
6616+
6617+
// Attach subprogram to the function.
6618+
Func->setSubprogram(OutlinedSP);
6619+
// Update the CurrentDebugLocation in the builder so that right scope
6620+
// is used for things inside outlined function.
6621+
Builder.SetCurrentDebugLocation(
6622+
DILocation::get(Func->getContext(), DL.getLine(), DL.getCol(),
6623+
OutlinedSP, DL.getInlinedAt()));
6624+
}
66236625
}
66246626
}
66256627

0 commit comments

Comments
 (0)