diff --git a/llvm/include/llvm/IR/DIBuilder.h b/llvm/include/llvm/IR/DIBuilder.h --- a/llvm/include/llvm/IR/DIBuilder.h +++ b/llvm/include/llvm/IR/DIBuilder.h @@ -192,9 +192,9 @@ /// \param SizeInBits Size of the type. /// \param Encoding DWARF encoding code, e.g., dwarf::DW_ATE_float. /// \param Flags Optional DWARF attributes, e.g., DW_AT_endianity. - DIBasicType *createBasicType(StringRef Name, uint64_t SizeInBits, - unsigned Encoding, - DINode::DIFlags Flags = DINode::FlagZero); + DIBasicType * + createBasicType(StringRef Name, uint64_t SizeInBits, unsigned Encoding, + DIBasicType::DIBTFlags Flags = DIBasicType::BTFlagZero); /// Create debugging information entry for a qualified /// type, e.g. 'const int'. diff --git a/llvm/include/llvm/IR/DebugInfoFlags.def b/llvm/include/llvm/IR/DebugInfoFlags.def --- a/llvm/include/llvm/IR/DebugInfoFlags.def +++ b/llvm/include/llvm/IR/DebugInfoFlags.def @@ -10,7 +10,8 @@ // //===----------------------------------------------------------------------===// -#if !(defined HANDLE_DI_FLAG || defined HANDLE_DISP_FLAG) +#if !(defined HANDLE_DI_FLAG || defined HANDLE_DISP_FLAG || \ + defined HANDLE_DIBT_FLAG) #error "Missing macro definition of HANDLE_DI*" #endif @@ -22,6 +23,10 @@ #define HANDLE_DISP_FLAG(ID, NAME) #endif +#ifndef HANDLE_DIBT_FLAG +#define HANDLE_DIBT_FLAG(ID, NAME) +#endif + // General flags kept in DINode. HANDLE_DI_FLAG(0, Zero) // Use it as zero value. @@ -55,8 +60,6 @@ HANDLE_DI_FLAG((1 << 24), EnumClass) HANDLE_DI_FLAG((1 << 25), Thunk) HANDLE_DI_FLAG((1 << 26), NonTrivial) -HANDLE_DI_FLAG((1 << 27), BigEndian) -HANDLE_DI_FLAG((1 << 28), LittleEndian) HANDLE_DI_FLAG((1 << 29), AllCallsDescribed) // To avoid needing a dedicated value for IndirectVirtualBase, we use @@ -99,5 +102,21 @@ #undef DISP_FLAG_LARGEST_NEEDED #endif +// BasicType flags kept in DIBasicType + +// Use this as a zero/initialization value. +// For example: void foo(DIBTFlags Flags = BTFlagZero). +HANDLE_DIBT_FLAG(0, Zero) +HANDLE_DIBT_FLAG(1u, LittleEndian) +HANDLE_DIBT_FLAG(2u, BigEndian) + +#ifdef DIBT_FLAG_LARGEST_NEEDED +// Intended to be used with ADT/BitmaskEnum.h. +// NOTE: Always must be equal to largest flag, check this when adding new flags. +HANDLE_DIBT_FLAG(2u, Largest) +#undef DIBT_FLAG_LARGEST_NEEDED +#endif + #undef HANDLE_DI_FLAG #undef HANDLE_DISP_FLAG +#undef HANDLE_DIBT_FLAG diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h --- a/llvm/include/llvm/IR/DebugInfoMetadata.h +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h @@ -665,8 +665,6 @@ bool isTypePassByReference() const { return getFlags() & FlagTypePassByReference; } - bool isBigEndian() const { return getFlags() & FlagBigEndian; } - bool isLittleEndian() const { return getFlags() & FlagLittleEndian; } bool getExportSymbols() const { return getFlags() & FlagExportSymbols; } static bool classof(const Metadata *MD) { @@ -690,50 +688,79 @@ friend class LLVMContextImpl; friend class MDNode; +public: + /// Debug BasciType flags. + enum DIBTFlags : uint32_t { +#define HANDLE_DIBT_FLAG(ID, NAME) BTFlag##NAME = ID, +#define DIBT_FLAG_LARGEST_NEEDED +#include "llvm/IR/DebugInfoFlags.def" + LLVM_MARK_AS_BITMASK_ENUM(BTFlagLargest) + }; + + static DIBTFlags getFlag(StringRef Flag); + static StringRef getFlagString(DIBTFlags Flag); + + /// Split up a flags bitfield for easier printing. + /// + /// Split \c Flags into \c SplitFlags, a vector of its components. Returns + /// any remaining (unrecognized) bits. + static DIBTFlags splitFlags(DIBTFlags Flags, + SmallVectorImpl &SplitFlags); + + // Helper for converting old bitfields to new flags word. + static DIBTFlags toBTFlags(bool IsBigEndian, bool IsLittleEndian) { + return static_cast( + (IsBigEndian ? BTFlagBigEndian : BTFlagZero) | + (IsLittleEndian ? BTFlagLittleEndian : BTFlagZero)); + } + +private: + DIBTFlags BTFlags; unsigned Encoding; DIBasicType(LLVMContext &C, StorageType Storage, unsigned Tag, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, - DIFlags Flags, ArrayRef Ops) + DIBTFlags BTFlags, ArrayRef Ops) : DIType(C, DIBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0, - Flags, Ops), - Encoding(Encoding) {} + FlagZero, Ops), + BTFlags(BTFlags), Encoding(Encoding) {} ~DIBasicType() = default; static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, - DIFlags Flags, StorageType Storage, + DIBTFlags BTFlags, StorageType Storage, bool ShouldCreate = true) { return getImpl(Context, Tag, getCanonicalMDString(Context, Name), - SizeInBits, AlignInBits, Encoding, Flags, Storage, + SizeInBits, AlignInBits, Encoding, BTFlags, Storage, ShouldCreate); } + static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, - DIFlags Flags, StorageType Storage, + DIBTFlags BTFlags, StorageType Storage, bool ShouldCreate = true); TempDIBasicType cloneImpl() const { return getTemporary(getContext(), getTag(), getName(), getSizeInBits(), - getAlignInBits(), getEncoding(), getFlags()); + getAlignInBits(), getEncoding(), getBTFlags()); } public: DEFINE_MDNODE_GET(DIBasicType, (unsigned Tag, StringRef Name), - (Tag, Name, 0, 0, 0, FlagZero)) + (Tag, Name, 0, 0, 0, BTFlagZero)) DEFINE_MDNODE_GET(DIBasicType, (unsigned Tag, StringRef Name, uint64_t SizeInBits, - uint32_t AlignInBits, unsigned Encoding, DIFlags Flags), + uint32_t AlignInBits, unsigned Encoding, DIBTFlags Flags), (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags)) DEFINE_MDNODE_GET(DIBasicType, (unsigned Tag, MDString *Name, uint64_t SizeInBits, - uint32_t AlignInBits, unsigned Encoding, DIFlags Flags), + uint32_t AlignInBits, unsigned Encoding, DIBTFlags Flags), (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags)) TempDIBasicType clone() const { return cloneImpl(); } - + DIBTFlags getBTFlags() const { return BTFlags; } unsigned getEncoding() const { return Encoding; } enum class Signedness { Signed, Unsigned }; @@ -741,6 +768,8 @@ /// Return the signedness of this type, or None if this type is neither /// signed nor unsigned. Optional getSignedness() const; + bool isBigEndian() const { return getBTFlags() & BTFlagBigEndian; } + bool isLittleEndian() const { return getBTFlags() & BTFlagLittleEndian; } static bool classof(const Metadata *MD) { return MD->getMetadataID() == DIBasicTypeKind; diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp --- a/llvm/lib/AsmParser/LLLexer.cpp +++ b/llvm/lib/AsmParser/LLLexer.cpp @@ -928,6 +928,11 @@ return lltok::DISPFlag; } + if (Keyword.startswith("DIBTFlag")) { + StrVal.assign(Keyword.begin(), Keyword.end()); + return lltok::DIBTFlag; + } + if (Keyword.startswith("CSK_")) { StrVal.assign(Keyword.begin(), Keyword.end()); return lltok::ChecksumKind; diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -3867,6 +3867,10 @@ DISPFlagField() : MDFieldImpl(DISubprogram::SPFlagZero) {} }; +struct DIBTFlagField : public MDFieldImpl { + DIBTFlagField() : MDFieldImpl(DIBasicType::BTFlagZero) {} +}; + struct MDSignedField : public MDFieldImpl { int64_t Min; int64_t Max; @@ -4159,6 +4163,46 @@ return false; } +/// DIBTFlagField +/// ::= uint32 +/// ::= DIBTFlagBigEndian +/// ::= DIBTFlagBigEndian '|' DIBTFlag* '|' uint32 +template <> +bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DIBTFlagField &Result) { + + // Parser for a single flag. + auto parseFlag = [&](DIBasicType::DIBTFlags &Val) { + if (Lex.getKind() == lltok::APSInt && !Lex.getAPSIntVal().isSigned()) { + uint32_t TempVal = static_cast(Val); + bool Res = ParseUInt32(TempVal); + Val = static_cast(TempVal); + return Res; + } + + if (Lex.getKind() != lltok::DIBTFlag) + return TokError("expected debug info flag"); + + Val = DIBasicType::getFlag(Lex.getStrVal()); + if (!Val) + return TokError(Twine("invalid basicType debug info flag '") + + Lex.getStrVal() + "'"); + Lex.Lex(); + return false; + }; + + // Parse the flags and combine them together. + DIBasicType::DIBTFlags Combined = DIBasicType::BTFlagZero; + do { + DIBasicType::DIBTFlags Val; + if (parseFlag(Val)) + return true; + Combined |= Val; + } while (EatIfPresent(lltok::bar)); + + Result.assign(Combined); + return false; +} + /// DISPFlagField /// ::= uint32 /// ::= DISPFlagVector @@ -4487,9 +4531,8 @@ return false; } -/// ParseDIBasicType: /// ::= !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, -/// encoding: DW_ATE_encoding, flags: 0) +/// encoding: DW_ATE_encoding, btFlags: DIBTFlagBigEndian) bool LLParser::ParseDIBasicType(MDNode *&Result, bool IsDistinct) { #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_base_type)); \ @@ -4497,12 +4540,11 @@ OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \ OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \ OPTIONAL(encoding, DwarfAttEncodingField, ); \ - OPTIONAL(flags, DIFlagField, ); + OPTIONAL(btFlags, DIBTFlagField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS - Result = GET_OR_DISTINCT(DIBasicType, (Context, tag.Val, name.Val, size.Val, - align.Val, encoding.Val, flags.Val)); + align.Val, encoding.Val, btFlags.Val)); return false; } diff --git a/llvm/lib/AsmParser/LLToken.h b/llvm/lib/AsmParser/LLToken.h --- a/llvm/lib/AsmParser/LLToken.h +++ b/llvm/lib/AsmParser/LLToken.h @@ -462,6 +462,7 @@ DwarfOp, // DW_OP_foo DIFlag, // DIFlagFoo DISPFlag, // DISPFlagFoo + DIBTFlag, // DIBTFlagFoo DwarfMacinfo, // DW_MACINFO_foo ChecksumKind, // CSK_foo diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp --- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp +++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp @@ -1294,8 +1294,9 @@ return error("Invalid record"); IsDistinct = Record[0]; - DINode::DIFlags Flags = (Record.size() > 6) ? - static_cast(Record[6]) : DINode::FlagZero; + DIBasicType::DIBTFlags Flags = + (Record.size() > 6) ? static_cast(Record[6]) + : DIBasicType::BTFlagZero; MetadataList.assignValue( GET_OR_DISTINCT(DIBasicType, diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1546,7 +1546,7 @@ Record.push_back(N->getSizeInBits()); Record.push_back(N->getAlignInBits()); Record.push_back(N->getEncoding()); - Record.push_back(N->getFlags()); + Record.push_back(N->getBTFlags()); Stream.EmitRecord(bitc::METADATA_BASIC_TYPE, Record, Abbrev); Record.clear(); diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -1617,6 +1617,7 @@ void printBool(StringRef Name, bool Value, Optional Default = None); void printDIFlags(StringRef Name, DINode::DIFlags Flags); void printDISPFlags(StringRef Name, DISubprogram::DISPFlags Flags); + void printDIBTFlags(StringRef Name, DIBasicType::DIBTFlags Flags); template void printDwarfEnum(StringRef Name, IntTy Value, Stringifier toString, bool ShouldSkipZero = true); @@ -1715,6 +1716,26 @@ Out << FlagsFS << Extra; } +void MDFieldPrinter::printDIBTFlags(StringRef Name, + DIBasicType::DIBTFlags Flags) { + if (!Flags) { + return; + } + + Out << FS << Name << ": "; + SmallVector SplitFlags; + auto Extra = DIBasicType::splitFlags(Flags, SplitFlags); + + FieldSeparator FlagsFS(" | "); + for (auto F : SplitFlags) { + auto StringF = DIBasicType::getFlagString(F); + assert(!StringF.empty() && "Expected valid flag"); + Out << FlagsFS << StringF; + } + if (Extra || SplitFlags.empty()) + Out << FlagsFS << Extra; +} + void MDFieldPrinter::printDISPFlags(StringRef Name, DISubprogram::DISPFlags Flags) { // Always print this field, because no flags in the IR at all will be @@ -1839,7 +1860,7 @@ Printer.printInt("align", N->getAlignInBits()); Printer.printDwarfEnum("encoding", N->getEncoding(), dwarf::AttributeEncodingString); - Printer.printDIFlags("flags", N->getFlags()); + Printer.printDIBTFlags("btFlags", N->getBTFlags()); Out << ")"; } diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -260,7 +260,7 @@ DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits, unsigned Encoding, - DINode::DIFlags Flags) { + DIBasicType::DIBTFlags Flags) { assert(!Name.empty() && "Unable to create type without name"); return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits, 0, Encoding, Flags); diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -726,6 +726,11 @@ return static_cast(Flags); } +static DIBasicType::DIBTFlags pack_into_DIBTFlags(bool IsBigEndian, + bool IsLittleEndian) { + return DIBasicType::toBTFlags(IsBigEndian, IsLittleEndian); +} + static DISubprogram::DISPFlags pack_into_DISPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized) { return DISubprogram::toSPFlags(IsLocalToUnit, IsDefinition, IsOptimized); @@ -1018,9 +1023,10 @@ size_t NameLen, uint64_t SizeInBits, LLVMDWARFTypeEncoding Encoding, LLVMDIFlags Flags) { - return wrap(unwrap(Builder)->createBasicType({Name, NameLen}, - SizeInBits, Encoding, - map_from_llvmDIFlags(Flags))); + auto BTFlags = pack_into_DIBTFlags(Flags & LLVMDIFlagBigEndian, + Flags & LLVMDIFlagLittleEndian); + return wrap(unwrap(Builder)->createBasicType({Name, NameLen}, SizeInBits, + Encoding, BTFlags)); } LLVMMetadataRef LLVMDIBuilderCreatePointerType( diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -344,14 +344,46 @@ DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding, - DIFlags Flags, StorageType Storage, + DIBTFlags BTFlags, StorageType Storage, bool ShouldCreate) { assert(isCanonical(Name) && "Expected canonical MDString"); - DEFINE_GETIMPL_LOOKUP(DIBasicType, - (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags)); + DEFINE_GETIMPL_LOOKUP( + DIBasicType, (Tag, Name, SizeInBits, AlignInBits, Encoding, BTFlags)); Metadata *Ops[] = {nullptr, nullptr, Name}; - DEFINE_GETIMPL_STORE(DIBasicType, (Tag, SizeInBits, AlignInBits, Encoding, - Flags), Ops); + DEFINE_GETIMPL_STORE(DIBasicType, + (Tag, SizeInBits, AlignInBits, Encoding, BTFlags), Ops); +} + +DIBasicType::DIBTFlags DIBasicType::getFlag(StringRef Flag) { + return StringSwitch(Flag) +#define HANDLE_DIBT_FLAG(ID, NAME) .Case("DIBTFlag" #NAME, BTFlag##NAME) +#include "llvm/IR/DebugInfoFlags.def" + .Default(BTFlagZero); +} + +StringRef DIBasicType::getFlagString(DIBTFlags Flag) { + switch (Flag) { + // Appease a warning. +#define HANDLE_DIBT_FLAG(ID, NAME) \ + case BTFlag##NAME: \ + return "DIBTFlag" #NAME; +#include "llvm/IR/DebugInfoFlags.def" + } + return ""; +} + +DIBasicType::DIBTFlags +DIBasicType::splitFlags(DIBTFlags Flags, + SmallVectorImpl &SplitFlags) { + // Multi-bit fields can require special handling. In our case all its values + // happen to be single-bit values. +#define HANDLE_DIBT_FLAG(ID, NAME) \ + if (DIBTFlags Bit = Flags & BTFlag##NAME) { \ + SplitFlags.push_back(Bit); \ + Flags &= ~Bit; \ + } +#include "llvm/IR/DebugInfoFlags.def" + return Flags; } Optional DIBasicType::getSignedness() const { diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h --- a/llvm/lib/IR/LLVMContextImpl.h +++ b/llvm/lib/IR/LLVMContextImpl.h @@ -379,22 +379,22 @@ uint64_t SizeInBits; uint32_t AlignInBits; unsigned Encoding; - unsigned Flags; + unsigned BTFlags; MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits, - uint32_t AlignInBits, unsigned Encoding, unsigned Flags) + uint32_t AlignInBits, unsigned Encoding, unsigned BTFlags) : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits), - Encoding(Encoding), Flags(Flags) {} + Encoding(Encoding), BTFlags(BTFlags) {} MDNodeKeyImpl(const DIBasicType *N) : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()), - AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()), Flags(N->getFlags()) {} + AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()), + BTFlags(N->getBTFlags()) {} bool isKeyOf(const DIBasicType *RHS) const { return Tag == RHS->getTag() && Name == RHS->getRawName() && SizeInBits == RHS->getSizeInBits() && AlignInBits == RHS->getAlignInBits() && - Encoding == RHS->getEncoding() && - Flags == RHS->getFlags(); + Encoding == RHS->getEncoding() && BTFlags == RHS->getBTFlags(); } unsigned getHashValue() const { diff --git a/llvm/test/Assembler/debug-info.ll b/llvm/test/Assembler/debug-info.ll --- a/llvm/test/Assembler/debug-info.ll +++ b/llvm/test/Assembler/debug-info.ll @@ -95,7 +95,7 @@ !39 = !DIFile(filename: "file", directory: "dir", source: "int source() { }\0A") !40 = !DIFile(filename: "file", directory: "dir", checksumkind: CSK_MD5, checksum: "3a420e2646916a475e68de8d48f779f5", source: "int source() { }\0A") -; CHECK-NEXT: !38 = !DIBasicType(name: "u64.be", size: 64, align: 1, encoding: DW_ATE_unsigned, flags: DIFlagBigEndian) -; CHECK-NEXT: !39 = !DIBasicType(name: "u64.le", size: 64, align: 1, encoding: DW_ATE_unsigned, flags: DIFlagLittleEndian) -!41 = !DIBasicType(name: "u64.be", size: 64, align: 1, encoding: DW_ATE_unsigned, flags: DIFlagBigEndian) -!42 = !DIBasicType(name: "u64.le", size: 64, align: 1, encoding: DW_ATE_unsigned, flags: DIFlagLittleEndian) +; CHECK-NEXT: !38 = !DIBasicType(name: "u64.be", size: 64, align: 1, encoding: DW_ATE_unsigned, btFlags: DIBTFlagBigEndian) +; CHECK-NEXT: !39 = !DIBasicType(name: "u64.le", size: 64, align: 1, encoding: DW_ATE_unsigned, btFlags: DIBTFlagLittleEndian) +!41 = !DIBasicType(name: "u64.be", size: 64, align: 1, encoding: DW_ATE_unsigned, btFlags: DIBTFlagBigEndian) +!42 = !DIBasicType(name: "u64.le", size: 64, align: 1, encoding: DW_ATE_unsigned, btFlags: DIBTFlagLittleEndian) diff --git a/llvm/test/Bitcode/DIBasicType.ll b/llvm/test/Bitcode/DIBasicType.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Bitcode/DIBasicType.ll @@ -0,0 +1,34 @@ +; RUN: llvm-dis -o - %s.bc | FileCheck %s +; CHECK: = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 1, type: ![[#LETYPE:]], isLocal: false, isDefinition: true) +; CHECK: = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 1, type: ![[#BETYPE:]], isLocal: false, isDefinition: true) +; CHECK: ![[#BETYPE]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed, btFlags: DIBTFlagBigEndian) +; CHECK: ![[#LETYPE]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed, btFlags: DIBTFlagLittleEndian) + +@a = common dso_local global i32 0, align 4, !dbg !0 +@b = common dso_local global i32 0, align 4, !dbg !6 + +define dso_local void @main() !dbg !12 { +entry: + ret void, !dbg !15 +} + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!10, !11} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 1, type: !9, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None) +!3 = !DIFile(filename: "main.c", directory: "/dir") +!4 = !{} +!5 = !{!0, !6} +!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) +!7 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true) +!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed, btFlags: DIBTFlagBigEndian) +!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed, btFlags: DIBTFlagLittleEndian) +!10 = !{i32 7, !"Dwarf Version", i32 4} +!11 = !{i32 2, !"Debug Info Version", i32 3} +!12 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 2, type: !13, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4) +!13 = !DISubroutineType(types: !14) +!14 = !{null} +!15 = !DILocation(line: 2, column: 14, scope: !12) + diff --git a/llvm/test/Bitcode/DIBasicType.ll.bc b/llvm/test/Bitcode/DIBasicType.ll.bc new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@getTag()); EXPECT_EQ("special", N->getName()); EXPECT_EQ(33u, N->getSizeInBits()); @@ -1213,31 +1212,31 @@ EXPECT_EQ(0u, N->getLine()); EXPECT_EQ(DINode::FlagZero, N->getFlags()); EXPECT_EQ(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, - 26, 7, DINode::FlagZero)); + 26, 7, DIBasicType::BTFlagZero)); EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type, - "special", 33, 26, 7, DINode::FlagZero)); - EXPECT_NE(N, - DIBasicType::get(Context, dwarf::DW_TAG_base_type, "s", 33, 26, 7, - DINode::FlagZero)); + "special", 33, 26, 7, DIBasicType::BTFlagZero)); + EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "s", 33, 26, + 7, DIBasicType::BTFlagZero)); EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 32, - 26, 7, DINode::FlagZero)); + 26, 7, DIBasicType::BTFlagZero)); EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, - 25, 7, DINode::FlagZero)); + 25, 7, DIBasicType::BTFlagZero)); EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, - 26, 6, DINode::FlagZero)); + 26, 6, DIBasicType::BTFlagZero)); EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, - 26, 7, DINode::FlagBigEndian)); + 26, 7, DIBasicType::BTFlagBigEndian)); EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, - 26, 7, DINode::FlagLittleEndian)); + 26, 7, DIBasicType::BTFlagLittleEndian)); TempDIBasicType Temp = N->clone(); EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); } TEST_F(DIBasicTypeTest, getWithLargeValues) { - auto *N = DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", - UINT64_MAX, UINT32_MAX - 1, 7, DINode::FlagZero); + auto *N = + DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", UINT64_MAX, + UINT32_MAX - 1, 7, DIBasicType::BTFlagZero); EXPECT_EQ(UINT64_MAX, N->getSizeInBits()); EXPECT_EQ(UINT32_MAX - 1, N->getAlignInBits()); } @@ -1251,7 +1250,7 @@ EXPECT_EQ(0u, N->getAlignInBits()); EXPECT_EQ(0u, N->getEncoding()); EXPECT_EQ(0u, N->getLine()); - EXPECT_EQ(DINode::FlagZero, N->getFlags()); + EXPECT_EQ(DIBasicType::BTFlagZero, N->getFlags()); } typedef MetadataTest DITypeTest; @@ -1259,7 +1258,7 @@ TEST_F(DITypeTest, clone) { // Check that DIType has a specialized clone that returns TempDIType. DIType *N = DIBasicType::get(Context, dwarf::DW_TAG_base_type, "int", 32, 32, - dwarf::DW_ATE_signed, DINode::FlagZero); + dwarf::DW_ATE_signed, DIBasicType::BTFlagZero); TempDIType Temp = N->clone(); EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));