Skip to content

Commit 88fffad

Browse files
author
Jenkins
committed
merge main into amd-stg-open
Change-Id: Id69edef44c1f1fb3eefe9a71413a00c831ba10ee
2 parents 72a126e + 5862ed2 commit 88fffad

File tree

54 files changed

+3191
-286
lines changed

Some content is hidden

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

54 files changed

+3191
-286
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ contribute, and we appreciate all contributions.
55

66
To get started with contributing, please take a look at the
77
[Contributing to LLVM](https://llvm.org/docs/Contributing.html) guide. It
8-
describes how to get involved, raise issues and submit patches. Please note
9-
that at the moment the LLVM project does not use GitHub pull requests.
8+
describes how to get involved, raise issues and submit patches.
109

1110
## Getting in touch
1211

clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ bool NonZeroEnumToBoolConversionCheck::isLanguageVersionSupported(
4949
}
5050

5151
void NonZeroEnumToBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
52+
// Excluding bitwise operators (binary and overload) to avoid false-positives
53+
// in code like this 'if (e & SUCCESS) {'.
54+
auto ExcludedOperators = binaryOperation(hasAnyOperatorName(
55+
"|", "&", "^", "<<", ">>", "~", "|=", "&=", "^=", "<<=", ">>="));
56+
5257
Finder->addMatcher(
5358
castExpr(hasCastKind(CK_IntegralToBoolean),
5459
unless(isExpansionInSystemHeader()), hasType(booleanType()),
@@ -58,7 +63,8 @@ void NonZeroEnumToBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
5863
unless(matchers::matchesAnyListedName(
5964
EnumIgnoreList)))
6065
.bind("enum"))))),
61-
unless(declRefExpr(to(enumConstantDecl()))))),
66+
unless(declRefExpr(to(enumConstantDecl()))),
67+
unless(ignoringImplicit(ExcludedOperators)))),
6268
unless(hasAncestor(staticAssertDecl())))
6369
.bind("cast"),
6470
this);

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ Changes in existing checks
183183
<clang-tidy/checks/bugprone/lambda-function-name>` check by adding option
184184
`IgnoreMacros` to ignore warnings in macros.
185185

186+
- Improved :doc:`bugprone-non-zero-enum-to-bool-conversion
187+
<clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion>` check by
188+
eliminating false positives resulting from direct usage of bitwise operators.
189+
186190
- Improved :doc:`bugprone-reserved-identifier
187191
<clang-tidy/checks/bugprone/reserved-identifier>` check, so that it does not
188192
warn on macros starting with underscore and lowercase letter.

clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ bool explicitCompare(EStatus value) {
8282
return value == SUCCESS;
8383
}
8484

85+
bool explicitBitUsage1(EStatus value) {
86+
return (value & SUCCESS);
87+
}
88+
89+
bool explicitBitUsage2(EStatus value) {
90+
return (value | SUCCESS);
91+
}
92+
8593
bool testEnumeratorCompare() {
8694
return SUCCESS;
8795
}
@@ -104,4 +112,16 @@ bool testIgnored(IgnoredSecondEnum value) {
104112
return value;
105113
}
106114

115+
enum CustomOperatorEnum {
116+
E0 = 0x1,
117+
E1 = 0x2,
118+
E2 = 0x4
119+
};
120+
121+
CustomOperatorEnum operator&(CustomOperatorEnum a, CustomOperatorEnum b) { return static_cast<CustomOperatorEnum>(a & b); }
122+
123+
void testCustomOperator(CustomOperatorEnum e) {
124+
if (e & E1) {}
125+
}
126+
107127
}

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5514,7 +5514,7 @@ the configuration (without a prefix: ``Auto``).
55145514
.. _SpacesInParentheses:
55155515

55165516
**SpacesInParentheses** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`<SpacesInParentheses>`
5517-
If ``true'', spaces will be inserted after ``(`` and before ``)``.
5517+
If ``true``, spaces will be inserted after ``(`` and before ``)``.
55185518
This option is **deprecated**. The previous behavior is preserved by using
55195519
``SpacesInParens`` with ``Custom`` and by setting all
55205520
``SpacesInParensOptions`` to ``true`` except for ``InCStyleCasts`` and

clang/include/clang/ARCMigrate/FileRemapper.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_CLANG_ARCMIGRATE_FILEREMAPPER_H
1010
#define LLVM_CLANG_ARCMIGRATE_FILEREMAPPER_H
1111

12+
#include "clang/Basic/FileEntry.h"
1213
#include "clang/Basic/LLVM.h"
1314
#include "llvm/ADT/DenseMap.h"
1415
#include "llvm/ADT/PointerUnion.h"
@@ -23,7 +24,6 @@ namespace llvm {
2324

2425
namespace clang {
2526
class FileManager;
26-
class FileEntry;
2727
class DiagnosticsEngine;
2828
class PreprocessorOptions;
2929

@@ -33,11 +33,11 @@ class FileRemapper {
3333
// FIXME: Reuse the same FileManager for multiple ASTContexts.
3434
std::unique_ptr<FileManager> FileMgr;
3535

36-
typedef llvm::PointerUnion<const FileEntry *, llvm::MemoryBuffer *> Target;
37-
typedef llvm::DenseMap<const FileEntry *, Target> MappingsTy;
36+
typedef llvm::PointerUnion<FileEntryRef, llvm::MemoryBuffer *> Target;
37+
using MappingsTy = llvm::DenseMap<FileEntryRef, Target>;
3838
MappingsTy FromToMappings;
3939

40-
llvm::DenseMap<const FileEntry *, const FileEntry *> ToFromMappings;
40+
llvm::DenseMap<const FileEntry *, FileEntryRef> ToFromMappings;
4141

4242
public:
4343
FileRemapper();
@@ -66,10 +66,10 @@ class FileRemapper {
6666
void clear(StringRef outputDir = StringRef());
6767

6868
private:
69-
void remap(const FileEntry *file, std::unique_ptr<llvm::MemoryBuffer> memBuf);
70-
void remap(const FileEntry *file, const FileEntry *newfile);
69+
void remap(FileEntryRef file, std::unique_ptr<llvm::MemoryBuffer> memBuf);
70+
void remap(FileEntryRef file, FileEntryRef newfile);
7171

72-
const FileEntry *getOriginalFile(StringRef filePath);
72+
OptionalFileEntryRef getOriginalFile(StringRef filePath);
7373
void resetTarget(Target &targ);
7474

7575
bool report(const Twine &err, DiagnosticsEngine &Diag);

clang/include/clang/AST/Expr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ class Expr : public ValueStmt {
566566
SmallVectorImpl<
567567
PartialDiagnosticAt> &Diags);
568568

569-
/// isPotentialConstantExprUnevaluted - Return true if this expression might
569+
/// isPotentialConstantExprUnevaluated - Return true if this expression might
570570
/// be usable in a constant expression in C++11 in an unevaluated context, if
571571
/// it were in function FD marked constexpr. Return false if the function can
572572
/// never produce a constant expression, along with diagnostics describing

clang/include/clang/Format/Format.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4351,7 +4351,7 @@ struct FormatStyle {
43514351
SIPO_Custom,
43524352
};
43534353

4354-
/// If ``true'', spaces will be inserted after ``(`` and before ``)``.
4354+
/// If ``true``, spaces will be inserted after ``(`` and before ``)``.
43554355
/// This option is **deprecated**. The previous behavior is preserved by using
43564356
/// ``SpacesInParens`` with ``Custom`` and by setting all
43574357
/// ``SpacesInParensOptions`` to ``true`` except for ``InCStyleCasts`` and

clang/lib/ARCMigrate/FileRemapper.cpp

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ bool FileRemapper::initFromFile(StringRef filePath, DiagnosticsEngine &Diag,
6060
if (!llvm::sys::fs::exists(infoFile))
6161
return false;
6262

63-
std::vector<std::pair<const FileEntry *, const FileEntry *> > pairs;
63+
std::vector<std::pair<FileEntryRef, FileEntryRef>> pairs;
6464

6565
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileBuf =
6666
llvm::MemoryBuffer::getFile(infoFile, /*IsText=*/true);
@@ -78,20 +78,20 @@ bool FileRemapper::initFromFile(StringRef filePath, DiagnosticsEngine &Diag,
7878
Diag);
7979
StringRef toFilename = lines[idx+2];
8080

81-
llvm::ErrorOr<const FileEntry *> origFE = FileMgr->getFile(fromFilename);
81+
auto origFE = FileMgr->getOptionalFileRef(fromFilename);
8282
if (!origFE) {
8383
if (ignoreIfFilesChanged)
8484
continue;
8585
return report("File does not exist: " + fromFilename, Diag);
8686
}
87-
llvm::ErrorOr<const FileEntry *> newFE = FileMgr->getFile(toFilename);
87+
auto newFE = FileMgr->getOptionalFileRef(toFilename);
8888
if (!newFE) {
8989
if (ignoreIfFilesChanged)
9090
continue;
9191
return report("File does not exist: " + toFilename, Diag);
9292
}
9393

94-
if ((uint64_t)(*origFE)->getModificationTime() != timeModified) {
94+
if ((uint64_t)origFE->getModificationTime() != timeModified) {
9595
if (ignoreIfFilesChanged)
9696
continue;
9797
return report("File was modified: " + fromFilename, Diag);
@@ -128,23 +128,24 @@ bool FileRemapper::flushToFile(StringRef outputPath, DiagnosticsEngine &Diag) {
128128
for (MappingsTy::iterator
129129
I = FromToMappings.begin(), E = FromToMappings.end(); I != E; ++I) {
130130

131-
const FileEntry *origFE = I->first;
132-
SmallString<200> origPath = StringRef(origFE->getName());
131+
FileEntryRef origFE = I->first;
132+
SmallString<200> origPath = StringRef(origFE.getName());
133133
fs::make_absolute(origPath);
134134
infoOut << origPath << '\n';
135-
infoOut << (uint64_t)origFE->getModificationTime() << '\n';
135+
infoOut << (uint64_t)origFE.getModificationTime() << '\n';
136136

137-
if (const FileEntry *FE = I->second.dyn_cast<const FileEntry *>()) {
138-
SmallString<200> newPath = StringRef(FE->getName());
137+
if (I->second.is<FileEntryRef>()) {
138+
auto FE = I->second.get<FileEntryRef>();
139+
SmallString<200> newPath = StringRef(FE.getName());
139140
fs::make_absolute(newPath);
140141
infoOut << newPath << '\n';
141142
} else {
142143

143144
SmallString<64> tempPath;
144145
int fd;
145146
if (fs::createTemporaryFile(
146-
path::filename(origFE->getName()),
147-
path::extension(origFE->getName()).drop_front(), fd, tempPath,
147+
path::filename(origFE.getName()),
148+
path::extension(origFE.getName()).drop_front(), fd, tempPath,
148149
llvm::sys::fs::OF_Text))
149150
return report("Could not create file: " + tempPath.str(), Diag);
150151

@@ -153,10 +154,10 @@ bool FileRemapper::flushToFile(StringRef outputPath, DiagnosticsEngine &Diag) {
153154
newOut.write(mem->getBufferStart(), mem->getBufferSize());
154155
newOut.close();
155156

156-
auto newE = FileMgr->getFile(tempPath);
157+
auto newE = FileMgr->getOptionalFileRef(tempPath);
157158
if (newE) {
158159
remap(origFE, *newE);
159-
infoOut << (*newE)->getName() << '\n';
160+
infoOut << newE->getName() << '\n';
160161
}
161162
}
162163
}
@@ -171,14 +172,14 @@ bool FileRemapper::overwriteOriginal(DiagnosticsEngine &Diag,
171172

172173
for (MappingsTy::iterator
173174
I = FromToMappings.begin(), E = FromToMappings.end(); I != E; ++I) {
174-
const FileEntry *origFE = I->first;
175+
FileEntryRef origFE = I->first;
175176
assert(I->second.is<llvm::MemoryBuffer *>());
176-
if (!fs::exists(origFE->getName()))
177-
return report(StringRef("File does not exist: ") + origFE->getName(),
177+
if (!fs::exists(origFE.getName()))
178+
return report(StringRef("File does not exist: ") + origFE.getName(),
178179
Diag);
179180

180181
std::error_code EC;
181-
llvm::raw_fd_ostream Out(origFE->getName(), EC, llvm::sys::fs::OF_None);
182+
llvm::raw_fd_ostream Out(origFE.getName(), EC, llvm::sys::fs::OF_None);
182183
if (EC)
183184
return report(EC.message(), Diag);
184185

@@ -196,24 +197,26 @@ void FileRemapper::forEachMapping(
196197
llvm::function_ref<void(StringRef, const llvm::MemoryBufferRef &)>
197198
CaptureBuffer) const {
198199
for (auto &Mapping : FromToMappings) {
199-
if (const FileEntry *FE = Mapping.second.dyn_cast<const FileEntry *>()) {
200-
CaptureFile(Mapping.first->getName(), FE->getName());
200+
if (Mapping.second.is<FileEntryRef>()) {
201+
auto FE = Mapping.second.get<FileEntryRef>();
202+
CaptureFile(Mapping.first.getName(), FE.getName());
201203
continue;
202204
}
203205
CaptureBuffer(
204-
Mapping.first->getName(),
206+
Mapping.first.getName(),
205207
Mapping.second.get<llvm::MemoryBuffer *>()->getMemBufferRef());
206208
}
207209
}
208210

209211
void FileRemapper::applyMappings(PreprocessorOptions &PPOpts) const {
210212
for (MappingsTy::const_iterator
211213
I = FromToMappings.begin(), E = FromToMappings.end(); I != E; ++I) {
212-
if (const FileEntry *FE = I->second.dyn_cast<const FileEntry *>()) {
213-
PPOpts.addRemappedFile(I->first->getName(), FE->getName());
214+
if (I->second.is<FileEntryRef>()) {
215+
auto FE = I->second.get<FileEntryRef>();
216+
PPOpts.addRemappedFile(I->first.getName(), FE.getName());
214217
} else {
215218
llvm::MemoryBuffer *mem = I->second.get<llvm::MemoryBuffer *>();
216-
PPOpts.addRemappedFile(I->first->getName(), mem);
219+
PPOpts.addRemappedFile(I->first.getName(), mem);
217220
}
218221
}
219222

@@ -222,38 +225,37 @@ void FileRemapper::applyMappings(PreprocessorOptions &PPOpts) const {
222225

223226
void FileRemapper::remap(StringRef filePath,
224227
std::unique_ptr<llvm::MemoryBuffer> memBuf) {
225-
remap(getOriginalFile(filePath), std::move(memBuf));
228+
OptionalFileEntryRef File = getOriginalFile(filePath);
229+
assert(File);
230+
remap(*File, std::move(memBuf));
226231
}
227232

228-
void FileRemapper::remap(const FileEntry *file,
233+
void FileRemapper::remap(FileEntryRef file,
229234
std::unique_ptr<llvm::MemoryBuffer> memBuf) {
230-
assert(file);
231235
Target &targ = FromToMappings[file];
232236
resetTarget(targ);
233237
targ = memBuf.release();
234238
}
235239

236-
void FileRemapper::remap(const FileEntry *file, const FileEntry *newfile) {
237-
assert(file && newfile);
240+
void FileRemapper::remap(FileEntryRef file, FileEntryRef newfile) {
238241
Target &targ = FromToMappings[file];
239242
resetTarget(targ);
240243
targ = newfile;
241-
ToFromMappings[newfile] = file;
244+
ToFromMappings.insert({newfile, file});
242245
}
243246

244-
const FileEntry *FileRemapper::getOriginalFile(StringRef filePath) {
245-
const FileEntry *file = nullptr;
246-
if (auto fileOrErr = FileMgr->getFile(filePath))
247-
file = *fileOrErr;
247+
OptionalFileEntryRef FileRemapper::getOriginalFile(StringRef filePath) {
248+
OptionalFileEntryRef File = FileMgr->getOptionalFileRef(filePath);
249+
if (!File)
250+
return std::nullopt;
248251
// If we are updating a file that overridden an original file,
249252
// actually update the original file.
250-
llvm::DenseMap<const FileEntry *, const FileEntry *>::iterator
251-
I = ToFromMappings.find(file);
253+
auto I = ToFromMappings.find(*File);
252254
if (I != ToFromMappings.end()) {
253-
file = I->second;
254-
assert(FromToMappings.contains(file) && "Original file not in mappings!");
255+
*File = I->second;
256+
assert(FromToMappings.contains(*File) && "Original file not in mappings!");
255257
}
256-
return file;
258+
return File;
257259
}
258260

259261
void FileRemapper::resetTarget(Target &targ) {
@@ -263,7 +265,7 @@ void FileRemapper::resetTarget(Target &targ) {
263265
if (llvm::MemoryBuffer *oldmem = targ.dyn_cast<llvm::MemoryBuffer *>()) {
264266
delete oldmem;
265267
} else {
266-
const FileEntry *toFE = targ.get<const FileEntry *>();
268+
FileEntryRef toFE = targ.get<FileEntryRef>();
267269
ToFromMappings.erase(toFE);
268270
}
269271
}

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,18 @@ void AArch64TargetInfo::getTargetDefinesARMV94A(const LangOptions &Opts,
335335
void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
336336
MacroBuilder &Builder) const {
337337
// Target identification.
338-
Builder.defineMacro("__aarch64__");
338+
if (getTriple().isWindowsArm64EC()) {
339+
// Define the same set of macros as would be defined on x86_64 to ensure that
340+
// ARM64EC datatype layouts match those of x86_64 compiled code
341+
Builder.defineMacro("__amd64__");
342+
Builder.defineMacro("__amd64");
343+
Builder.defineMacro("__x86_64");
344+
Builder.defineMacro("__x86_64__");
345+
Builder.defineMacro("__arm64ec__");
346+
} else {
347+
Builder.defineMacro("__aarch64__");
348+
}
349+
339350
// Inline assembly supports AArch64 flag outputs.
340351
Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
341352

@@ -1465,7 +1476,13 @@ MicrosoftARM64TargetInfo::MicrosoftARM64TargetInfo(const llvm::Triple &Triple,
14651476
void MicrosoftARM64TargetInfo::getTargetDefines(const LangOptions &Opts,
14661477
MacroBuilder &Builder) const {
14671478
WindowsARM64TargetInfo::getTargetDefines(Opts, Builder);
1468-
Builder.defineMacro("_M_ARM64", "1");
1479+
if (getTriple().isWindowsArm64EC()) {
1480+
Builder.defineMacro("_M_X64", "100");
1481+
Builder.defineMacro("_M_AMD64", "100");
1482+
Builder.defineMacro("_M_ARM64EC", "1");
1483+
} else {
1484+
Builder.defineMacro("_M_ARM64", "1");
1485+
}
14691486
}
14701487

14711488
TargetInfo::CallingConvKind

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ llvm::Triple::ArchType darwin::getArchTypeForMachOArchName(StringRef Str) {
5353
// translation.
5454

5555
return llvm::StringSwitch<llvm::Triple::ArchType>(Str)
56-
.Cases("ppc", "ppc601", "ppc603", "ppc604", "ppc604e", llvm::Triple::ppc)
57-
.Cases("ppc750", "ppc7400", "ppc7450", "ppc970", llvm::Triple::ppc)
58-
.Case("ppc64", llvm::Triple::ppc64)
5956
.Cases("i386", "i486", "i486SX", "i586", "i686", llvm::Triple::x86)
6057
.Cases("pentium", "pentpro", "pentIIm3", "pentIIm5", "pentium4",
6158
llvm::Triple::x86)

clang/lib/Serialization/ASTReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5689,7 +5689,7 @@ llvm::Error ASTReader::ReadSubmoduleBlock(ModuleFile &F,
56895689
"too many submodules");
56905690

56915691
if (!ParentModule) {
5692-
if (const FileEntry *CurFile = CurrentModule->getASTFile()) {
5692+
if (OptionalFileEntryRef CurFile = CurrentModule->getASTFile()) {
56935693
// Don't emit module relocation error if we have -fno-validate-pch
56945694
if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation &
56955695
DisableValidationForModuleKind::Module) &&

0 commit comments

Comments
 (0)