Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,8 @@ void CGDebugInfo::CreateCompileUnit() {

// Create new compile unit.
TheCU = DBuilder.createCompileUnit(
LangTag, CUFile, CGOpts.EmitVersionIdentMetadata ? Producer : "",
llvm::DISourceLanguageName(LangTag), CUFile,
CGOpts.EmitVersionIdentMetadata ? Producer : "",
CGOpts.OptimizationLevel != 0 || CGOpts.PrepareForLTO ||
CGOpts.PrepareForThinLTO,
CGOpts.DwarfDebugFlags, RuntimeVers, CGOpts.SplitDwarfFile, EmissionKind,
Expand Down Expand Up @@ -1232,7 +1233,7 @@ llvm::DIType *CGDebugInfo::CreateType(const PointerType *Ty,

/// \return whether a C++ mangling exists for the type defined by TD.
static bool hasCXXMangling(const TagDecl *TD, llvm::DICompileUnit *TheCU) {
switch (TheCU->getSourceLanguage()) {
switch (TheCU->getSourceLanguage().getUnversionedName()) {
case llvm::dwarf::DW_LANG_C_plus_plus:
case llvm::dwarf::DW_LANG_C_plus_plus_11:
case llvm::dwarf::DW_LANG_C_plus_plus_14:
Expand Down Expand Up @@ -3211,8 +3212,8 @@ llvm::DIType *CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
if (!ID)
return nullptr;

auto RuntimeLang =
static_cast<llvm::dwarf::SourceLanguage>(TheCU->getSourceLanguage());
auto RuntimeLang = static_cast<llvm::dwarf::SourceLanguage>(
TheCU->getSourceLanguage().getUnversionedName());

// Return a forward declaration if this type was imported from a clang module,
// and this is not the compile unit with the implementation of the type (which
Expand Down Expand Up @@ -3348,7 +3349,8 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const ObjCInterfaceType *Ty,
ObjCInterfaceDecl *ID = Ty->getDecl();
llvm::DIFile *DefUnit = getOrCreateFile(ID->getLocation());
unsigned Line = getLineNumber(ID->getLocation());
unsigned RuntimeLang = TheCU->getSourceLanguage();

unsigned RuntimeLang = TheCU->getSourceLanguage().getUnversionedName();

// Bit size, align and offset of the type.
uint64_t Size = CGM.getContext().getTypeSize(Ty);
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/IR/DIBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ namespace llvm {
/// \param SDK The SDK name. On Darwin, this is the last component
/// of the sysroot.
LLVM_ABI DICompileUnit *
createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer,
bool isOptimized, StringRef Flags, unsigned RV,
StringRef SplitName = StringRef(),
createCompileUnit(DISourceLanguageName Lang, DIFile *File,
StringRef Producer, bool isOptimized, StringRef Flags,
unsigned RV, StringRef SplitName = StringRef(),
DICompileUnit::DebugEmissionKind Kind =
DICompileUnit::DebugEmissionKind::FullDebug,
uint64_t DWOId = 0, bool SplitDebugInlining = true,
Expand Down
76 changes: 63 additions & 13 deletions llvm/include/llvm/IR/DebugInfoMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,55 @@ namespace dwarf {
enum Tag : uint16_t;
}

/// Wrapper structure that holds a language name and its version.
///
/// Some debug-info formats, particularly DWARF, distniguish between
/// language codes that include the version name and codes that don't.
/// DISourceLanguageName may hold either of these.
///
class DISourceLanguageName {
/// Language version. The version scheme is language
/// dependent.
uint32_t Version = 0;

/// Language name.
/// If \ref HasVersion is \c true, then this name
/// is version independent (i.e., doesn't include the language
/// version in its name).
uint16_t Name;

/// If \c true, then \ref Version is interpretable and \ref Name
/// is a version independent name.
bool HasVersion;

public:
bool hasVersionedName() const { return HasVersion; }

/// Returns a versioned or unversioned language name.
uint16_t getName() const { return Name; }

/// Transitional API for cases where we do not yet support
/// versioned source language names. Use \ref getName instead.
///
/// FIXME: remove once all callers of this API account for versioned
/// names.
uint16_t getUnversionedName() const {
assert(!hasVersionedName());
return Name;
}

/// Returns language version. Only valid for versioned language names.
uint32_t getVersion() const {
assert(hasVersionedName());
return Version;
}

DISourceLanguageName(uint16_t Lang, uint32_t Version)
: Version(Version), Name(Lang), HasVersion(true) {};
DISourceLanguageName(uint16_t Lang)
: Version(0), Name(Lang), HasVersion(false) {};
};

class DbgVariableRecord;

LLVM_ABI extern cl::opt<bool> EnableFSDiscriminator;
Expand Down Expand Up @@ -2003,7 +2052,7 @@ class DICompileUnit : public DIScope {
LLVM_ABI static const char *nameTableKindString(DebugNameTableKind PK);

private:
unsigned SourceLanguage;
DISourceLanguageName SourceLanguage;
unsigned RuntimeVersion;
uint64_t DWOId;
unsigned EmissionKind;
Expand All @@ -2013,16 +2062,17 @@ class DICompileUnit : public DIScope {
bool DebugInfoForProfiling;
bool RangesBaseAddress;

DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
bool IsOptimized, unsigned RuntimeVersion,
unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
bool DebugInfoForProfiling, unsigned NameTableKind,
bool RangesBaseAddress, ArrayRef<Metadata *> Ops);
DICompileUnit(LLVMContext &C, StorageType Storage,
DISourceLanguageName SourceLanguage, bool IsOptimized,
unsigned RuntimeVersion, unsigned EmissionKind, uint64_t DWOId,
bool SplitDebugInlining, bool DebugInfoForProfiling,
unsigned NameTableKind, bool RangesBaseAddress,
ArrayRef<Metadata *> Ops);
~DICompileUnit() = default;

static DICompileUnit *
getImpl(LLVMContext &Context, unsigned SourceLanguage, DIFile *File,
StringRef Producer, bool IsOptimized, StringRef Flags,
getImpl(LLVMContext &Context, DISourceLanguageName SourceLanguage,
DIFile *File, StringRef Producer, bool IsOptimized, StringRef Flags,
unsigned RuntimeVersion, StringRef SplitDebugFilename,
unsigned EmissionKind, DICompositeTypeArray EnumTypes,
DIScopeArray RetainedTypes,
Expand All @@ -2042,8 +2092,8 @@ class DICompileUnit : public DIScope {
getCanonicalMDString(Context, SDK), Storage, ShouldCreate);
}
LLVM_ABI static DICompileUnit *
getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
MDString *Producer, bool IsOptimized, MDString *Flags,
getImpl(LLVMContext &Context, DISourceLanguageName SourceLanguage,
Metadata *File, MDString *Producer, bool IsOptimized, MDString *Flags,
unsigned RuntimeVersion, MDString *SplitDebugFilename,
unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
Metadata *GlobalVariables, Metadata *ImportedEntities,
Expand All @@ -2068,7 +2118,7 @@ class DICompileUnit : public DIScope {

DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
DICompileUnit,
(unsigned SourceLanguage, DIFile *File, StringRef Producer,
(DISourceLanguageName SourceLanguage, DIFile *File, StringRef Producer,
bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
StringRef SplitDebugFilename, DebugEmissionKind EmissionKind,
DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
Expand All @@ -2084,7 +2134,7 @@ class DICompileUnit : public DIScope {
SysRoot, SDK))
DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
DICompileUnit,
(unsigned SourceLanguage, Metadata *File, MDString *Producer,
(DISourceLanguageName SourceLanguage, Metadata *File, MDString *Producer,
bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes,
Metadata *RetainedTypes, Metadata *GlobalVariables,
Expand All @@ -2099,7 +2149,7 @@ class DICompileUnit : public DIScope {

TempDICompileUnit clone() const { return cloneImpl(); }

unsigned getSourceLanguage() const { return SourceLanguage; }
DISourceLanguageName getSourceLanguage() const { return SourceLanguage; }
bool isOptimized() const { return IsOptimized; }
unsigned getRuntimeVersion() const { return RuntimeVersion; }
DebugEmissionKind getEmissionKind() const {
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/Analysis/ModuleDebugInfoPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ static void printModuleDebugInfo(raw_ostream &O, const Module *M,
// filenames), so just print a few useful things.
for (DICompileUnit *CU : Finder.compile_units()) {
O << "Compile unit: ";
auto Lang = dwarf::LanguageString(CU->getSourceLanguage());
auto Lang =
dwarf::LanguageString(CU->getSourceLanguage().getUnversionedName());
if (!Lang.empty())
O << Lang;
else
O << "unknown-language(" << CU->getSourceLanguage() << ")";
O << "unknown-language(" << CU->getSourceLanguage().getUnversionedName()
<< ")";
printFile(O, CU->getFilename(), CU->getDirectory());
O << '\n';
}
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5861,11 +5861,11 @@ bool LLParser::parseDICompileUnit(MDNode *&Result, bool IsDistinct) {
#undef VISIT_MD_FIELDS

Result = DICompileUnit::getDistinct(
Context, language.Val, file.Val, producer.Val, isOptimized.Val, flags.Val,
runtimeVersion.Val, splitDebugFilename.Val, emissionKind.Val, enums.Val,
retainedTypes.Val, globals.Val, imports.Val, macros.Val, dwoId.Val,
splitDebugInlining.Val, debugInfoForProfiling.Val, nameTableKind.Val,
rangesBaseAddress.Val, sysroot.Val, sdk.Val);
Context, DISourceLanguageName(language.Val), file.Val, producer.Val,
isOptimized.Val, flags.Val, runtimeVersion.Val, splitDebugFilename.Val,
emissionKind.Val, enums.Val, retainedTypes.Val, globals.Val, imports.Val,
macros.Val, dwoId.Val, splitDebugInlining.Val, debugInfoForProfiling.Val,
nameTableKind.Val, rangesBaseAddress.Val, sysroot.Val, sdk.Val);
return false;
}

Expand Down
10 changes: 6 additions & 4 deletions llvm/lib/Bitcode/Reader/MetadataLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1866,11 +1866,13 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
// Ignore Record[0], which indicates whether this compile unit is
// distinct. It's always distinct.
IsDistinct = true;

auto *CU = DICompileUnit::getDistinct(
Context, Record[1], getMDOrNull(Record[2]), getMDString(Record[3]),
Record[4], getMDString(Record[5]), Record[6], getMDString(Record[7]),
Record[8], getMDOrNull(Record[9]), getMDOrNull(Record[10]),
getMDOrNull(Record[12]), getMDOrNull(Record[13]),
Context, DISourceLanguageName(Record[1]), getMDOrNull(Record[2]),
getMDString(Record[3]), Record[4], getMDString(Record[5]), Record[6],
getMDString(Record[7]), Record[8], getMDOrNull(Record[9]),
getMDOrNull(Record[10]), getMDOrNull(Record[12]),
getMDOrNull(Record[13]),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the AutoUpgrade from the old format work here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally (assuming that the old and new enums are not compatible, we should add a .bc file to the tests with a compile unit in the old format to prove that we can upgrade it correctly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, looks like I misunderstood what this patch is doing — it's NFC as far as the bitcode format is concerned.

Record.size() <= 15 ? nullptr : getMDOrNull(Record[15]),
Record.size() <= 14 ? 0 : Record[14],
Record.size() <= 16 ? true : Record[16],
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2105,7 +2105,8 @@ void ModuleBitcodeWriter::writeDICompileUnit(const DICompileUnit *N,
unsigned Abbrev) {
assert(N->isDistinct() && "Expected distinct compile units");
Record.push_back(/* IsDistinct */ true);
Record.push_back(N->getSourceLanguage());

Record.push_back(N->getSourceLanguage().getUnversionedName());
Record.push_back(VE.getMetadataOrNullID(N->getFile()));
Record.push_back(VE.getMetadataOrNullID(N->getRawProducer()));
Record.push_back(N->isOptimized());
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ void CodeViewDebug::beginModule(Module *M) {
Node = *CUs->operands().begin();
}
const auto *CU = cast<DICompileUnit>(Node);

CurrentSourceLanguage = MapDWLangToCVLang(CU->getSourceLanguage());
CurrentSourceLanguage =
MapDWLangToCVLang(CU->getSourceLanguage().getUnversionedName());
if (!M->getCodeViewFlag() ||
CU->getEmissionKind() == DICompileUnit::NoDebug) {
Asm = nullptr;
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,8 @@ void DwarfDebug::finishUnitAttributes(const DICompileUnit *DIUnit,
NewCU.addString(Die, dwarf::DW_AT_producer, Producer);

NewCU.addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
DIUnit->getSourceLanguage());
DIUnit->getSourceLanguage().getUnversionedName());

NewCU.addString(Die, dwarf::DW_AT_name, FN);
StringRef SysRoot = DIUnit->getSysRoot();
if (!SysRoot.empty())
Expand Down Expand Up @@ -2930,10 +2931,9 @@ static dwarf::PubIndexEntryDescriptor computeIndexValue(DwarfUnit *CU,
case dwarf::DW_TAG_union_type:
case dwarf::DW_TAG_enumeration_type:
return dwarf::PubIndexEntryDescriptor(
dwarf::GIEK_TYPE,
dwarf::isCPlusPlus((dwarf::SourceLanguage)CU->getLanguage())
? dwarf::GIEL_EXTERNAL
: dwarf::GIEL_STATIC);
dwarf::GIEK_TYPE, dwarf::isCPlusPlus(CU->getSourceLanguage())
? dwarf::GIEL_EXTERNAL
: dwarf::GIEL_STATIC);
case dwarf::DW_TAG_typedef:
case dwarf::DW_TAG_base_type:
case dwarf::DW_TAG_subrange_type:
Expand Down Expand Up @@ -3926,7 +3926,7 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
TypeUnitsUnderConstruction.emplace_back(std::move(OwnedUnit), CTy);

NewTU.addUInt(UnitDie, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
CU.getLanguage());
CU.getSourceLanguage());

uint64_t Signature = makeTypeSignature(Identifier);
NewTU.setTypeSignature(Signature);
Expand Down
16 changes: 10 additions & 6 deletions llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ DwarfUnit::~DwarfUnit() {
}

int64_t DwarfUnit::getDefaultLowerBound() const {
switch (getLanguage()) {
switch (getSourceLanguage()) {
default:
break;

Expand Down Expand Up @@ -704,12 +704,17 @@ void DwarfUnit::addType(DIE &Entity, const DIType *Ty,
addDIEEntry(Entity, Attribute, DIEEntry(*getOrCreateTypeDIE(Ty)));
}

llvm::dwarf::SourceLanguage DwarfUnit::getSourceLanguage() const {
return static_cast<llvm::dwarf::SourceLanguage>(
getLanguage().getUnversionedName());
}

std::string DwarfUnit::getParentContextString(const DIScope *Context) const {
if (!Context)
return "";

// FIXME: Decide whether to implement this for non-C++ languages.
if (!dwarf::isCPlusPlus((dwarf::SourceLanguage)getLanguage()))
if (!dwarf::isCPlusPlus(getSourceLanguage()))
return "";

std::string CS;
Expand Down Expand Up @@ -940,7 +945,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DISubroutineType *CTy) {

// Add prototype flag if we're dealing with a C language and the function has
// been prototyped.
if (isPrototyped && dwarf::isC((dwarf::SourceLanguage)getLanguage()))
if (isPrototyped && dwarf::isC(getSourceLanguage()))
addFlag(Buffer, dwarf::DW_AT_prototyped);

// Add a DW_AT_calling_convention if this has an explicit convention.
Expand Down Expand Up @@ -1448,7 +1453,7 @@ void DwarfUnit::applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie,

// Add the prototype if we have a prototype and we have a C like
// language.
if (SP->isPrototyped() && dwarf::isC((dwarf::SourceLanguage)getLanguage()))
if (SP->isPrototyped() && dwarf::isC(getSourceLanguage()))
addFlag(SPDie, dwarf::DW_AT_prototyped);

if (SP->isObjCDirect())
Expand Down Expand Up @@ -1700,8 +1705,7 @@ DIE *DwarfUnit::getIndexTyDie() {
addString(*IndexTyDie, dwarf::DW_AT_name, Name);
addUInt(*IndexTyDie, dwarf::DW_AT_byte_size, std::nullopt, sizeof(int64_t));
addUInt(*IndexTyDie, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
dwarf::getArrayIndexTypeEncoding(
(dwarf::SourceLanguage)getLanguage()));
dwarf::getArrayIndexTypeEncoding(getSourceLanguage()));
DD->addAccelType(*this, CUNode->getNameTableKind(), Name, *IndexTyDie,
/*Flags*/ 0);
return IndexTyDie;
Expand Down
7 changes: 6 additions & 1 deletion llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/Target/TargetMachine.h"
#include <optional>
#include <string>
Expand Down Expand Up @@ -107,7 +108,7 @@ class DwarfUnit : public DIEUnit {
return LabelBegin;
}
MCSymbol *getEndLabel() const { return EndLabel; }
uint16_t getLanguage() const { return CUNode->getSourceLanguage(); }
llvm::dwarf::SourceLanguage getSourceLanguage() const;
const DICompileUnit *getCUNode() const { return CUNode; }
DwarfDebug &getDwarfDebug() const { return *DD; }

Expand Down Expand Up @@ -358,6 +359,10 @@ class DwarfUnit : public DIEUnit {
}

private:
DISourceLanguageName getLanguage() const {
return CUNode->getSourceLanguage();
}

/// A helper to add a wide integer constant to a DIE using a block
/// form.
void addIntAsBlock(DIE &Die, dwarf::Attribute Attribute, const APInt &Val);
Expand Down
8 changes: 6 additions & 2 deletions llvm/lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2369,8 +2369,12 @@ static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N,
AsmWriterContext &WriterCtx) {
Out << "!DICompileUnit(";
MDFieldPrinter Printer(Out, WriterCtx);
Printer.printDwarfEnum("language", N->getSourceLanguage(),
dwarf::LanguageString, /* ShouldSkipZero */ false);

Printer.printDwarfEnum("language",
N->getSourceLanguage().getUnversionedName(),
dwarf::LanguageString,
/* ShouldSkipZero */ false);

Printer.printMetadata("file", N->getRawFile(), /* ShouldSkipNull */ false);
Printer.printString("producer", N->getProducer());
Printer.printBool("isOptimized", N->isOptimized());
Expand Down
Loading