Skip to content

Commit ae3d827

Browse files
author
git apple-llvm automerger
committed
Merge commit 'c32753a77a72' from llvm.org/main into next
2 parents 5eae241 + c32753a commit ae3d827

File tree

10 files changed

+136
-38
lines changed

10 files changed

+136
-38
lines changed

llvm/include/llvm/AsmParser/LLToken.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -489,27 +489,28 @@ enum Kind {
489489
SummaryID, // ^42
490490

491491
// String valued tokens (StrVal).
492-
LabelStr, // foo:
493-
GlobalVar, // @foo @"foo"
494-
ComdatVar, // $foo
495-
LocalVar, // %foo %"foo"
496-
MetadataVar, // !foo
497-
StringConstant, // "foo"
498-
DwarfTag, // DW_TAG_foo
499-
DwarfAttEncoding, // DW_ATE_foo
500-
DwarfVirtuality, // DW_VIRTUALITY_foo
501-
DwarfLang, // DW_LANG_foo
502-
DwarfCC, // DW_CC_foo
503-
EmissionKind, // lineTablesOnly
504-
NameTableKind, // GNU
505-
FixedPointKind, // Fixed point
506-
DwarfOp, // DW_OP_foo
507-
DIFlag, // DIFlagFoo
508-
DISPFlag, // DISPFlagFoo
509-
DwarfMacinfo, // DW_MACINFO_foo
510-
ChecksumKind, // CSK_foo
511-
DbgRecordType, // dbg_foo
512-
DwarfEnumKind, // DW_APPLE_ENUM_KIND_foo
492+
LabelStr, // foo:
493+
GlobalVar, // @foo @"foo"
494+
ComdatVar, // $foo
495+
LocalVar, // %foo %"foo"
496+
MetadataVar, // !foo
497+
StringConstant, // "foo"
498+
DwarfTag, // DW_TAG_foo
499+
DwarfAttEncoding, // DW_ATE_foo
500+
DwarfVirtuality, // DW_VIRTUALITY_foo
501+
DwarfLang, // DW_LANG_foo
502+
DwarfSourceLangName, // DW_LNAME_foo
503+
DwarfCC, // DW_CC_foo
504+
EmissionKind, // lineTablesOnly
505+
NameTableKind, // GNU
506+
FixedPointKind, // Fixed point
507+
DwarfOp, // DW_OP_foo
508+
DIFlag, // DIFlagFoo
509+
DISPFlag, // DISPFlagFoo
510+
DwarfMacinfo, // DW_MACINFO_foo
511+
ChecksumKind, // CSK_foo
512+
DbgRecordType, // dbg_foo
513+
DwarfEnumKind, // DW_APPLE_ENUM_KIND_foo
513514

514515
// Type valued tokens (TyVal).
515516
Type,

llvm/lib/AsmParser/LLLexer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ lltok::Kind LLLexer::LexIdentifier() {
983983
DWKEYWORD(ATE, DwarfAttEncoding);
984984
DWKEYWORD(VIRTUALITY, DwarfVirtuality);
985985
DWKEYWORD(LANG, DwarfLang);
986+
DWKEYWORD(LNAME, DwarfSourceLangName);
986987
DWKEYWORD(CC, DwarfCC);
987988
DWKEYWORD(OP, DwarfOp);
988989
DWKEYWORD(MACINFO, DwarfMacinfo);

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4742,6 +4742,10 @@ struct DwarfLangField : public MDUnsignedField {
47424742
DwarfLangField() : MDUnsignedField(0, dwarf::DW_LANG_hi_user) {}
47434743
};
47444744

4745+
struct DwarfSourceLangNameField : public MDUnsignedField {
4746+
DwarfSourceLangNameField() : MDUnsignedField(0, UINT32_MAX) {}
4747+
};
4748+
47454749
struct DwarfCCField : public MDUnsignedField {
47464750
DwarfCCField() : MDUnsignedField(0, dwarf::DW_CC_hi_user) {}
47474751
};
@@ -5003,6 +5007,25 @@ bool LLParser::parseMDField(LocTy Loc, StringRef Name, DwarfLangField &Result) {
50035007
return false;
50045008
}
50055009

5010+
template <>
5011+
bool LLParser::parseMDField(LocTy Loc, StringRef Name,
5012+
DwarfSourceLangNameField &Result) {
5013+
if (Lex.getKind() == lltok::APSInt)
5014+
return parseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
5015+
5016+
if (Lex.getKind() != lltok::DwarfSourceLangName)
5017+
return tokError("expected DWARF source language name");
5018+
5019+
unsigned Lang = dwarf::getSourceLanguageName(Lex.getStrVal());
5020+
if (!Lang)
5021+
return tokError("invalid DWARF source language name" + Twine(" '") +
5022+
Lex.getStrVal() + "'");
5023+
assert(Lang <= Result.Max && "Expected valid DWARF source language name");
5024+
Result.assign(Lang);
5025+
Lex.Lex();
5026+
return false;
5027+
}
5028+
50065029
template <>
50075030
bool LLParser::parseMDField(LocTy Loc, StringRef Name, DwarfCCField &Result) {
50085031
if (Lex.getKind() == lltok::APSInt)
@@ -5842,9 +5865,12 @@ bool LLParser::parseDICompileUnit(MDNode *&Result, bool IsDistinct) {
58425865
if (!IsDistinct)
58435866
return tokError("missing 'distinct', required for !DICompileUnit");
58445867

5868+
LocTy Loc = Lex.getLoc();
5869+
58455870
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
5846-
REQUIRED(language, DwarfLangField, ); \
58475871
REQUIRED(file, MDField, (/* AllowNull */ false)); \
5872+
OPTIONAL(language, DwarfLangField, ); \
5873+
OPTIONAL(sourceLanguageName, DwarfSourceLangNameField, ); \
58485874
OPTIONAL(producer, MDStringField, ); \
58495875
OPTIONAL(isOptimized, MDBoolField, ); \
58505876
OPTIONAL(flags, MDStringField, ); \
@@ -5866,12 +5892,23 @@ bool LLParser::parseDICompileUnit(MDNode *&Result, bool IsDistinct) {
58665892
PARSE_MD_FIELDS();
58675893
#undef VISIT_MD_FIELDS
58685894

5895+
if (!language.Seen && !sourceLanguageName.Seen)
5896+
return error(Loc, "missing one of 'language' or 'sourceLanguageName', "
5897+
"required for !DICompileUnit");
5898+
5899+
if (language.Seen && sourceLanguageName.Seen)
5900+
return error(Loc, "can only specify one of 'language' and "
5901+
"'sourceLanguageName' on !DICompileUnit");
5902+
58695903
Result = DICompileUnit::getDistinct(
5870-
Context, DISourceLanguageName(language.Val), file.Val, producer.Val,
5871-
isOptimized.Val, flags.Val, runtimeVersion.Val, splitDebugFilename.Val,
5872-
emissionKind.Val, enums.Val, retainedTypes.Val, globals.Val, imports.Val,
5873-
macros.Val, dwoId.Val, splitDebugInlining.Val, debugInfoForProfiling.Val,
5874-
nameTableKind.Val, rangesBaseAddress.Val, sysroot.Val, sdk.Val);
5904+
Context,
5905+
language.Seen ? DISourceLanguageName(language.Val)
5906+
: DISourceLanguageName(sourceLanguageName.Val, 0),
5907+
file.Val, producer.Val, isOptimized.Val, flags.Val, runtimeVersion.Val,
5908+
splitDebugFilename.Val, emissionKind.Val, enums.Val, retainedTypes.Val,
5909+
globals.Val, imports.Val, macros.Val, dwoId.Val, splitDebugInlining.Val,
5910+
debugInfoForProfiling.Val, nameTableKind.Val, rangesBaseAddress.Val,
5911+
sysroot.Val, sdk.Val);
58755912
return false;
58765913
}
58775914

llvm/lib/Bitcode/Reader/MetadataLoader.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,12 +1868,18 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
18681868
// distinct. It's always distinct.
18691869
IsDistinct = true;
18701870

1871+
const auto LangVersionMask = (uint64_t(1) << 63);
1872+
const bool HasVersionedLanguage = Record[1] & LangVersionMask;
1873+
18711874
auto *CU = DICompileUnit::getDistinct(
1872-
Context, DISourceLanguageName(Record[1]), getMDOrNull(Record[2]),
1873-
getMDString(Record[3]), Record[4], getMDString(Record[5]), Record[6],
1874-
getMDString(Record[7]), Record[8], getMDOrNull(Record[9]),
1875-
getMDOrNull(Record[10]), getMDOrNull(Record[12]),
1876-
getMDOrNull(Record[13]),
1875+
Context,
1876+
HasVersionedLanguage
1877+
? DISourceLanguageName(Record[1] & ~LangVersionMask, 0)
1878+
: DISourceLanguageName(Record[1]),
1879+
getMDOrNull(Record[2]), getMDString(Record[3]), Record[4],
1880+
getMDString(Record[5]), Record[6], getMDString(Record[7]), Record[8],
1881+
getMDOrNull(Record[9]), getMDOrNull(Record[10]),
1882+
getMDOrNull(Record[12]), getMDOrNull(Record[13]),
18771883
Record.size() <= 15 ? nullptr : getMDOrNull(Record[15]),
18781884
Record.size() <= 14 ? 0 : Record[14],
18791885
Record.size() <= 16 ? true : Record[16],

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,13 @@ void ModuleBitcodeWriter::writeDICompileUnit(const DICompileUnit *N,
21112111
assert(N->isDistinct() && "Expected distinct compile units");
21122112
Record.push_back(/* IsDistinct */ true);
21132113

2114-
Record.push_back(N->getSourceLanguage().getUnversionedName());
2114+
auto Lang = N->getSourceLanguage();
2115+
Record.push_back(Lang.getName());
2116+
// Set bit so the MetadataLoader can distniguish between versioned and
2117+
// unversioned names.
2118+
if (Lang.hasVersionedName())
2119+
Record.back() ^= (uint64_t(1) << 63);
2120+
21152121
Record.push_back(VE.getMetadataOrNullID(N->getFile()));
21162122
Record.push_back(VE.getMetadataOrNullID(N->getRawProducer()));
21172123
Record.push_back(N->isOptimized());

llvm/lib/IR/AsmWriter.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,10 +2371,16 @@ static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N,
23712371
Out << "!DICompileUnit(";
23722372
MDFieldPrinter Printer(Out, WriterCtx);
23732373

2374-
Printer.printDwarfEnum("language",
2375-
N->getSourceLanguage().getUnversionedName(),
2376-
dwarf::LanguageString,
2377-
/* ShouldSkipZero */ false);
2374+
auto Lang = N->getSourceLanguage();
2375+
if (Lang.hasVersionedName())
2376+
Printer.printDwarfEnum(
2377+
"sourceLanguageName",
2378+
static_cast<llvm::dwarf::SourceLanguageName>(Lang.getName()),
2379+
dwarf::SourceLanguageNameString,
2380+
/* ShouldSkipZero */ false);
2381+
else
2382+
Printer.printDwarfEnum("language", Lang.getName(), dwarf::LanguageString,
2383+
/* ShouldSkipZero */ false);
23782384

23792385
Printer.printMetadata("file", N->getRawFile(), /* ShouldSkipNull */ false);
23802386
Printer.printString("producer", N->getProducer());
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
2+
3+
; CHECK: <stdin>:[[@LINE+1]]:15: error: can only specify one of 'language' and 'sourceLanguageName' on !DICompileUnit
4+
!0 = distinct !DICompileUnit(language: DW_LANG_C, sourceLanguageName: DW_LNAME_C, file: !DIFile(filename: "a", directory: "b"))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: split-file %s %t
2+
; RUN: not llvm-as < %t/invalid_dw_lang.ll -disable-output 2>&1 | FileCheck %s --check-prefix=INVALID_DW_LANG
3+
; RUN: not llvm-as < %t/invalid_dw_lang_2.ll -disable-output 2>&1 | FileCheck %s --check-prefix=INVALID_DW_LANG_2
4+
; RUN: not llvm-as < %t/invalid_dw_lname.ll -disable-output 2>&1 | FileCheck %s --check-prefix=INVALID_DW_LNAME
5+
; RUN: not llvm-as < %t/invalid_dw_lname_2.ll -disable-output 2>&1 | FileCheck %s --check-prefix=INVALID_DW_LNAME_2
6+
7+
; INVALID_DW_LANG: invalid DWARF language 'DW_LANG_blah'
8+
; INVALID_DW_LANG_2: expected DWARF language
9+
; INVALID_DW_LNAME: invalid DWARF source language name 'DW_LNAME_blah'
10+
; INVALID_DW_LNAME_2: expected DWARF source language name
11+
12+
;--- invalid_dw_lang.ll
13+
!0 = distinct !DICompileUnit(language: DW_LANG_blah)
14+
15+
;--- invalid_dw_lang_2.ll
16+
!0 = distinct !DICompileUnit(language: DW_LNAME_C)
17+
18+
;--- invalid_dw_lname.ll
19+
!0 = distinct !DICompileUnit(sourceLanguageName: DW_LNAME_blah)
20+
21+
;--- invalid_dw_lname_2.ll
22+
!0 = distinct !DICompileUnit(sourceLanguageName: DW_LANG_C)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
22

3-
; CHECK: <stdin>:[[@LINE+1]]:74: error: missing required field 'language'
3+
; CHECK: <stdin>:[[@LINE+1]]:15: error: missing one of 'language' or 'sourceLanguageName', required for !DICompileUnit
44
!0 = distinct !DICompileUnit(file: !DIFile(filename: "a", directory: "b"))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
2+
3+
; CHECK: sourceLanguageName: DW_LNAME_ObjC_plus_plus
4+
5+
source_filename = "cu.cpp"
6+
target triple = "arm64-apple-macosx"
7+
8+
!llvm.dbg.cu = !{!0}
9+
!llvm.module.flags = !{!3, !4}
10+
11+
!0 = distinct !DICompileUnit(sourceLanguageName: DW_LNAME_ObjC_plus_plus, file: !1, producer: "handwritten", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !2, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")
12+
!1 = !DIFile(filename: "cu.cpp", directory: "/tmp")
13+
!2 = !{}
14+
!3 = !{i32 7, !"Dwarf Version", i32 5}
15+
!4 = !{i32 2, !"Debug Info Version", i32 3}

0 commit comments

Comments
 (0)