simon_tatham created this revision. simon_tatham added reviewers: rsmith, lebedev.ri, akyrtzi. Herald added subscribers: dexonsmith, hiraditya. simon_tatham requested review of this revision. Herald added projects: clang, LLVM. Herald added subscribers: llvm-commits, cfe-commits.
This is part of a patch series working towards the ability to make SourceLocation into a 64-bit type to handle larger translation units. !srcloc is generated in clang codegen, and pulled back out by llvm functions like AsmPrinter::emitInlineAsm that need to report errors in the inline asm. From there it goes to LLVMContext::emitError, is stored in DiagnosticInfoInlineAsm, and ends up back in clang, at BackendConsumer::InlineAsmDiagHandler(), which reconstitutes a true clang::SourceLocation from the integer cookie. Throughout this code path, it's now 64-bit rather than 32, which means that if SourceLocation is expanded to a 64-bit type, this error report won't lose half of the data. Patch originally by Mikhail Maltsev. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D105491 Files: clang/lib/CodeGen/CGStmt.cpp llvm/include/llvm/IR/DiagnosticInfo.h llvm/include/llvm/IR/LLVMContext.h llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp llvm/lib/CodeGen/MachineInstr.cpp llvm/lib/IR/LLVMContext.cpp
Index: llvm/lib/IR/LLVMContext.cpp =================================================================== --- llvm/lib/IR/LLVMContext.cpp +++ llvm/lib/IR/LLVMContext.cpp @@ -248,7 +248,7 @@ exit(1); } -void LLVMContext::emitError(unsigned LocCookie, const Twine &ErrorStr) { +void LLVMContext::emitError(uint64_t LocCookie, const Twine &ErrorStr) { diagnose(DiagnosticInfoInlineAsm(LocCookie, ErrorStr)); } Index: llvm/lib/CodeGen/MachineInstr.cpp =================================================================== --- llvm/lib/CodeGen/MachineInstr.cpp +++ llvm/lib/CodeGen/MachineInstr.cpp @@ -2083,7 +2083,7 @@ void MachineInstr::emitError(StringRef Msg) const { // Find the source location cookie. - unsigned LocCookie = 0; + uint64_t LocCookie = 0; const MDNode *LocMD = nullptr; for (unsigned i = getNumOperands(); i != 0; --i) { if (getOperand(i-1).isMetadata() && Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp +++ llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp @@ -130,7 +130,7 @@ static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI, MachineModuleInfo *MMI, AsmPrinter *AP, - unsigned LocCookie, raw_ostream &OS) { + uint64_t LocCookie, raw_ostream &OS) { // Switch to the inline assembly variant. OS << "\t.intel_syntax\n\t"; @@ -272,7 +272,7 @@ static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI, MachineModuleInfo *MMI, const MCAsmInfo *MAI, - AsmPrinter *AP, unsigned LocCookie, + AsmPrinter *AP, uint64_t LocCookie, raw_ostream &OS) { int CurVariant = -1; // The number of the {.|.|.} region we are in. const char *LastEmitted = AsmStr; // One past the last character emitted. @@ -483,7 +483,7 @@ // Get the !srcloc metadata node if we have it, and decode the loc cookie from // it. - unsigned LocCookie = 0; + uint64_t LocCookie = 0; const MDNode *LocMD = nullptr; for (unsigned i = MI->getNumOperands(); i != 0; --i) { if (MI->getOperand(i-1).isMetadata() && Index: llvm/include/llvm/IR/LLVMContext.h =================================================================== --- llvm/include/llvm/IR/LLVMContext.h +++ llvm/include/llvm/IR/LLVMContext.h @@ -290,7 +290,7 @@ /// be prepared to drop the erroneous construct on the floor and "not crash". /// The generated code need not be correct. The error message will be /// implicitly prefixed with "error: " and should not end with a ".". - void emitError(unsigned LocCookie, const Twine &ErrorStr); + void emitError(uint64_t LocCookie, const Twine &ErrorStr); void emitError(const Instruction *I, const Twine &ErrorStr); void emitError(const Twine &ErrorStr); Index: llvm/include/llvm/IR/DiagnosticInfo.h =================================================================== --- llvm/include/llvm/IR/DiagnosticInfo.h +++ llvm/include/llvm/IR/DiagnosticInfo.h @@ -131,7 +131,7 @@ class DiagnosticInfoInlineAsm : public DiagnosticInfo { private: /// Optional line information. 0 if not set. - unsigned LocCookie = 0; + uint64_t LocCookie = 0; /// Message to be reported. const Twine &MsgStr; /// Optional origin of the problem. @@ -149,7 +149,7 @@ /// \p MsgStr gives the message. /// This class does not copy \p MsgStr, therefore the reference must be valid /// for the whole life time of the Diagnostic. - DiagnosticInfoInlineAsm(unsigned LocCookie, const Twine &MsgStr, + DiagnosticInfoInlineAsm(uint64_t LocCookie, const Twine &MsgStr, DiagnosticSeverity Severity = DS_Error) : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(LocCookie), MsgStr(MsgStr) {} @@ -162,7 +162,7 @@ DiagnosticInfoInlineAsm(const Instruction &I, const Twine &MsgStr, DiagnosticSeverity Severity = DS_Error); - unsigned getLocCookie() const { return LocCookie; } + uint64_t getLocCookie() const { return LocCookie; } const Twine &getMsgStr() const { return MsgStr; } const Instruction *getInstruction() const { return Instr; } Index: clang/lib/CodeGen/CGStmt.cpp =================================================================== --- clang/lib/CodeGen/CGStmt.cpp +++ clang/lib/CodeGen/CGStmt.cpp @@ -2123,7 +2123,7 @@ SmallVector<llvm::Metadata *, 8> Locs; // Add the location of the first line to the MDNode. Locs.push_back(llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( - CGF.Int32Ty, Str->getBeginLoc().getRawEncoding()))); + CGF.Int64Ty, Str->getBeginLoc().getRawEncoding()))); StringRef StrVal = Str->getString(); if (!StrVal.empty()) { const SourceManager &SM = CGF.CGM.getContext().getSourceManager(); @@ -2138,7 +2138,7 @@ SourceLocation LineLoc = Str->getLocationOfByte( i + 1, SM, LangOpts, CGF.getTarget(), &StartToken, &ByteOffset); Locs.push_back(llvm::ConstantAsMetadata::get( - llvm::ConstantInt::get(CGF.Int32Ty, LineLoc.getRawEncoding()))); + llvm::ConstantInt::get(CGF.Int64Ty, LineLoc.getRawEncoding()))); } } @@ -2175,8 +2175,8 @@ getAsmSrcLocInfo(gccAsmStmt->getAsmString(), CGF)); else { // At least put the line number on MS inline asm blobs. - llvm::Constant *Loc = llvm::ConstantInt::get(CGF.Int32Ty, - S.getAsmLoc().getRawEncoding()); + llvm::Constant *Loc = + llvm::ConstantInt::get(CGF.Int64Ty, S.getAsmLoc().getRawEncoding()); Result.setMetadata("srcloc", llvm::MDNode::get(CGF.getLLVMContext(), llvm::ConstantAsMetadata::get(Loc)));
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits