@@ -157,16 +157,13 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
157
157
// Unless this is a named pipe (in which case we can handle a mismatch),
158
158
// check that the file's size is the same as in the file entry (which may
159
159
// have come from a stat cache).
160
- #ifndef __MVS__
161
- if (!ContentsEntry->isNamedPipe () &&
162
- Buffer->getBufferSize () != (size_t )ContentsEntry->getSize ()) {
163
- #else
164
160
// The buffer will always be larger than the file size on z/OS in the presence
165
161
// of characters outside the base character set.
162
+ assert (Buffer->getBufferSize () >= (size_t )ContentsEntry->getSize ());
166
163
if (!ContentsEntry->isNamedPipe () &&
167
164
Buffer->getBufferSize () < (size_t )ContentsEntry->getSize ()) {
168
- #endif
169
165
Diag.Report (Loc, diag::err_file_modified) << ContentsEntry->getName ();
166
+
170
167
return std::nullopt;
171
168
}
172
169
@@ -590,6 +587,18 @@ SourceManager::getOrCreateFileID(FileEntryRef SourceFile,
590
587
FileCharacter);
591
588
}
592
589
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
+
593
602
// / createFileID - Create a new FileID for the specified ContentCache and
594
603
// / include position. This works regardless of whether the ContentCache
595
604
// / corresponds to a file or some other input source.
@@ -609,23 +618,20 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename,
609
618
return FileID::get (LoadedID);
610
619
}
611
620
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) {
616
623
// Buffer size may increase due to potential z/OS EBCDIC to UTF-8
617
624
// conversion.
618
625
if (std::optional<llvm::MemoryBufferRef> Buffer =
619
626
File.getBufferOrNone (Diag, getFileManager ())) {
620
627
unsigned BufSize = Buffer->getBufferSize ();
621
628
if (BufSize > FileSize) {
622
629
if (File.ContentsEntry .has_value ())
623
- File.ContentsEntry ->getFileEntry ().setSize (BufSize);
630
+ File.ContentsEntry ->getFileEntryToUpdate ().setSize (BufSize);
624
631
FileSize = BufSize;
625
632
}
626
633
}
627
634
}
628
- #endif
629
635
if (!(NextLocalOffset + FileSize + 1 > NextLocalOffset &&
630
636
NextLocalOffset + FileSize + 1 <= CurrentLoadedOffset)) {
631
637
Diag.Report (IncludePos, diag::err_sloc_space_too_large);
0 commit comments