Skip to content

Commit 3d10997

Browse files
arlosirnk
authored andcommitted
Add Rust to CodeView SourceLanguage (CV_CFL_LANG) enum
Microsoft has added several new entries to the CV_CFL_LANG enum, including Rust: https://docs.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/cv-cfl-lang This change adds Rust to the corresponding LLVM enum and translates `dwarf::DW_LANG_Rust` to `SourceLanguage::Rust` in the CodeView AsmPrinter. This means that Rust will no longer emit as Masm. Differential Revision: https://reviews.llvm.org/D115300
1 parent e37b6a6 commit 3d10997

File tree

8 files changed

+59
-1
lines changed

8 files changed

+59
-1
lines changed

llvm/include/llvm/DebugInfo/CodeView/CodeView.h

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ enum SourceLanguage : uint8_t {
162162
MSIL = 0x0f,
163163
HLSL = 0x10,
164164

165+
Rust = 0x15,
166+
165167
/// The DMD & Swift compilers emit 'D' and 'S', respectively, for the CV
166168
/// source language. Microsoft does not have enumerators for them yet.
167169
D = 'D',

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ static SourceLanguage MapDWLangToCVLang(unsigned DWLang) {
600600
return SourceLanguage::D;
601601
case dwarf::DW_LANG_Swift:
602602
return SourceLanguage::Swift;
603+
case dwarf::DW_LANG_Rust:
604+
return SourceLanguage::Rust;
603605
default:
604606
// There's no CodeView representation for this language, and CV doesn't
605607
// have an "unknown" option for the language field, so we'll use MASM,

llvm/lib/DebugInfo/CodeView/EnumTables.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static const EnumEntry<codeview::SourceLanguage> SourceLanguages[] = {
104104
CV_ENUM_ENT(SourceLanguage, ILAsm), CV_ENUM_ENT(SourceLanguage, Java),
105105
CV_ENUM_ENT(SourceLanguage, JScript), CV_ENUM_ENT(SourceLanguage, MSIL),
106106
CV_ENUM_ENT(SourceLanguage, HLSL), CV_ENUM_ENT(SourceLanguage, D),
107-
CV_ENUM_ENT(SourceLanguage, Swift),
107+
CV_ENUM_ENT(SourceLanguage, Swift), CV_ENUM_ENT(SourceLanguage, Rust),
108108
};
109109

110110
static const EnumEntry<uint32_t> CompileSym2FlagNames[] = {

llvm/lib/DebugInfo/PDB/PDBExtras.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ raw_ostream &llvm::pdb::operator<<(raw_ostream &OS, const PDB_Lang &Lang) {
231231
CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, HLSL, OS)
232232
CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, D, OS)
233233
CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Swift, OS)
234+
CASE_OUTPUT_ENUM_CLASS_NAME(PDB_Lang, Rust, OS)
234235
}
235236
return OS;
236237
}

llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ std::string PDBSymbolCompiland::getSourceFileFullPath() const {
100100
.Case(".c", Lang == PDB_Lang::C)
101101
.Case(".asm", Lang == PDB_Lang::Masm)
102102
.Case(".swift", Lang == PDB_Lang::Swift)
103+
.Case(".rs", Lang == PDB_Lang::Rust)
103104
.Default(false))
104105
return File->getFileName();
105106
}

llvm/test/DebugInfo/COFF/language.ll

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
;
3737
; RUN: sed -e 's/<LANG1>/DW_LANG_Fortran08/;s/<LANG2>/Fortran/' %s > %t
3838
; RUN: llc -filetype=obj -o - %t | llvm-readobj --codeview - | FileCheck %t
39+
;
40+
; RUN: sed -e 's/<LANG1>/DW_LANG_Rust/;s/<LANG2>/Rust/' %s > %t
41+
; RUN: llc -filetype=obj -o - %t | llvm-readobj --codeview - | FileCheck %t
3942

4043
; CHECK: CodeViewDebugInfo [
4144
; CHECK: Subsection [

llvm/test/DebugInfo/COFF/rust.ll

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; RUN: llc < %s | FileCheck %s --check-prefix=ASM
2+
; RUN: llc -filetype=obj < %s | llvm-readobj --codeview - | FileCheck %s --check-prefix=OBJ
3+
4+
; ASM: .short 4412 # Record kind: S_COMPILE3
5+
; ASM-NEXT: .long 21 # Flags and language
6+
; ASM-NEXT: .short 208 # CPUType
7+
8+
; OBJ-LABEL: Compile3Sym {
9+
; OBJ-NEXT: Kind: S_COMPILE3 (0x113C)
10+
; OBJ-NEXT: Language: Rust (0x15)
11+
; OBJ-NEXT: Flags [ (0x0)
12+
; OBJ-NEXT: ]
13+
; OBJ-NEXT: Machine: X64 (0xD0)
14+
; OBJ-NEXT: FrontendVersion: {{[0-9.]*}}
15+
; OBJ-NEXT: BackendVersion: {{[0-9.]*}}
16+
; OBJ-NEXT: VersionName: clang LLVM (rustc version 1.57.0 (f1edd0429 2021-11-29))
17+
; OBJ-NEXT: }
18+
19+
20+
; ModuleID = 'main.a61fec89-cgu.0'
21+
source_filename = "main.a61fec89-cgu.0"
22+
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
23+
target triple = "x86_64-pc-windows-msvc"
24+
25+
; Function Attrs: uwtable
26+
define void @f() unnamed_addr #0 !dbg !6 {
27+
start:
28+
ret void, !dbg !11
29+
}
30+
31+
attributes #0 = { uwtable "target-cpu"="x86-64" }
32+
33+
!llvm.module.flags = !{!0, !1, !2}
34+
!llvm.dbg.cu = !{!3}
35+
36+
!0 = !{i32 7, !"PIC Level", i32 2}
37+
!1 = !{i32 2, !"CodeView", i32 1}
38+
!2 = !{i32 2, !"Debug Info Version", i32 3}
39+
!3 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !4, producer: "clang LLVM (rustc version 1.57.0 (f1edd0429 2021-11-29))", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !5)
40+
!4 = !DIFile(filename: "main.rs", directory: "src")
41+
!5 = !{}
42+
!6 = distinct !DISubprogram(name: "f", scope: !8, file: !7, line: 13, type: !9, scopeLine: 13, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !3, templateParams: !5, retainedNodes: !5)
43+
!7 = !DIFile(filename: "main.rs", directory: "src", checksumkind: CSK_SHA1, checksum: "2ac9107db410c2ac03093f537ff521068091fb92")
44+
!8 = !DINamespace(name: "main", scope: null)
45+
!9 = !DISubroutineType(types: !10)
46+
!10 = !{null}
47+
!11 = !DILocation(line: 14, scope: !12)
48+
!12 = !DILexicalBlockFile(scope: !6, file: !7, discriminator: 0)

llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ static std::string formatSourceLanguage(SourceLanguage Lang) {
207207
RETURN_CASE(SourceLanguage, HLSL, "hlsl");
208208
RETURN_CASE(SourceLanguage, D, "d");
209209
RETURN_CASE(SourceLanguage, Swift, "swift");
210+
RETURN_CASE(SourceLanguage, Rust, "rust");
210211
}
211212
return formatUnknownEnum(Lang);
212213
}

0 commit comments

Comments
 (0)