Skip to content

Commit 13ef517

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:71bdd2c2380d into amd-gfx:319c66a13c02
Local branch amd-gfx 319c66a Merged main:080fb3e5b73b into amd-gfx:7c4daea7af99 Remote branch main 71bdd2c mlir/lib/Dialect/GPU/Transforms: improve context management in SerializeToCubin (llvm#65779)
2 parents 319c66a + 71bdd2c commit 13ef517

File tree

230 files changed

+3892
-3565
lines changed

Some content is hidden

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

230 files changed

+3892
-3565
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ Improvements to Clang's diagnostics
346346
| ~~~~~~~~~^~~~~~~~
347347
- Clang now always diagnoses when using non-standard layout types in ``offsetof`` .
348348
(`#64619: <https://github.com/llvm/llvm-project/issues/64619>`_)
349+
- Clang now diagnoses use of variable-length arrays in C++ by default (and
350+
under ``-Wall`` in GNU++ mode). This is an extension supported by Clang and
351+
GCC, but is very easy to accidentally use without realizing it's a
352+
nonportable construct that has different semantics from a constant-sized
353+
array. (`#62836 <https://github.com/llvm/llvm-project/issues/62836>`_)
349354

350355
Bug Fixes in This Version
351356
-------------------------

clang/include/clang/ARCMigrate/FileRemapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
#include "clang/Basic/FileEntry.h"
1313
#include "clang/Basic/LLVM.h"
1414
#include "llvm/ADT/DenseMap.h"
15-
#include "llvm/ADT/PointerUnion.h"
1615
#include "llvm/ADT/STLExtras.h"
1716
#include "llvm/ADT/StringRef.h"
1817
#include <memory>
18+
#include <variant>
1919

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

36-
typedef llvm::PointerUnion<FileEntryRef, llvm::MemoryBuffer *> Target;
36+
using Target = std::variant<FileEntryRef, llvm::MemoryBuffer *>;
3737
using MappingsTy = llvm::DenseMap<FileEntryRef, Target>;
3838
MappingsTy FromToMappings;
3939

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,8 @@ def OverridingMethodMismatch : DiagGroup<"overriding-method-mismatch">;
848848
def VariadicMacros : DiagGroup<"variadic-macros">;
849849
def VectorConversion : DiagGroup<"vector-conversion">; // clang specific
850850
def VexingParse : DiagGroup<"vexing-parse">;
851-
def VLAExtension : DiagGroup<"vla-extension">;
851+
def VLAUseStaticAssert : DiagGroup<"vla-extension-static-assert">;
852+
def VLAExtension : DiagGroup<"vla-extension", [VLAUseStaticAssert]>;
852853
def VLA : DiagGroup<"vla", [VLAExtension]>;
853854
def VolatileRegisterVar : DiagGroup<"volatile-register-var">;
854855
def Visibility : DiagGroup<"visibility">;
@@ -1085,7 +1086,7 @@ def Consumed : DiagGroup<"consumed">;
10851086
// warning should be active _only_ when -Wall is passed in, mark it as
10861087
// DefaultIgnore in addition to putting it here.
10871088
def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
1088-
MisleadingIndentation, PackedNonPod]>;
1089+
MisleadingIndentation, PackedNonPod, VLAExtension]>;
10891090

10901091
// Warnings that should be in clang-cl /w4.
10911092
def : DiagGroup<"CL4", [All, Extra]>;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ def err_half_const_requires_fp16 : Error<
137137
// C99 variable-length arrays
138138
def ext_vla : Extension<"variable length arrays are a C99 feature">,
139139
InGroup<VLAExtension>;
140+
// In C++ language modes, we warn by default as an extension, while in GNU++
141+
// language modes, we warn as an extension but add the warning group to -Wall.
142+
def ext_vla_cxx : ExtWarn<
143+
"variable length arrays in C++ are a Clang extension">,
144+
InGroup<VLAExtension>;
145+
def ext_vla_cxx_in_gnu_mode : Extension<ext_vla_cxx.Summary>,
146+
InGroup<VLAExtension>;
147+
def ext_vla_cxx_static_assert : ExtWarn<
148+
"variable length arrays in C++ are a Clang extension; did you mean to use "
149+
"'static_assert'?">, InGroup<VLAUseStaticAssert>;
150+
def ext_vla_cxx_in_gnu_mode_static_assert : Extension<
151+
ext_vla_cxx_static_assert.Summary>, InGroup<VLAUseStaticAssert>;
140152
def warn_vla_used : Warning<"variable length array used">,
141153
InGroup<VLA>, DefaultIgnore;
142154
def err_vla_in_sfinae : Error<

