Skip to content

Commit 3d6c0d7

Browse files
authored
Merge branch 'main' into reland-clang-movt-movw-addend-check
2 parents d6a8927 + 1dfdbf7 commit 3d6c0d7

File tree

94 files changed

+2548
-772
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+2548
-772
lines changed

clang/include/clang/Basic/FileManager.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ class FileManager : public RefCountedBase<FileManager> {
124124
std::unique_ptr<FileSystemStatCache> StatCache;
125125

126126
std::error_code getStatValue(StringRef Path, llvm::vfs::Status &Status,
127-
bool isFile,
128-
std::unique_ptr<llvm::vfs::File> *F);
127+
bool isFile, std::unique_ptr<llvm::vfs::File> *F,
128+
bool IsText = true);
129129

130130
/// Add all ancestors of the given path (pointing to either a file
131131
/// or a directory) as virtual directories.
@@ -230,7 +230,8 @@ class FileManager : public RefCountedBase<FileManager> {
230230
/// the failure to find this file.
231231
llvm::Expected<FileEntryRef> getFileRef(StringRef Filename,
232232
bool OpenFile = false,
233-
bool CacheFailure = true);
233+
bool CacheFailure = true,
234+
bool IsText = true);
234235

235236
/// Get the FileEntryRef for stdin, returning an error if stdin cannot be
236237
/// read.
@@ -290,23 +291,28 @@ class FileManager : public RefCountedBase<FileManager> {
290291

291292
/// Open the specified file as a MemoryBuffer, returning a new
292293
/// MemoryBuffer if successful, otherwise returning null.
294+
/// The IsText parameter controls whether the file should be opened as a text
295+
/// or binary file, and should be set to false if the file contents should be
296+
/// treated as binary.
293297
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
294298
getBufferForFile(FileEntryRef Entry, bool isVolatile = false,
295299
bool RequiresNullTerminator = true,
296-
std::optional<int64_t> MaybeLimit = std::nullopt);
300+
std::optional<int64_t> MaybeLimit = std::nullopt,
301+
bool IsText = true);
297302
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
298303
getBufferForFile(StringRef Filename, bool isVolatile = false,
299304
bool RequiresNullTerminator = true,
300-
std::optional<int64_t> MaybeLimit = std::nullopt) const {
305+
std::optional<int64_t> MaybeLimit = std::nullopt,
306+
bool IsText = true) const {
301307
return getBufferForFileImpl(Filename,
302308
/*FileSize=*/MaybeLimit.value_or(-1),
303-
isVolatile, RequiresNullTerminator);
309+
isVolatile, RequiresNullTerminator, IsText);
304310
}
305311

306312
private:
307313
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
308314
getBufferForFileImpl(StringRef Filename, int64_t FileSize, bool isVolatile,
309-
bool RequiresNullTerminator) const;
315+
bool RequiresNullTerminator, bool IsText) const;
310316

311317
DirectoryEntry *&getRealDirEntry(const llvm::vfs::Status &Status);
312318

clang/include/clang/Basic/FileSystemStatCache.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class FileSystemStatCache {
4848
/// success for directories (not files). On a successful file lookup, the
4949
/// implementation can optionally fill in \p F with a valid \p File object and
5050
/// the client guarantees that it will close it.
51-
static std::error_code
52-
get(StringRef Path, llvm::vfs::Status &Status, bool isFile,
53-
std::unique_ptr<llvm::vfs::File> *F,
54-
FileSystemStatCache *Cache, llvm::vfs::FileSystem &FS);
51+
static std::error_code get(StringRef Path, llvm::vfs::Status &Status,
52+
bool isFile, std::unique_ptr<llvm::vfs::File> *F,
53+
FileSystemStatCache *Cache,
54+
llvm::vfs::FileSystem &FS, bool IsText = true);
5555

5656
protected:
5757
// FIXME: The pointer here is a non-owning/optional reference to the

clang/include/clang/Basic/TargetInfo.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ enum class FloatModeKind {
8787
struct TransferrableTargetInfo {
8888
unsigned char PointerWidth, PointerAlign;
8989
unsigned char BoolWidth, BoolAlign;
90+
unsigned char ShortWidth, ShortAlign;
9091
unsigned char IntWidth, IntAlign;
9192
unsigned char HalfWidth, HalfAlign;
9293
unsigned char BFloat16Width, BFloat16Align;
@@ -497,13 +498,10 @@ class TargetInfo : public TransferrableTargetInfo,
497498
unsigned getCharWidth() const { return 8; } // FIXME
498499
unsigned getCharAlign() const { return 8; } // FIXME
499500

500-
/// Return the size of 'signed short' and 'unsigned short' for this
501-
/// target, in bits.
502-
unsigned getShortWidth() const { return 16; } // FIXME
503-
504-
/// Return the alignment of 'signed short' and 'unsigned short' for
505-
/// this target.
506-
unsigned getShortAlign() const { return 16; } // FIXME
501+
/// getShortWidth/Align - Return the size of 'signed short' and
502+
/// 'unsigned short' for this target, in bits.
503+
unsigned getShortWidth() const { return ShortWidth; }
504+
unsigned getShortAlign() const { return ShortAlign; }
507505

508506
/// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
509507
/// this target, in bits.

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6097,7 +6097,8 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
60976097

60986098
if (VD->evaluateValue())
60996099
return revisit(VD);
6100-
return this->emitInvalidDeclRef(cast<DeclRefExpr>(E), E);
6100+
return this->emitInvalidDeclRef(cast<DeclRefExpr>(E),
6101+
/*InitializerFailed=*/true, E);
61016102
}
61026103
}
61036104
} else {
@@ -6123,7 +6124,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
61236124
}
61246125

