[PATCH] D94882: [MC] Upgrade DWARF version to 5 upon .file 0

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 09:41:13 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG3e8ab54ba072: [MC] Upgrade DWARF version to 5 upon .file 0 (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94882/new/

https://reviews.llvm.org/D94882

Files:
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/test/MC/ELF/dwarf-file0.s
  llvm/test/MC/ELF/dwarf-loc0.s


Index: llvm/test/MC/ELF/dwarf-loc0.s
===================================================================
--- llvm/test/MC/ELF/dwarf-loc0.s
+++ llvm/test/MC/ELF/dwarf-loc0.s
@@ -1,8 +1,10 @@
 # REQUIRES: default_triple
-# RUN: llvm-mc -dwarf-version 5 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s
+# RUN: llvm-mc -dwarf-version 5 --defsym FILE0=1 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s
 # RUN: not llvm-mc -dwarf-version 4 %s -filetype=asm -o - 2>&1 | FileCheck %s -check-prefix=ERR
 # Show that ".loc 0" works in DWARF v5, gets an error for earlier versions.
+.ifdef FILE0
         .file 0 "root.cpp"
+.endif
         .file 1 "header.h"
 	.loc  0 10 0
         .byte 0
Index: llvm/test/MC/ELF/dwarf-file0.s
===================================================================
--- llvm/test/MC/ELF/dwarf-file0.s
+++ llvm/test/MC/ELF/dwarf-file0.s
@@ -1,34 +1,22 @@
 # REQUIRES: default_triple
-# RUN: llvm-mc -dwarf-version 4 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s --check-prefixes=CHECK,CHECK-4
-# RUN: llvm-mc -dwarf-version 4 %s -filetype=asm -o - | FileCheck %s --check-prefixes=ASM,ASM-4
-# RUN: llvm-mc -dwarf-version 4 %s -filetype=asm -o - 2>&1 | FileCheck %s --check-prefix=WARN
-# RUN: llvm-mc -dwarf-version 5 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s --check-prefixes=CHECK,CHECK-5
-# RUN: llvm-mc -dwarf-version 5 %s -filetype=asm -o - | FileCheck %s --check-prefixes=ASM,ASM-5
+# RUN: llvm-mc -dwarf-version 4 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s
+# RUN: llvm-mc -dwarf-version 4 %s --fatal-warnings -o - | FileCheck %s --check-prefix=ASM
+# RUN: llvm-mc -dwarf-version 5 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s
+# RUN: llvm-mc -dwarf-version 5 %s -o - | FileCheck %s --check-prefix=ASM
+
+## If the DWARF version is less than 5, .file 0 upgrades the version to 5.
         .file 0 "/test" "root.cpp"
         .file 1 "/include" "header.h"
         .file 2 "/test" "root.cpp"
-# CHECK-5:     include_directories[ 0] = "/test"
-# CHECK-4-NOT: include_directories[ 0]
-# CHECK:       include_directories[ 1] = "/include"
-# CHECK-4:     include_directories[ 2] = "/test"
-# CHECK-NOT:   include_directories
-# CHECK-4-NOT: file_names[ 0]
-# CHECK-5:     file_names[ 0]:
-# CHECK-5-NEXT: name: "root.cpp"
-# CHECK-5-NEXT: dir_index: 0
-# CHECK:       file_names[ 1]:
-# CHECK-NEXT:  name: "header.h"
-# CHECK-NEXT:  dir_index: 1
-# CHECK-4:     file_names[ 2]:
-# CHECK-4-NEXT: name: "root.cpp"
-# CHECK-4-NEXT: dir_index: 2
+# CHECK:       include_directories[  0] = "/test"
+# CHECK-NEXT:  include_directories[  1] = "/include"
+# CHECK:       file_names[  0]:
+# CHECK-NEXT:             name: "root.cpp"
+# CHECK-NEXT:        dir_index: 0
+# CHECK-NEXT:  file_names[  1]:
+# CHECK-NEXT:             name: "header.h"
+# CHECK-NEXT:        dir_index: 1
 
-# ASM-NOT: .file
-# ASM-5:   .file 0 "/test" "root.cpp"
+# ASM:     .file 0 "/test" "root.cpp"
 # ASM:     .file 1 "/include" "header.h"
-# ASM-4:   .file 2 "/test" "root.cpp"
 # ASM-NOT: .file
-
-# WARN:      file 0 not supported prior to DWARF-5
-# WARN-NEXT: .file 0
-# WARN-NEXT: ^
Index: llvm/lib/MC/MCParser/AsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/AsmParser.cpp
+++ llvm/lib/MC/MCParser/AsmParser.cpp
@@ -3485,8 +3485,9 @@
       Source = StringRef(SourceBuf, SourceString.size());
     }
     if (FileNumber == 0) {
+      // Upgrade to Version 5 for assembly actions like clang -c a.s.
       if (Ctx.getDwarfVersion() < 5)
-        return Warning(DirectiveLoc, "file 0 not supported prior to DWARF-5");
+        Ctx.setDwarfVersion(5);
       getStreamer().emitDwarfFile0Directive(Directory, Filename, CKMem, Source);
     } else {
       Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94882.320826.patch
Type: text/x-patch
Size: 3922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210202/e4fd9f65/attachment.bin>


More information about the llvm-commits mailing list