Skip to content

Commit 6e0fa54

Browse files
authored
Merge branch 'release/20.x' into issue136842
2 parents 6dca7d1 + a7166c3 commit 6e0fa54

File tree

54 files changed

+702
-194
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

+702
-194
lines changed

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def find_compilation_database(path: str) -> str:
8787

8888

8989
def get_tidy_invocation(
90-
f: str,
90+
f: Optional[str],
9191
clang_tidy_binary: str,
9292
checks: str,
9393
tmpdir: Optional[str],
@@ -147,7 +147,8 @@ def get_tidy_invocation(
147147
start.append(f"--warnings-as-errors={warnings_as_errors}")
148148
if allow_no_checks:
149149
start.append("--allow-no-checks")
150-
start.append(f)
150+
if f:
151+
start.append(f)
151152
return start
152153

153154

@@ -490,7 +491,7 @@ async def main() -> None:
490491

491492
try:
492493
invocation = get_tidy_invocation(
493-
"",
494+
None,
494495
clang_tidy_binary,
495496
args.checks,
496497
None,

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ Improvements to clang-tidy
190190
- Fixed bug in :program:`clang-tidy` by which `HeaderFilterRegex` did not take
191191
effect when passed via the `.clang-tidy` file.
192192

193+
- Fixed bug in :program:`run_clang_tidy.py` where the program would not
194+
correctly display the checks enabled by the top-level `.clang-tidy` file.
195+
193196
New checks
194197
^^^^^^^^^^
195198

clang/include/clang/Driver/Distro.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class Distro {
3939
DebianBullseye,
4040
DebianBookworm,
4141
DebianTrixie,
42+
DebianForky,
43+
DebianDuke,
4244
Exherbo,
4345
RHEL5,
4446
RHEL6,
@@ -128,7 +130,7 @@ class Distro {
128130
bool IsOpenSUSE() const { return DistroVal == OpenSUSE; }
129131

130132
bool IsDebian() const {
131-
return DistroVal >= DebianLenny && DistroVal <= DebianTrixie;
133+
return DistroVal >= DebianLenny && DistroVal <= DebianDuke;
132134
}
133135

134136
bool IsUbuntu() const {

clang/include/clang/Interpreter/Interpreter.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class CXXRecordDecl;
4141
class Decl;
4242
class IncrementalExecutor;
4343
class IncrementalParser;
44+
class IncrementalCUDADeviceParser;
4445

4546
/// Create a pre-configured \c CompilerInstance for incremental processing.
4647
class IncrementalCompilerBuilder {
@@ -93,7 +94,10 @@ class Interpreter {
9394
std::unique_ptr<IncrementalExecutor> IncrExecutor;
9495

9596
// An optional parser for CUDA offloading
96-
std::unique_ptr<IncrementalParser> DeviceParser;
97+
std::unique_ptr<IncrementalCUDADeviceParser> DeviceParser;
98+
99+
// An optional action for CUDA offloading
100+
std::unique_ptr<IncrementalAction> DeviceAct;
97101

98102
/// List containing information about each incrementally parsed piece of code.
99103
std::list<PartialTranslationUnit> PTUs;
@@ -112,6 +116,9 @@ class Interpreter {
112116
/// Compiler instance performing the incremental compilation.
113117
std::unique_ptr<CompilerInstance> CI;
114118

119+
/// An optional compiler instance for CUDA offloading
120+
std::unique_ptr<CompilerInstance> DeviceCI;
121+
115122
protected:
116123
// Derived classes can use an extended interface of the Interpreter.
117124
Interpreter(std::unique_ptr<CompilerInstance> Instance, llvm::Error &Err,
@@ -175,10 +182,11 @@ class Interpreter {
175182
llvm::Expected<Expr *> ExtractValueFromExpr(Expr *E);
176183
llvm::Expected<llvm::orc::ExecutorAddr> CompileDtorCall(CXXRecordDecl *CXXRD);
177184

178-
CodeGenerator *getCodeGen() const;
179-
std::unique_ptr<llvm::Module> GenModule();
185+
CodeGenerator *getCodeGen(IncrementalAction *Action = nullptr) const;
186+
std::unique_ptr<llvm::Module> GenModule(IncrementalAction *Action = nullptr);
180187
PartialTranslationUnit &RegisterPTU(TranslationUnitDecl *TU,
181-
std::unique_ptr<llvm::Module> M = {});
188+
std::unique_ptr<llvm::Module> M = {},
189+
IncrementalAction *Action = nullptr);
182190

183191
// A cache for the compiled destructors used to for de-allocation of managed
184192
// clang::Values.

clang/lib/Driver/Distro.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ static Distro::DistroType DetectDistro(llvm::vfs::FileSystem &VFS) {
160160
return Distro::DebianBookworm;
161161
case 13:
162162
return Distro::DebianTrixie;
163+
case 14:
164+
return Distro::DebianForky;
165+
case 15:
166+
return Distro::DebianDuke;
163167
default:
164168
return Distro::UnknownDistro;
165169
}
@@ -173,6 +177,8 @@ static Distro::DistroType DetectDistro(llvm::vfs::FileSystem &VFS) {
173177
.Case("bullseye/sid", Distro::DebianBullseye)
174178
.Case("bookworm/sid", Distro::DebianBookworm)
175179
.Case("trixie/sid", Distro::DebianTrixie)
180+
.Case("forky/sid", Distro::DebianForky)
181+
.Case("duke/sid", Distro::DebianDuke)
176182
.Default(Distro::UnknownDistro);
177183
}
178184

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,8 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
25812581
if (Prev) {
25822582
auto OptionalParens = [&] {
25832583
if (MightBeStmtExpr || MightBeFoldExpr || Line->InMacroBody ||
2584-
SeenComma || Style.RemoveParentheses == FormatStyle::RPS_Leave) {
2584+
SeenComma || Style.RemoveParentheses == FormatStyle::RPS_Leave ||
2585+
RParen->getPreviousNonComment() == LParen) {
25852586
return false;
25862587
}
25872588
const bool DoubleParens =

clang/lib/Interpreter/DeviceOffload.cpp

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@
2525
namespace clang {
2626

2727
IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
28-
std::unique_ptr<CompilerInstance> DeviceInstance,
29-
CompilerInstance &HostInstance,
28+
CompilerInstance &DeviceInstance, CompilerInstance &HostInstance,
3029
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS,
3130
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs)
32-
: IncrementalParser(*DeviceInstance, Err), PTUs(PTUs), VFS(FS),
31+
: IncrementalParser(DeviceInstance, Err), PTUs(PTUs), VFS(FS),
3332
CodeGenOpts(HostInstance.getCodeGenOpts()),
34-
TargetOpts(HostInstance.getTargetOpts()) {
33+
TargetOpts(DeviceInstance.getTargetOpts()) {
3534
if (Err)
3635
return;
37-
DeviceCI = std::move(DeviceInstance);
3836
StringRef Arch = TargetOpts.CPU;
3937
if (!Arch.starts_with("sm_") || Arch.substr(3).getAsInteger(10, SMVersion)) {
4038
Err = llvm::joinErrors(std::move(Err), llvm::make_error<llvm::StringError>(
@@ -44,34 +42,6 @@ IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
4442
}
4543
}
4644

47-
llvm::Expected<TranslationUnitDecl *>
48-
IncrementalCUDADeviceParser::Parse(llvm::StringRef Input) {
49-
auto PTU = IncrementalParser::Parse(Input);
50-
if (!PTU)
51-
return PTU.takeError();
52-
53-
auto PTX = GeneratePTX();
54-
if (!PTX)
55-
return PTX.takeError();
56-
57-
auto Err = GenerateFatbinary();
58-
if (Err)
59-
return std::move(Err);
60-
61-
std::string FatbinFileName =
62-
"/incr_module_" + std::to_string(PTUs.size()) + ".fatbin";
63-
VFS->addFile(FatbinFileName, 0,
64-
llvm::MemoryBuffer::getMemBuffer(
65-
llvm::StringRef(FatbinContent.data(), FatbinContent.size()),
66-
"", false));
67-
68-
CodeGenOpts.CudaGpuBinaryFileName = FatbinFileName;
69-
70-
FatbinContent.clear();
71-
72-
return PTU;
73-
}
74-
7545
llvm::Expected<llvm::StringRef> IncrementalCUDADeviceParser::GeneratePTX() {
7646
auto &PTU = PTUs.back();
7747
std::string Error;
@@ -172,6 +142,19 @@ llvm::Error IncrementalCUDADeviceParser::GenerateFatbinary() {
172142

173143
FatbinContent.append(PTXCode.begin(), PTXCode.end());
174144

145+
const PartialTranslationUnit &PTU = PTUs.back();
146+
147+
std::string FatbinFileName = "/" + PTU.TheModule->getName().str() + ".fatbin";
148+
149+
VFS->addFile(FatbinFileName, 0,
150+
llvm::MemoryBuffer::getMemBuffer(
151+
llvm::StringRef(FatbinContent.data(), FatbinContent.size()),
152+
"", false));
153+
154+
CodeGenOpts.CudaGpuBinaryFileName = FatbinFileName;
155+
156+
FatbinContent.clear();
157+
175158
return llvm::Error::success();
176159
}
177160

clang/lib/Interpreter/DeviceOffload.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@ class IncrementalCUDADeviceParser : public IncrementalParser {
2828

2929
public:
3030
IncrementalCUDADeviceParser(
31-
std::unique_ptr<CompilerInstance> DeviceInstance,
32-
CompilerInstance &HostInstance,
31+
CompilerInstance &DeviceInstance, CompilerInstance &HostInstance,
3332
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS,
3433
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs);
3534

36-
llvm::Expected<TranslationUnitDecl *> Parse(llvm::StringRef Input) override;
37-
3835
// Generate PTX for the last PTU.
3936
llvm::Expected<llvm::StringRef> GeneratePTX();
4037

@@ -44,7 +41,6 @@ class IncrementalCUDADeviceParser : public IncrementalParser {
4441
~IncrementalCUDADeviceParser();
4542

4643
protected:
47-
std::unique_ptr<CompilerInstance> DeviceCI;
4844
int SMVersion;
4945
llvm::SmallString<1024> PTXCode;
5046
llvm::SmallVector<char, 1024> FatbinContent;

clang/lib/Interpreter/IncrementalExecutor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class IncrementalExecutor {
5757
virtual llvm::Error removeModule(PartialTranslationUnit &PTU);
5858
virtual llvm::Error runCtors() const;
5959
virtual llvm::Error cleanUp();
60-
llvm::Expected<llvm::orc::ExecutorAddr>
60+
virtual llvm::Expected<llvm::orc::ExecutorAddr>
6161
getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
6262

6363
llvm::orc::LLJIT &GetExecutionEngine() { return *Jit; }

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/Support/VirtualFileSystem.h"
1919
#ifdef __EMSCRIPTEN__
2020
#include "Wasm.h"
21+
#include <dlfcn.h>
2122
#endif // __EMSCRIPTEN__
2223

2324
#include "clang/AST/ASTConsumer.h"
@@ -415,6 +416,10 @@ Interpreter::Interpreter(std::unique_ptr<CompilerInstance> Instance,
415416
Interpreter::~Interpreter() {
416417
IncrParser.reset();
417418
Act->FinalizeAction();
419+
if (DeviceParser)
420+
DeviceParser.reset();
421+
if (DeviceAct)
422+
DeviceAct->FinalizeAction();
418423
if (IncrExecutor) {
419424
if (llvm::Error Err = IncrExecutor->cleanUp())
420425
llvm::report_fatal_error(
@@ -480,20 +485,37 @@ Interpreter::createWithCUDA(std::unique_ptr<CompilerInstance> CI,
480485
OverlayVFS->pushOverlay(IMVFS);
481486
CI->createFileManager(OverlayVFS);
482487

483-
auto Interp = Interpreter::create(std::move(CI));
484-
if (auto E = Interp.takeError())
485-
return std::move(E);
488+
llvm::Expected<std::unique_ptr<Interpreter>> InterpOrErr =
489+
Interpreter::create(std::move(CI));
490+
if (!InterpOrErr)
491+
return InterpOrErr;
492+
493+
std::unique_ptr<Interpreter> Interp = std::move(*InterpOrErr);
486494

487495
llvm::Error Err = llvm::Error::success();
488-
auto DeviceParser = std::make_unique<IncrementalCUDADeviceParser>(
489-
std::move(DCI), *(*Interp)->getCompilerInstance(), IMVFS, Err,
490-
(*Interp)->PTUs);
496+
llvm::LLVMContext &LLVMCtx = *Interp->TSCtx->getContext();
497+
498+
auto DeviceAct =
499+
std::make_unique<IncrementalAction>(*DCI, LLVMCtx, Err, *Interp);
500+
491501
if (Err)
492502
return std::move(Err);
493503

494-
(*Interp)->DeviceParser = std::move(DeviceParser);
504+
Interp->DeviceAct = std::move(DeviceAct);
505+
506+
DCI->ExecuteAction(*Interp->DeviceAct);
507+
508+
Interp->DeviceCI = std::move(DCI);
509+
510+
auto DeviceParser = std::make_unique<IncrementalCUDADeviceParser>(
511+
*Interp->DeviceCI, *Interp->getCompilerInstance(), IMVFS, Err,
512+
Interp->PTUs);
513+
514+
if (Err)
515+
return std::move(Err);
495516

496-
return Interp;
517+
Interp->DeviceParser = std::move(DeviceParser);
518+
return std::move(Interp);
497519
}
498520

499521
const CompilerInstance *Interpreter::getCompilerInstance() const {
@@ -531,15 +553,17 @@ size_t Interpreter::getEffectivePTUSize() const {
531553

532554
PartialTranslationUnit &
533555
Interpreter::RegisterPTU(TranslationUnitDecl *TU,
534-
std::unique_ptr<llvm::Module> M /*={}*/) {
556+
std::unique_ptr<llvm::Module> M /*={}*/,
557+
IncrementalAction *Action) {
535558
PTUs.emplace_back(PartialTranslationUnit());
536559
PartialTranslationUnit &LastPTU = PTUs.back();
537560
LastPTU.TUPart = TU;
538561

539562
if (!M)
540-
M = GenModule();
563+
M = GenModule(Action);
541564

542-
assert((!getCodeGen() || M) && "Must have a llvm::Module at this point");
565+
assert((!getCodeGen(Action) || M) &&
566+
"Must have a llvm::Module at this point");
543567

544568
LastPTU.TheModule = std::move(M);
545569
LLVM_DEBUG(llvm::dbgs() << "compile-ptu " << PTUs.size() - 1
@@ -559,6 +583,16 @@ Interpreter::Parse(llvm::StringRef Code) {
559583
llvm::Expected<TranslationUnitDecl *> DeviceTU = DeviceParser->Parse(Code);
560584
if (auto E = DeviceTU.takeError())
561585
return std::move(E);
586+
587+
RegisterPTU(*DeviceTU, nullptr, DeviceAct.get());
588+
589+
llvm::Expected<llvm::StringRef> PTX = DeviceParser->GeneratePTX();
590+
if (!PTX)
591+
return PTX.takeError();
592+
593+
llvm::Error Err = DeviceParser->GenerateFatbinary();
594+
if (Err)
595+
return std::move(Err);
562596
}
563597

564598
// Tell the interpreter sliently ignore unused expressions since value
@@ -711,6 +745,14 @@ llvm::Error Interpreter::Undo(unsigned N) {
711745
}
712746

713747
llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
748+
#ifdef __EMSCRIPTEN__
749+
void *handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL);
750+
if (!handle) {
751+
llvm::errs() << dlerror() << '\n';
752+
return llvm::make_error<llvm::StringError>("Failed to load dynamic library",
753+
llvm::inconvertibleErrorCode());
754+
}
755+
#else
714756
auto EE = getExecutionEngine();
715757
if (!EE)
716758
return EE.takeError();
@@ -722,13 +764,15 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
722764
EE->getMainJITDylib().addGenerator(std::move(*DLSG));
723765
else
724766
return DLSG.takeError();
767+
#endif
725768

726769
return llvm::Error::success();
727770
}
728771

729-
std::unique_ptr<llvm::Module> Interpreter::GenModule() {
772+
std::unique_ptr<llvm::Module>
773+
Interpreter::GenModule(IncrementalAction *Action) {
730774
static unsigned ID = 0;
731-
if (CodeGenerator *CG = getCodeGen()) {
775+
if (CodeGenerator *CG = getCodeGen(Action)) {
732776
// Clang's CodeGen is designed to work with a single llvm::Module. In many
733777
// cases for convenience various CodeGen parts have a reference to the
734778
// llvm::Module (TheModule or Module) which does not change when a new
@@ -750,8 +794,10 @@ std::unique_ptr<llvm::Module> Interpreter::GenModule() {
750794
return nullptr;
751795
}
752796

753-
CodeGenerator *Interpreter::getCodeGen() const {
754-
FrontendAction *WrappedAct = Act->getWrapped();
797+
CodeGenerator *Interpreter::getCodeGen(IncrementalAction *Action) const {
798+
if (!Action)
799+
Action = Act.get();
800+
FrontendAction *WrappedAct = Action->getWrapped();
755801
if (!WrappedAct->hasIRSupport())
756802
return nullptr;
757803
return static_cast<CodeGenAction *>(WrappedAct)->getCodeGenerator();

0 commit comments

Comments
 (0)