61256126
if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
6126-
return this->emitInvalidDeclRef(DRE, E);
6127+
return this->emitInvalidDeclRef(DRE, /*InitializerFailed=*/false, E);
61276128
return false;
61286129
}
61296130

clang/lib/AST/ByteCode/Interp.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,9 +2818,18 @@ inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind,
28182818
return false;
28192819
}
28202820

2821-
inline bool InvalidDeclRef(InterpState &S, CodePtr OpPC,
2822-
const DeclRefExpr *DR) {
2821+
inline bool InvalidDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR,
2822+
bool InitializerFailed) {
28232823
assert(DR);
2824+
2825+
if (InitializerFailed) {
2826+
const SourceInfo &Loc = S.Current->getSource(OpPC);
2827+
const auto *VD = cast<VarDecl>(DR->getDecl());
2828+
S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;
2829+
S.Note(VD->getLocation(), diag::note_declared_at);
2830+
return false;
2831+
}
2832+
28242833
return CheckDeclRef(S, OpPC, DR);
28252834
}
28262835

clang/lib/AST/ByteCode/Opcodes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ def InvalidCast : Opcode {
769769
}
770770

771771
def InvalidDeclRef : Opcode {
772-
let Args = [ArgDeclRef];
772+
let Args = [ArgDeclRef, ArgBool];
773773
}
774774

775775
def SizelessVectorElementSize : Opcode;

clang/lib/Basic/FileManager.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,10 @@ FileManager::getFile(StringRef Filename, bool openFile, bool CacheFailure) {
212212
return llvm::errorToErrorCode(Result.takeError());
213213
}
214214

215-
llvm::Expected<FileEntryRef>
216-
FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) {
215+
llvm::Expected<FileEntryRef> FileManager::getFileRef(StringRef Filename,
216+
bool openFile,
217+
bool CacheFailure,
218+
bool IsText) {
217219
++NumFileLookups;
218220

219221
// See if there is already an entry in the map.
@@ -259,7 +261,7 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) {
259261
std::unique_ptr<llvm::vfs::File> F;
260262
llvm::vfs::Status Status;
261263
auto statError = getStatValue(InterndFileName, Status, true,
262-
openFile ? &F : nullptr);
264+
openFile ? &F : nullptr, IsText);
263265
if (statError) {
264266
// There's no real file at the given path.
265267
if (CacheFailure)
@@ -531,7 +533,7 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) {
531533
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
532534
FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile,
533535
bool RequiresNullTerminator,
534-
std::optional<int64_t> MaybeLimit) {
536+
std::optional<int64_t> MaybeLimit, bool IsText) {
535537
const FileEntry *Entry = &FE.getFileEntry();
536538
// If the content is living on the file entry, return a reference to it.
537539
if (Entry->Content)
@@ -558,42 +560,44 @@ FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile,
558560

559561
// Otherwise, open the file.
560562
return getBufferForFileImpl(Filename, FileSize, isVolatile,
561-
RequiresNullTerminator);
563+
RequiresNullTerminator, IsText);
562564
}
563565

564566
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
565567
FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize,
566-
bool isVolatile,
567-
bool RequiresNullTerminator) const {
568+
bool isVolatile, bool RequiresNullTerminator,
569+
bool IsText) const {
568570
if (FileSystemOpts.WorkingDir.empty())
569571
return FS->getBufferForFile(Filename, FileSize, RequiresNullTerminator,
570-
isVolatile);
572+
isVolatile, IsText);
571573

