From: Duncan P. N. Exon Smith Date: Fri, 13 Feb 2015 01:39:44 +0000 (+0000) Subject: AsmWriter/Bitcode: MDLocalVariable X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=a342d827bd3e42a82881d04e9b130792669bc1b0 AsmWriter/Bitcode: MDLocalVariable git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229022 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Bitcode/LLVMBitCodes.h b/include/llvm/Bitcode/LLVMBitCodes.h index 492d7c588b3..dff1c28591d 100644 --- a/include/llvm/Bitcode/LLVMBitCodes.h +++ b/include/llvm/Bitcode/LLVMBitCodes.h @@ -162,7 +162,8 @@ namespace bitc { METADATA_NAMESPACE = 24, // [distinct, scope, file, name, line] METADATA_TEMPLATE_TYPE = 25, // [distinct, scope, name, type, ...] METADATA_TEMPLATE_VALUE= 26, // [distinct, scope, name, type, value, ...] - METADATA_GLOBAL_VAR = 27 // [distinct, ...] + METADATA_GLOBAL_VAR = 27, // [distinct, ...] + METADATA_LOCAL_VAR = 28 // [distinct, ...] }; // The constants block (CONSTANTS_BLOCK_ID) describes emission for each diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 9c557258a4a..48dbaeeb76a 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -3575,9 +3575,30 @@ bool LLParser::ParseMDGlobalVariable(MDNode *&Result, bool IsDistinct) { return false; } +/// ParseMDLocalVariable: +/// ::= !MDLocalVariable(tag: DW_TAG_arg_variable, scope: !0, name: "foo", +/// file: !1, line: 7, type: !2, arg: 2, flags: 7, +/// inlinedAt: !3) bool LLParser::ParseMDLocalVariable(MDNode *&Result, bool IsDistinct) { - return TokError("unimplemented parser"); +#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ + REQUIRED(tag, DwarfTagField, ); \ + OPTIONAL(scope, MDField, ); \ + OPTIONAL(name, MDStringField, ); \ + OPTIONAL(file, MDField, ); \ + OPTIONAL(line, LineField, ); \ + OPTIONAL(type, MDField, ); \ + OPTIONAL(arg, MDUnsignedField, (0, UINT8_MAX)); \ + OPTIONAL(flags, MDUnsignedField, (0, UINT32_MAX)); \ + OPTIONAL(inlinedAt, MDField, ); + PARSE_MD_FIELDS(); +#undef VISIT_MD_FIELDS + + Result = GET_OR_DISTINCT( + MDLocalVariable, (Context, tag.Val, scope.Val, name.Val, file.Val, + line.Val, type.Val, arg.Val, flags.Val, inlinedAt.Val)); + return false; } + bool LLParser::ParseMDExpression(MDNode *&Result, bool IsDistinct) { return TokError("unimplemented parser"); } diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 56855ebb81b..5dee2f90677 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1539,6 +1539,19 @@ std::error_code BitcodeReader::ParseMetadata() { NextMDValueNo++); break; } + case bitc::METADATA_LOCAL_VAR: { + if (Record.size() != 10) + return Error("Invalid record"); + + MDValueList.AssignValue( + GET_OR_DISTINCT(MDLocalVariable, Record[0], + (Context, Record[1], getMDOrNull(Record[2]), + getMDString(Record[3]), getMDOrNull(Record[4]), + Record[5], getMDOrNull(Record[6]), Record[7], + Record[8], getMDOrNull(Record[9]))), + NextMDValueNo++); + break; + } case bitc::METADATA_STRING: { std::string String(Record.begin(), Record.end()); llvm::UpgradeMDStringConstant(String); diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index a86e26cc362..9feb4ffda7f 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1072,11 +1072,26 @@ static void WriteMDGlobalVariable(const MDGlobalVariable *N, Record.clear(); } -static void WriteMDLocalVariable(const MDLocalVariable *, - const ValueEnumerator &, BitstreamWriter &, - SmallVectorImpl &, unsigned) { - llvm_unreachable("write not implemented"); +static void WriteMDLocalVariable(const MDLocalVariable *N, + const ValueEnumerator &VE, + BitstreamWriter &Stream, + SmallVectorImpl &Record, + unsigned Abbrev) { + Record.push_back(N->isDistinct()); + Record.push_back(N->getTag()); + Record.push_back(VE.getMetadataOrNullID(N->getScope())); + Record.push_back(VE.getMetadataOrNullID(N->getRawName())); + Record.push_back(VE.getMetadataOrNullID(N->getFile())); + Record.push_back(N->getLine()); + Record.push_back(VE.getMetadataOrNullID(N->getType())); + Record.push_back(N->getArg()); + Record.push_back(N->getFlags()); + Record.push_back(VE.getMetadataOrNullID(N->getInlinedAt())); + + Stream.EmitRecord(bitc::METADATA_LOCAL_VAR, Record, Abbrev); + Record.clear(); } + static void WriteMDExpression(const MDExpression *, const ValueEnumerator &, BitstreamWriter &, SmallVectorImpl &, unsigned) { diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index b00d52ca744..ae9a50c94da 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -1748,11 +1748,39 @@ static void writeMDGlobalVariable(raw_ostream &Out, const MDGlobalVariable *N, Out << ")"; } -static void writeMDLocalVariable(raw_ostream &, const MDLocalVariable *, - TypePrinting *, SlotTracker *, - const Module *) { - llvm_unreachable("write not implemented"); +static void writeMDLocalVariable(raw_ostream &Out, const MDLocalVariable *N, + TypePrinting *TypePrinter, + SlotTracker *Machine, const Module *Context) { + Out << "!MDLocalVariable("; + FieldSeparator FS; + writeTag(Out, FS, N); + Out << FS << "scope: "; + writeMetadataAsOperand(Out, N->getScope(), TypePrinter, Machine, Context); + Out << FS << "name: \"" << N->getName() << "\""; + if (N->getFile()) { + Out << FS << "file: "; + writeMetadataAsOperand(Out, N->getFile(), TypePrinter, Machine, + Context); + } + if (N->getLine()) + Out << FS << "line: " << N->getLine(); + if (N->getType()) { + Out << FS << "type: "; + writeMetadataAsOperand(Out, N->getType(), TypePrinter, Machine, + Context); + } + if (N->getTag() == dwarf::DW_TAG_arg_variable || N->getArg()) + Out << FS << "arg: " << N->getArg(); + if (N->getFlags()) + Out << FS << "flags: " << N->getFlags(); + if (N->getInlinedAt()) { + Out << FS << "inlinedAt: "; + writeMetadataAsOperand(Out, N->getInlinedAt(), TypePrinter, Machine, + Context); + } + Out << ")"; } + static void writeMDExpression(raw_ostream &, const MDExpression *, TypePrinting *, SlotTracker *, const Module *) { llvm_unreachable("write not implemented"); diff --git a/lib/IR/DebugInfoMetadata.cpp b/lib/IR/DebugInfoMetadata.cpp index 46ac98a7d0c..3d6ebbce1b4 100644 --- a/lib/IR/DebugInfoMetadata.cpp +++ b/lib/IR/DebugInfoMetadata.cpp @@ -336,6 +336,12 @@ MDLocalVariable *MDLocalVariable::getImpl( LLVMContext &Context, unsigned Tag, Metadata *Scope, MDString *Name, Metadata *File, unsigned Line, Metadata *Type, unsigned Arg, unsigned Flags, Metadata *InlinedAt, StorageType Storage, bool ShouldCreate) { + // Truncate Arg to 8 bits. + // + // FIXME: This is gross (and should be changed to an assert or removed), but + // it matches historical behaviour for now. + Arg &= (1u << 8) - 1; + assert(isCanonical(Name) && "Expected canonical MDString"); DEFINE_GETIMPL_LOOKUP(MDLocalVariable, (Tag, Scope, getString(Name), File, Line, Type, Arg, Flags, InlinedAt)); diff --git a/test/Assembler/invalid-mdlocalvariable-missing-name.ll b/test/Assembler/invalid-mdlocalvariable-missing-name.ll new file mode 100644 index 00000000000..5b23600a0e4 --- /dev/null +++ b/test/Assembler/invalid-mdlocalvariable-missing-name.ll @@ -0,0 +1,4 @@ +; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s + +; CHECK: :[[@LINE+1]]:29: error: missing required field 'tag' +!0 = !MDLocalVariable(arg: 7) diff --git a/test/Assembler/mdlocalvariable.ll b/test/Assembler/mdlocalvariable.ll new file mode 100644 index 00000000000..6a7e530175d --- /dev/null +++ b/test/Assembler/mdlocalvariable.ll @@ -0,0 +1,26 @@ +; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s +; RUN: verify-uselistorder %s + +@foo = global i32 0 + +; CHECK: !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} +!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} + +!0 = distinct !{} +!1 = !{!"path/to/file", !"/path/to/dir"} +!2 = !MDFile(filename: "path/to/file", directory: "/path/to/dir") +!3 = distinct !{} +!4 = distinct !{} + +; CHECK: !5 = !MDLocalVariable(tag: DW_TAG_arg_variable, scope: !0, name: "foo", file: !1, line: 7, type: !3, arg: 3, flags: 8, inlinedAt: !4) +; CHECK: !6 = !MDLocalVariable(tag: DW_TAG_auto_variable, scope: !0, name: "foo", file: !1, line: 7, type: !3, flags: 8, inlinedAt: !4) +!5 = !MDLocalVariable(tag: DW_TAG_arg_variable, scope: !0, name: "foo", + file: !1, line: 7, type: !3, arg: 3, + flags: 8, inlinedAt: !4) +!6 = !MDLocalVariable(tag: DW_TAG_auto_variable, scope: !0, name: "foo", + file: !1, line: 7, type: !3, flags: 8, inlinedAt: !4) + +; CHECK: !7 = !MDLocalVariable(tag: DW_TAG_arg_variable, scope: null, name: "", arg: 0) +; CHECK: !8 = !MDLocalVariable(tag: DW_TAG_auto_variable, scope: null, name: "") +!7 = !MDLocalVariable(tag: DW_TAG_arg_variable) +!8 = !MDLocalVariable(tag: DW_TAG_auto_variable)