@@ -162,8 +162,8 @@ class AsmParser : public MCAsmParser {
162162 };
163163 CppHashInfoTy CppHashInfo;
164164
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 ;
167167
168168 // / List of forward directional labels for diagnosis at the end.
169169 SmallVector<std::tuple<SMLoc, CppHashInfoTy, MCSymbol *>, 4 > DirLabels;
@@ -952,6 +952,12 @@ bool AsmParser::enabledGenDwarfForAssembly() {
952952 // the assembler source was produced with debug info already) then emit one
953953 // describing the assembler source file itself.
954954 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 );
955961 const MCDwarfFile &RootFile =
956962 getContext ().getMCDwarfLineTable (/* CUID=*/ 0 ).getRootFile ();
957963 getContext ().setGenDwarfFileNumber (getStreamer ().emitDwarfFileDirective (
@@ -2434,19 +2440,8 @@ bool AsmParser::parseCppHashLineFilenameComment(SMLoc L, bool SaveLocInfo) {
24342440 CppHashInfo.Filename = Filename;
24352441 CppHashInfo.LineNumber = LineNumber;
24362442 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;
24502445 return false ;
24512446}
24522447
0 commit comments