572574
SmallString<128> FilePath(Filename);
573575
FixupRelativePath(FilePath);
574576
return FS->getBufferForFile(FilePath, FileSize, RequiresNullTerminator,
575-
isVolatile);
577+
isVolatile, IsText);
576578
}
577579

578580
/// getStatValue - Get the 'stat' information for the specified path,
579581
/// using the cache to accelerate it if possible. This returns true
580582
/// if the path points to a virtual file or does not exist, or returns
581583
/// false if it's an existent real file. If FileDescriptor is NULL,
582584
/// do directory look-up instead of file look-up.
583-
std::error_code
584-
FileManager::getStatValue(StringRef Path, llvm::vfs::Status &Status,
585-
bool isFile, std::unique_ptr<llvm::vfs::File> *F) {
585+
std::error_code FileManager::getStatValue(StringRef Path,
586+
llvm::vfs::Status &Status,
587+
bool isFile,
588+
std::unique_ptr<llvm::vfs::File> *F,
589+
bool IsText) {
586590
// FIXME: FileSystemOpts shouldn't be passed in here, all paths should be
587591
// absolute!
588592
if (FileSystemOpts.WorkingDir.empty())
589-
return FileSystemStatCache::get(Path, Status, isFile, F,
590-
StatCache.get(), *FS);
593+
return FileSystemStatCache::get(Path, Status, isFile, F, StatCache.get(),
594+
*FS, IsText);
591595

592596
SmallString<128> FilePath(Path);
593597
FixupRelativePath(FilePath);
594598

595599
return FileSystemStatCache::get(FilePath.c_str(), Status, isFile, F,
596-
StatCache.get(), *FS);
600+
StatCache.get(), *FS, IsText);
597601
}
598602

599603
std::error_code

clang/lib/Basic/FileSystemStatCache.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ void FileSystemStatCache::anchor() {}
3030
/// success for directories (not files). On a successful file lookup, the
3131
/// implementation can optionally fill in FileDescriptor with a valid
3232
/// descriptor and the client guarantees that it will close it.
33-
std::error_code
34-
FileSystemStatCache::get(StringRef Path, llvm::vfs::Status &Status,
35-
bool isFile, std::unique_ptr<llvm::vfs::File> *F,
36-
FileSystemStatCache *Cache,
37-
llvm::vfs::FileSystem &FS) {
33+
std::error_code FileSystemStatCache::get(StringRef Path,
34+
llvm::vfs::Status &Status, bool isFile,
35+
std::unique_ptr<llvm::vfs::File> *F,
36+
FileSystemStatCache *Cache,
37+
llvm::vfs::FileSystem &FS,
38+
bool IsText) {
3839
bool isForDir = !isFile;
3940
std::error_code RetCode;
4041

@@ -58,7 +59,8 @@ FileSystemStatCache::get(StringRef Path, llvm::vfs::Status &Status,
5859
//
5960
// Because of this, check to see if the file exists with 'open'. If the
6061
// open succeeds, use fstat to get the stat info.
61-
auto OwnedFile = FS.openFileForRead(Path);
62+
auto OwnedFile =
63+
IsText ? FS.openFileForRead(Path) : FS.openFileForReadBinary(Path);
6264

6365
if (!OwnedFile) {
6466
// If the open fails, our "stat" fails.

clang/lib/Basic/TargetInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
7070
HasStrictFP = false;
7171
PointerWidth = PointerAlign = 32;
7272
BoolWidth = BoolAlign = 8;
73+
ShortWidth = ShortAlign = 16;
7374
IntWidth = IntAlign = 32;
7475
LongWidth = LongAlign = 32;
7576
LongLongWidth = LongLongAlign = 64;
@@ -437,6 +438,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
437438
// what these normally are for the target.
438439
// We also define long long and long double here, although the
439440
// OpenCL standard only mentions these as "reserved".
441+
ShortWidth = ShortAlign = 16;
440442
IntWidth = IntAlign = 32;
441443
LongWidth = LongAlign = 64;
442444
LongLongWidth = LongLongAlign = 128;

clang/lib/Basic/Targets/AVR.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
2929
TLSSupported = false;
3030
PointerWidth = 16;
3131
PointerAlign = 8;
32+
ShortWidth = 16;
33+
ShortAlign = 8;
3234
IntWidth = 16;
3335
IntAlign = 8;
3436
LongWidth = 32;
@@ -65,6 +67,8 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
6567
return std::nullopt;
6668
}
6769

70+
bool allowsLargerPreferedTypeAlignment() const override { return false; }
71+
6872
BuiltinVaListKind getBuiltinVaListKind() const override {
6973
return TargetInfo::VoidPtrBuiltinVaList;
7074
}

0 commit comments

Comments
 (0)