Skip to content

Commit 747b134

Browse files
committed
clang/Basic: Remove SourceManager::getBufferPointer, NFC
Inline `Source::getBufferPointer` into its only remaining caller, `getBufferOrNone`. No functionality change. Differential Revision: https://reviews.llvm.org/D89430
1 parent 96f372c commit 747b134

File tree

2 files changed

+8
-27
lines changed

2 files changed

+8
-27
lines changed

clang/include/clang/Basic/SourceManager.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,6 @@ namespace SrcMgr {
188188
getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
189189
SourceLocation Loc = SourceLocation()) const;
190190

191-
private:
192-
/// Returns pointer to memory buffer.
193-
///
194-
/// TODO: SourceManager needs access to this for now, but once that's done
195-
/// we should remove this API.
196-
const llvm::MemoryBuffer *getBufferPointer(DiagnosticsEngine &Diag,
197-
FileManager &FM,
198-
SourceLocation Loc) const;
199-
friend class clang::SourceManager;
200-
201-
public:
202191
/// Returns the size of the content encapsulated by this
203192
/// ContentCache.
204193
///

clang/lib/Basic/SourceManager.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,14 @@ const char *ContentCache::getInvalidBOM(StringRef BufStr) {
121121
llvm::Optional<llvm::MemoryBufferRef>
122122
ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
123123
SourceLocation Loc) const {
124-
if (auto *B = getBufferPointer(Diag, FM, Loc))
125-
return B->getMemBufferRef();
126-
return None;
127-
}
128-
129-
const llvm::MemoryBuffer *
130-
ContentCache::getBufferPointer(DiagnosticsEngine &Diag, FileManager &FM,
131-
SourceLocation Loc) const {
132124
// Lazily create the Buffer for ContentCaches that wrap files. If we already
133125
// computed it, just return what we have.
134126
if (isBufferInvalid())
135-
return nullptr;
127+
return None;
136128
if (auto *B = Buffer.getPointer())
137-
return B;
129+
return B->getMemBufferRef();
138130
if (!ContentsEntry)
139-
return nullptr;
131+
return None;
140132

141133
// Check that the file's size fits in an 'unsigned' (with room for a
142134
// past-the-end value). This is deeply regrettable, but various parts of
@@ -153,7 +145,7 @@ ContentCache::getBufferPointer(DiagnosticsEngine &Diag, FileManager &FM,
153145
<< ContentsEntry->getName();
154146

155147
Buffer.setInt(Buffer.getInt() | InvalidFlag);
156-
return nullptr;
148+
return None;
157149
}
158150

159151
auto BufferOrError = FM.getBufferForFile(ContentsEntry, IsFileVolatile);
@@ -173,7 +165,7 @@ ContentCache::getBufferPointer(DiagnosticsEngine &Diag, FileManager &FM,
173165
<< ContentsEntry->getName() << BufferOrError.getError().message();
174166

175167
Buffer.setInt(Buffer.getInt() | InvalidFlag);
176-
return nullptr;
168+
return None;
177169
}
178170

179171
Buffer.setPointer(BufferOrError->release());
@@ -189,7 +181,7 @@ ContentCache::getBufferPointer(DiagnosticsEngine &Diag, FileManager &FM,
189181
<< ContentsEntry->getName();
190182

191183
Buffer.setInt(Buffer.getInt() | InvalidFlag);
192-
return nullptr;
184+
return None;
193185
}
194186

195187
// If the buffer is valid, check to see if it has a UTF Byte Order Mark
@@ -202,10 +194,10 @@ ContentCache::getBufferPointer(DiagnosticsEngine &Diag, FileManager &FM,
202194
Diag.Report(Loc, diag::err_unsupported_bom)
203195
<< InvalidBOM << ContentsEntry->getName();
204196
Buffer.setInt(Buffer.getInt() | InvalidFlag);
205-
return nullptr;
197+
return None;
206198
}
207199

208-
return Buffer.getPointer();
200+
return Buffer.getPointer()->getMemBufferRef();
209201
}
210202

211203
unsigned LineTableInfo::getLineTableFilenameID(StringRef Name) {

0 commit comments

Comments
 (0)