clang/include/clang/Basic/FileEntry.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -235,37 +235,6 @@ static_assert(std::is_trivially_copyable<OptionalFileEntryRef>::value,
235235

236236
namespace llvm {
237237

238-
template <> struct PointerLikeTypeTraits<clang::FileEntryRef> {
239-
static inline void *getAsVoidPointer(clang::FileEntryRef File) {
240-
return const_cast<clang::FileEntryRef::MapEntry *>(&File.getMapEntry());
241-
}
242-
243-
static inline clang::FileEntryRef getFromVoidPointer(void *Ptr) {
244-
return clang::FileEntryRef(
245-
*reinterpret_cast<const clang::FileEntryRef::MapEntry *>(Ptr));
246-
}
247-
248-
static constexpr int NumLowBitsAvailable = PointerLikeTypeTraits<
249-
const clang::FileEntryRef::MapEntry *>::NumLowBitsAvailable;
250-
};
251-
252-
template <> struct PointerLikeTypeTraits<clang::OptionalFileEntryRef> {
253-
static inline void *getAsVoidPointer(clang::OptionalFileEntryRef File) {
254-
if (!File)
255-
return nullptr;
256-
return PointerLikeTypeTraits<clang::FileEntryRef>::getAsVoidPointer(*File);
257-
}
258-
259-
static inline clang::OptionalFileEntryRef getFromVoidPointer(void *Ptr) {
260-
if (!Ptr)
261-
return std::nullopt;
262-
return PointerLikeTypeTraits<clang::FileEntryRef>::getFromVoidPointer(Ptr);
263-
}
264-
265-
static constexpr int NumLowBitsAvailable =
266-
PointerLikeTypeTraits<clang::FileEntryRef>::NumLowBitsAvailable;
267-
};
268-
269238
/// Specialisation of DenseMapInfo for FileEntryRef.
270239
template <> struct DenseMapInfo<clang::FileEntryRef> {
271240
static inline clang::FileEntryRef getEmptyKey() {

clang/include/clang/Basic/Module.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <optional>
3636
#include <string>
3737
#include <utility>
38+
#include <variant>
3839
#include <vector>
3940

4041
namespace llvm {
@@ -162,7 +163,7 @@ class alignas(8) Module {
162163
std::string PresumedModuleMapFile;
163164

164165
/// The umbrella header or directory.
165-
llvm::PointerUnion<FileEntryRef, DirectoryEntryRef> Umbrella;
166+
std::variant<std::monostate, FileEntryRef, DirectoryEntryRef> Umbrella;
166167

167168
/// The module signature.
168169
ASTFileSignature Signature;
@@ -665,18 +666,17 @@ class alignas(8) Module {
665666

666667
/// Retrieve the umbrella directory as written.
667668
std::optional<DirectoryName> getUmbrellaDirAsWritten() const {
668-
if (Umbrella && Umbrella.is<DirectoryEntryRef>())
669+
if (const auto *Dir = std::get_if<DirectoryEntryRef>(&Umbrella))
669670
return DirectoryName{UmbrellaAsWritten,
670-
UmbrellaRelativeToRootModuleDirectory,
671-
Umbrella.get<DirectoryEntryRef>()};
671+
UmbrellaRelativeToRootModuleDirectory, *Dir};
672672
return std::nullopt;
673673
}
674674

675675
/// Retrieve the umbrella header as written.
676676
std::optional<Header> getUmbrellaHeaderAsWritten() const {
677-
if (Umbrella && Umbrella.is<FileEntryRef>())
677+
if (const auto *Hdr = std::get_if<FileEntryRef>(&Umbrella))
678678
return Header{UmbrellaAsWritten, UmbrellaRelativeToRootModuleDirectory,
679-
Umbrella.get<FileEntryRef>()};
679+
*Hdr};
680680
return std::nullopt;
681681
}
682682

clang/include/clang/Frontend/VerifyDiagnosticConsumer.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,15 @@ class VerifyDiagnosticConsumer: public DiagnosticConsumer,
278278

279279
// These facilities are used for validation in debug builds.
280280
class UnparsedFileStatus {
281-
llvm::PointerIntPair<OptionalFileEntryRef, 1, bool> Data;
281+
OptionalFileEntryRef File;
282+
bool FoundDirectives;
282283

283284
public:
284285
UnparsedFileStatus(OptionalFileEntryRef File, bool FoundDirectives)
285-
: Data(File, FoundDirectives) {}
286+
: File(File), FoundDirectives(FoundDirectives) {}
286287

287-
OptionalFileEntryRef getFile() const { return Data.getPointer(); }
288-
bool foundDirectives() const { return Data.getInt(); }
288+
OptionalFileEntryRef getFile() const { return File; }
289+
bool foundDirectives() const { return FoundDirectives; }
289290
};
290291

291292
using ParsedFilesMap = llvm::DenseMap<FileID, const FileEntry *>;

clang/include/clang/Lex/ModuleMap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include "clang/Basic/SourceLocation.h"
2121
#include "llvm/ADT/ArrayRef.h"
2222
#include "llvm/ADT/DenseMap.h"
23+
#include "llvm/ADT/DenseSet.h"
2324
#include "llvm/ADT/PointerIntPair.h"
24-
#include "llvm/ADT/SmallPtrSet.h"
2525
#include "llvm/ADT/SmallVector.h"
2626
#include "llvm/ADT/StringMap.h"
2727
#include "llvm/ADT/StringRef.h"
@@ -194,7 +194,7 @@ class ModuleMap {
194194
}
195195
};
196196

197-
using AdditionalModMapsSet = llvm::SmallPtrSet<FileEntryRef, 1>;
197+
using AdditionalModMapsSet = llvm::DenseSet<FileEntryRef>;
198198

199199
private:
200200
friend class ModuleMapParser;

clang/lib/ARCMigrate/FileRemapper.cpp

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ bool FileRemapper::flushToFile(StringRef outputPath, DiagnosticsEngine &Diag) {
134134
infoOut << origPath << '\n';
135135
infoOut << (uint64_t)origFE.getModificationTime() << '\n';
136136

137-
if (I->second.is<FileEntryRef>()) {
138-
auto FE = I->second.get<FileEntryRef>();
139-
SmallString<200> newPath = StringRef(FE.getName());
137+
if (const auto *FE = std::get_if<FileEntryRef>(&I->second)) {
138+
SmallString<200> newPath = StringRef(FE->getName());
140139
fs::make_absolute(newPath);
141140
infoOut << newPath << '\n';
142141
} else {
@@ -150,7 +149,7 @@ bool FileRemapper::flushToFile(StringRef outputPath, DiagnosticsEngine &Diag) {
150149
return report("Could not create file: " + tempPath.str(), Diag);
151150

152151
llvm::raw_fd_ostream newOut(fd, /*shouldClose=*/true);
153-
llvm::MemoryBuffer *mem = I->second.get<llvm::MemoryBuffer *>();
152+
llvm::MemoryBuffer *mem = std::get<llvm::MemoryBuffer *>(I->second);
154153
newOut.write(mem->getBufferStart(), mem->getBufferSize());
155154
newOut.close();
156155

@@ -173,7 +172,7 @@ bool FileRemapper::overwriteOriginal(DiagnosticsEngine &Diag,
173172
for (MappingsTy::iterator
174173
I = FromToMappings.begin(), E = FromToMappings.end(); I != E; ++I) {
175174
FileEntryRef origFE = I->first;
176-
assert(I->second.is<llvm::MemoryBuffer *>());
175+
assert(std::holds_alternative<llvm::MemoryBuffer *>(I->second));
177176
if (!fs::exists(origFE.getName()))
178177
return report(StringRef("File does not exist: ") + origFE.getName(),
179178
Diag);
@@ -183,7 +182,7 @@ bool FileRemapper::overwriteOriginal(DiagnosticsEngine &Diag,
183182
if (EC)
184183
return report(EC.message(), Diag);
185184

186-
llvm::MemoryBuffer *mem = I->second.get<llvm::MemoryBuffer *>();
185+
llvm::MemoryBuffer *mem = std::get<llvm::MemoryBuffer *>(I->second);
187186
Out.write(mem->getBufferStart(), mem->getBufferSize());
188187
Out.close();
189188
}
@@ -197,25 +196,23 @@ void FileRemapper::forEachMapping(
197196
llvm::function_ref<void(StringRef, const llvm::MemoryBufferRef &)>
198197
CaptureBuffer) const {
199198
for (auto &Mapping : FromToMappings) {
200-
if (Mapping.second.is<FileEntryRef>()) {
201-
auto FE = Mapping.second.get<FileEntryRef>();
202-
CaptureFile(Mapping.first.getName(), FE.getName());
199+
if (const auto *FE = std::get_if<FileEntryRef>(&Mapping.second)) {
200+
CaptureFile(Mapping.first.getName(), FE->getName());
203201
continue;
204202
}
205203
CaptureBuffer(
206204
Mapping.first.getName(),
207-
Mapping.second.get<llvm::MemoryBuffer *>()->getMemBufferRef());
205+
std::get<llvm::MemoryBuffer *>(Mapping.second)->getMemBufferRef());
208206
}
209207
}
210208

211209
void FileRemapper::applyMappings(PreprocessorOptions &PPOpts) const {
212210
for (MappingsTy::const_iterator
213211
I = FromToMappings.begin(), E = FromToMappings.end(); I != E; ++I) {
214-
if (I->second.is<FileEntryRef>()) {
215-
auto FE = I->second.get<FileEntryRef>();
216-
PPOpts.addRemappedFile(I->first.getName(), FE.getName());
212+
if (const auto *FE = std::get_if<FileEntryRef>(&I->second)) {
213+
PPOpts.addRemappedFile(I->first.getName(), FE->getName());
217214
} else {
218-
llvm::MemoryBuffer *mem = I->second.get<llvm::MemoryBuffer *>();
215+
llvm::MemoryBuffer *mem = std::get<llvm::MemoryBuffer *>(I->second);
219216
PPOpts.addRemappedFile(I->first.getName(), mem);
220217
}
221218
}
@@ -230,18 +227,20 @@ void FileRemapper::remap(StringRef filePath,
230227
remap(*File, std::move(memBuf));
231228
}
232229

233-
void FileRemapper::remap(FileEntryRef file,
234-
std::unique_ptr<llvm::MemoryBuffer> memBuf) {
235-
Target &targ = FromToMappings[file];
236-
resetTarget(targ);
237-
targ = memBuf.release();
230+
void FileRemapper::remap(FileEntryRef File,
231+
std::unique_ptr<llvm::MemoryBuffer> MemBuf) {
232+
auto [It, New] = FromToMappings.insert({File, nullptr});
233+
if (!New)
234+
resetTarget(It->second);
235+
It->second = MemBuf.release();
238236
}
239237

240-
void FileRemapper::remap(FileEntryRef file, FileEntryRef newfile) {
241-
Target &targ = FromToMappings[file];
242-
resetTarget(targ);
243-
targ = newfile;
244-
ToFromMappings.insert({newfile, file});
238+
void FileRemapper::remap(FileEntryRef File, FileEntryRef NewFile) {
239+
auto [It, New] = FromToMappings.insert({File, nullptr});
240+
if (!New)
241+
resetTarget(It->second);
242+
It->second = NewFile;
243+
ToFromMappings.insert({NewFile, File});
245244
}
246245

247246
OptionalFileEntryRef FileRemapper::getOriginalFile(StringRef filePath) {
@@ -259,13 +258,11 @@ OptionalFileEntryRef FileRemapper::getOriginalFile(StringRef filePath) {
259258
}
260259

261260
void FileRemapper::resetTarget(Target &targ) {
262-
if (!targ)
263-
return;
264-
265-
if (llvm::MemoryBuffer *oldmem = targ.dyn_cast<llvm::MemoryBuffer *>()) {
261+
if (std::holds_alternative<llvm::MemoryBuffer *>(targ)) {
262+
llvm::MemoryBuffer *oldmem = std::get<llvm::MemoryBuffer *>(targ);
266263
delete oldmem;
267264
} else {
268-
FileEntryRef toFE = targ.get<FileEntryRef>();
265+
FileEntryRef toFE = std::get<FileEntryRef>(targ);
269266
ToFromMappings.erase(toFE);
270267
}
271268
}

clang/lib/Basic/Module.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,10 @@ bool Module::fullModuleNameIs(ArrayRef<StringRef> nameParts) const {
265265
}
266266

267267
OptionalDirectoryEntryRef Module::getEffectiveUmbrellaDir() const {
268-
if (Umbrella && Umbrella.is<FileEntryRef>())
269-
return Umbrella.get<FileEntryRef>().getDir();
270-
if (Umbrella && Umbrella.is<DirectoryEntryRef>())
271-
return Umbrella.get<DirectoryEntryRef>();
268+
if (const auto *Hdr = std::get_if<FileEntryRef>(&Umbrella))
269+
return Hdr->getDir();
270+
if (const auto *Dir = std::get_if<DirectoryEntryRef>(&Umbrella))
271+
return *Dir;
272272
return std::nullopt;
273273
}
274274

clang/lib/CodeGen/CGCall.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3447,9 +3447,9 @@ static llvm::Value *tryRemoveRetainOfSelf(CodeGenFunction &CGF,
34473447
const VarDecl *self = method->getSelfDecl();
34483448
if (!self->getType().isConstQualified()) return nullptr;
34493449

3450-
// Look for a retain call. Note: stripPointerCasts looks through returned arg
3451-
// functions, which would cause us to miss the retain.
3452-
llvm::CallInst *retainCall = dyn_cast<llvm::CallInst>(result);
3450+
// Look for a retain call.
3451+
llvm::CallInst *retainCall =
3452+
dyn_cast<llvm::CallInst>(result->stripPointerCasts());
34533453
if (!retainCall || retainCall->getCalledOperand() !=
34543454
CGF.CGM.getObjCEntrypoints().objc_retain)
34553455
return nullptr;

clang/lib/CodeGen/CGObjC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3954,7 +3954,7 @@ static unsigned getBaseMachOPlatformID(const llvm::Triple &TT) {
39543954
case llvm::Triple::DriverKit:
39553955
return llvm::MachO::PLATFORM_DRIVERKIT;
39563956
default:
3957-
return /*Unknown platform*/ 0;
3957+
return llvm::MachO::PLATFORM_UNKNOWN;
39583958
}
39593959
}
39603960

clang/lib/CodeGen/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ set(LLVM_LINK_COMPONENTS
3131
TransformUtils
3232
)
3333

34+
# Workaround for MSVC ARM64 performance regression:
35+
# https://developercommunity.visualstudio.com/t/Compiling-a-specific-code-for-ARM64-with/10444970
36+
# Since /O1 and /O2 represent a set of optimizations,
37+
# our goal is to disable the /Og flag while retaining the other optimizations from the /O1|/O2 set
38+
if(MSVC AND NOT CMAKE_CXX_COMPILER_ID MATCHES Clang
39+
AND MSVC_VERSION VERSION_GREATER_EQUAL 1932
40+
AND CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64")
41+
42+
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
43+
string(REGEX MATCHALL "/[Oo][12]" opt_flags "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}")
44+
if (opt_flags)
45+
if(opt_flags MATCHES "1$")
46+
set(opt_flags "/Od;/Os;/Oy;/Ob2;/GF;/Gy")
47+
elseif (opt_flags MATCHES "2$")
48+
set(opt_flags "/Od;/Oi;/Ot;/Oy;/Ob2;/GF;/Gy")
49+
endif()
50+
set_source_files_properties(CGBuiltin.cpp PROPERTIES COMPILE_OPTIONS "${opt_flags}")
51+
endif()
52+
endif()
53+
3454
add_clang_library(clangCodeGen
3555
ABIInfo.cpp
3656
ABIInfoImpl.cpp

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2295,7 +2295,7 @@ void tools::AddStaticDeviceLibs(Compilation *C, const Tool *T,
22952295
static const StringRef HostOnlyArchives[] = {
22962296
"omp", "cudart", "m", "gcc", "gcc_s", "pthread", "hip_hcc"};
22972297
for (auto SDLName : DriverArgs.getAllArgValues(options::OPT_l)) {
2298-
if (!HostOnlyArchives->contains(SDLName)) {
2298+
if (!llvm::is_contained(HostOnlyArchives, SDLName)) {
22992299
SDLNames.insert(std::string("-l") + SDLName);
23002300
}
23012301
}

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@ bool HeaderSearch::findUsableModuleForHeader(
16231623
ModuleMap::KnownHeader *SuggestedModule, bool IsSystemHeaderDir) {
16241624
if (needModuleLookup(RequestingModule, SuggestedModule)) {
16251625
// If there is a module that corresponds to this header, suggest it.
1626-
hasModuleMap(File.getName(), Root, IsSystemHeaderDir);
1626+
hasModuleMap(File.getNameAsRequested(), Root, IsSystemHeaderDir);
16271627
return suggestModule(*this, File, RequestingModule, SuggestedModule);
16281628
}
16291629
return true;

0 commit comments

Comments
 (0)