@@ -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