From: Mehdi Amini Date: Sat, 1 Oct 2016 16:38:28 +0000 (+0000) Subject: Use StringRef for MemoryBuffer identifier API (NFC) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=793d2a4cedd0adc8a327ff15ff92711666d84c65;p=llvm Use StringRef for MemoryBuffer identifier API (NFC) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283043 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ExecutionEngine/ObjectMemoryBuffer.h b/include/llvm/ExecutionEngine/ObjectMemoryBuffer.h index b07561152ec..0f00ad006a7 100644 --- a/include/llvm/ExecutionEngine/ObjectMemoryBuffer.h +++ b/include/llvm/ExecutionEngine/ObjectMemoryBuffer.h @@ -49,7 +49,7 @@ public: init(this->SV.begin(), this->SV.end(), false); } - const char* getBufferIdentifier() const override { return BufferName.c_str(); } + StringRef getBufferIdentifier() const override { return BufferName; } BufferKind getBufferKind() const override { return MemoryBuffer_Malloc; } diff --git a/include/llvm/Support/MemoryBuffer.h b/include/llvm/Support/MemoryBuffer.h index 73d643537a6..70d91bdc26a 100644 --- a/include/llvm/Support/MemoryBuffer.h +++ b/include/llvm/Support/MemoryBuffer.h @@ -56,9 +56,7 @@ public: /// Return an identifier for this buffer, typically the filename it was read /// from. - virtual const char *getBufferIdentifier() const { - return "Unknown buffer"; - } + virtual StringRef getBufferIdentifier() const { return "Unknown buffer"; } /// Open the specified file as a MemoryBuffer, returning a new MemoryBuffer /// if successful, otherwise returning null. If FileSize is specified, this diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp index b935cbf1ae7..689343206c5 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/lib/Support/MemoryBuffer.cpp @@ -90,9 +90,9 @@ public: /// tail-allocated data. void operator delete(void *p) { ::operator delete(p); } - const char *getBufferIdentifier() const override { - // The name is stored after the class itself. - return reinterpret_cast(this + 1); + StringRef getBufferIdentifier() const override { + // The name is stored after the class itself. + return StringRef(reinterpret_cast(this + 1)); } BufferKind getBufferKind() const override { @@ -221,9 +221,9 @@ public: /// tail-allocated data. void operator delete(void *p) { ::operator delete(p); } - const char *getBufferIdentifier() const override { + StringRef getBufferIdentifier() const override { // The name is stored after the class itself. - return reinterpret_cast(this + 1); + return StringRef(reinterpret_cast(this + 1)); } BufferKind getBufferKind() const override { diff --git a/lib/Support/SourceMgr.cpp b/lib/Support/SourceMgr.cpp index b2f87d64845..4cb9b2ff2cd 100644 --- a/lib/Support/SourceMgr.cpp +++ b/lib/Support/SourceMgr.cpp @@ -142,7 +142,7 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind, // location to pull out the source line. SmallVector, 4> ColRanges; std::pair LineAndCol; - const char *BufferID = ""; + StringRef BufferID = ""; std::string LineStr; if (Loc.isValid()) { diff --git a/utils/TableGen/CTagsEmitter.cpp b/utils/TableGen/CTagsEmitter.cpp index 35f4ad6dd5b..5213cd90446 100644 --- a/utils/TableGen/CTagsEmitter.cpp +++ b/utils/TableGen/CTagsEmitter.cpp @@ -37,7 +37,7 @@ public: void emit(raw_ostream &OS) const { const MemoryBuffer *CurMB = SrcMgr.getMemoryBuffer(SrcMgr.FindBufferContainingLoc(Loc)); - const char *BufferName = CurMB->getBufferIdentifier(); + auto BufferName = CurMB->getBufferIdentifier(); std::pair LineAndColumn = SrcMgr.getLineAndColumn(Loc); OS << *Id << "\t" << BufferName << "\t" << LineAndColumn.first << "\n"; }