Skip to content

Commit d7798e2

Browse files
committed
remove #ifdefs
1 parent 4583cac commit d7798e2

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

clang/include/clang/Basic/FileEntry.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ class FileEntryRef {
7070
const FileEntry &getFileEntry() const {
7171
return *getBaseMapEntry().second->V.get<FileEntry *>();
7272
}
73-
#ifdef __MVS__
74-
FileEntry &getFileEntry() {
73+
74+
// This is a non const version of getFileEntry() which is used if the buffer
75+
// size needs to be increased due to potential z/OS EBCDIC -> UTF-8 conversion
76+
FileEntry &getFileEntryToUpdate() {
7577
return *getBaseMapEntry().second->V.get<FileEntry *>();
7678
}
77-
#endif
79+
7880
DirectoryEntryRef getDir() const { return ME->second->Dir; }
7981

8082
inline off_t getSize() const;
@@ -328,10 +330,8 @@ class FileEntry {
328330

329331
StringRef tryGetRealPathName() const { return RealPathName; }
330332
off_t getSize() const { return Size; }
331-
#ifdef __MVS__
332333
// Size may increase due to potential z/OS EBCDIC -> UTF-8 conversion.
333334
void setSize(off_t NewSize) { Size = NewSize; }
334-
#endif
335335
unsigned getUID() const { return UID; }
336336
const llvm::sys::fs::UniqueID &getUniqueID() const { return UniqueID; }
337337
time_t getModificationTime() const { return ModTime; }

clang/lib/Basic/SourceManager.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,13 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
157157
// Unless this is a named pipe (in which case we can handle a mismatch),
158158
// check that the file's size is the same as in the file entry (which may
159159
// have come from a stat cache).
160-
#ifndef __MVS__
161-
if (!ContentsEntry->isNamedPipe() &&
162-
Buffer->getBufferSize() != (size_t)ContentsEntry->getSize()) {
163-
#else
164160
// The buffer will always be larger than the file size on z/OS in the presence
165161
// of characters outside the base character set.
162+
assert(Buffer->getBufferSize() <= (size_t)ContentsEntry->getSize());
166163
if (!ContentsEntry->isNamedPipe() &&
167164
Buffer->getBufferSize() < (size_t)ContentsEntry->getSize()) {
168-
#endif
169165
Diag.Report(Loc, diag::err_file_modified) << ContentsEntry->getName();
166+
170167
return std::nullopt;
171168
}
172169

@@ -590,6 +587,18 @@ SourceManager::getOrCreateFileID(FileEntryRef SourceFile,
590587
FileCharacter);
591588
}
592589

590+
/// Helper function to determine if an input file requires conversion
591+
bool needConversion(StringRef Filename) {
592+
#ifdef __MVS__
593+
llvm::ErrorOr<bool> NeedConversion =
594+
llvm::needzOSConversion(Filename.str().c_str());
595+
assert(NeedConversion && "Filename was not found");
596+
return *NeedConversion;
597+
#else
598+
return false;
599+
#endif
600+
}
601+
593602
/// createFileID - Create a new FileID for the specified ContentCache and
594603
/// include position. This works regardless of whether the ContentCache
595604
/// corresponds to a file or some other input source.
@@ -609,23 +618,20 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename,
609618
return FileID::get(LoadedID);
610619
}
611620
unsigned FileSize = File.getSize();
612-
#ifdef __MVS__
613-
llvm::ErrorOr<bool> NeedConversion =
614-
llvm::needzOSConversion(Filename.str().c_str());
615-
if (NeedConversion && *NeedConversion) {
621+
bool NeedConversion = needConversion(Filename);
622+
if (NeedConversion) {
616623
// Buffer size may increase due to potential z/OS EBCDIC to UTF-8
617624
// conversion.
618625
if (std::optional<llvm::MemoryBufferRef> Buffer =
619626
File.getBufferOrNone(Diag, getFileManager())) {
620627
unsigned BufSize = Buffer->getBufferSize();
621628
if (BufSize > FileSize) {
622629
if (File.ContentsEntry.has_value())
623-
File.ContentsEntry->getFileEntry().setSize(BufSize);
630+
File.ContentsEntry->getFileEntryToUpdate().setSize(BufSize);
624631
FileSize = BufSize;
625632
}
626633
}
627634
}
628-
#endif
629635
if (!(NextLocalOffset + FileSize + 1 > NextLocalOffset &&
630636
NextLocalOffset + FileSize + 1 <= CurrentLoadedOffset)) {
631637
Diag.Report(IncludePos, diag::err_sloc_space_too_large);

0 commit comments

Comments
 (0)