@@ -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,15 @@ SourceManager::getOrCreateFileID(FileEntryRef SourceFile,
590587 FileCharacter);
591588}
592589
590+ // / Helper function to determine if an input file requires conversion
591+ llvm::ErrorOr<bool > needConversion (StringRef Filename) {
592+ #ifdef __MVS__
593+ return llvm::needzOSConversion (Filename.str ().c_str ());
594+ #else
595+ return false ;
596+ #endif
597+ }
598+
593599// / createFileID - Create a new FileID for the specified ContentCache and
594600// / include position. This works regardless of whether the ContentCache
595601// / corresponds to a file or some other input source.
@@ -609,23 +615,21 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename,
609615 return FileID::get (LoadedID);
610616 }
611617 unsigned FileSize = File.getSize ();
612- #ifdef __MVS__
613- llvm::ErrorOr<bool > NeedConversion =
614- llvm::needzOSConversion (Filename.str ().c_str ());
615- if (NeedConversion && *NeedConversion) {
618+ llvm::ErrorOr<bool > NeedConversion = needConversion (Filename);
619+ assert (NeedConversion && " Filename was not found" );
620+ if (*NeedConversion) {
616621 // Buffer size may increase due to potential z/OS EBCDIC to UTF-8
617622 // conversion.
618623 if (std::optional<llvm::MemoryBufferRef> Buffer =
619624 File.getBufferOrNone (Diag, getFileManager ())) {
620625 unsigned BufSize = Buffer->getBufferSize ();
621626 if (BufSize > FileSize) {
622627 if (File.ContentsEntry .has_value ())
623- File.ContentsEntry ->getFileEntry ().setSize (BufSize);
628+ File.ContentsEntry ->getFileEntryToUpdate ().setSize (BufSize);
624629 FileSize = BufSize;
625630 }
626631 }
627632 }
628- #endif
629633 if (!(NextLocalOffset + FileSize + 1 > NextLocalOffset &&
630634 NextLocalOffset + FileSize + 1 <= CurrentLoadedOffset)) {
631635 Diag.Report (IncludePos, diag::err_sloc_space_too_large);
0 commit comments