@@ -162,8 +162,8 @@ class AsmParser : public MCAsmParser {
162
162
};
163
163
CppHashInfoTy CppHashInfo;
164
164
165
- // / Have we seen any file line comment.
166
- bool HadCppHashFilename = false ;
165
+ // / The filename from the first cpp hash file line comment, if any .
166
+ StringRef FirstCppHashFilename ;
167
167
168
168
// / List of forward directional labels for diagnosis at the end.
169
169
SmallVector<std::tuple<SMLoc, CppHashInfoTy, MCSymbol *>, 4 > DirLabels;
@@ -952,6 +952,12 @@ bool AsmParser::enabledGenDwarfForAssembly() {
952
952
// the assembler source was produced with debug info already) then emit one
953
953
// describing the assembler source file itself.
954
954
if (getContext ().getGenDwarfFileNumber () == 0 ) {
955
+ // Use the first #line directive for this, if any. It's preprocessed, so
956
+ // there is no checksum, and of course no source directive.
957
+ if (!FirstCppHashFilename.empty ())
958
+ getContext ().setMCLineTableRootFile (
959
+ /* CUID=*/ 0 , getContext ().getCompilationDir (), FirstCppHashFilename,
960
+ /* Cksum=*/ std::nullopt, /* Source=*/ std::nullopt);
955
961
const MCDwarfFile &RootFile =
956
962
getContext ().getMCDwarfLineTable (/* CUID=*/ 0 ).getRootFile ();
957
963
getContext ().setGenDwarfFileNumber (getStreamer ().emitDwarfFileDirective (
@@ -2434,19 +2440,8 @@ bool AsmParser::parseCppHashLineFilenameComment(SMLoc L, bool SaveLocInfo) {
2434
2440
CppHashInfo.Filename = Filename;
2435
2441
CppHashInfo.LineNumber = LineNumber;
2436
2442
CppHashInfo.Buf = CurBuffer;
2437
- if (!HadCppHashFilename) {
2438
- HadCppHashFilename = true ;
2439
- // If we haven't encountered any .file directives, then the first #line
2440
- // directive describes the "root" file and directory of the compilation
2441
- // unit.
2442
- if (getContext ().getGenDwarfFileNumber () == 0 ) {
2443
- // It's preprocessed, so there is no checksum, and of course no source
2444
- // directive.
2445
- getContext ().setMCLineTableRootFile (
2446
- /* CUID=*/ 0 , getContext ().getCompilationDir (), Filename,
2447
- /* Cksum=*/ std::nullopt, /* Source=*/ std::nullopt);
2448
- }
2449
- }
2443
+ if (FirstCppHashFilename.empty ())
2444
+ FirstCppHashFilename = Filename;
2450
2445
return false ;
2451
2446
}
2452
2447
0 commit comments