Skip to content

Commit adaa343

Browse files
authored
Merge branch 'release/20.x' into release_20_x_zt0_fix
2 parents 7a51bac + be4097b commit adaa343

File tree

21 files changed

+279
-94
lines changed

21 files changed

+279
-94
lines changed

clang/include/clang/Interpreter/Interpreter.h

+9-4
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;
@@ -175,10 +179,11 @@ class Interpreter {
175179
llvm::Expected<Expr *> ExtractValueFromExpr(Expr *E);
176180
llvm::Expected<llvm::orc::ExecutorAddr> CompileDtorCall(CXXRecordDecl *CXXRD);
177181

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

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

clang/lib/Interpreter/DeviceOffload.cpp

+15-30
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,17 @@ IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
3131
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs)
3232
: IncrementalParser(*DeviceInstance, Err), PTUs(PTUs), VFS(FS),
3333
CodeGenOpts(HostInstance.getCodeGenOpts()),
34-
TargetOpts(HostInstance.getTargetOpts()) {
34+
TargetOpts(DeviceInstance->getTargetOpts()) {
3535
if (Err)
3636
return;
37-
DeviceCI = std::move(DeviceInstance);
3837
StringRef Arch = TargetOpts.CPU;
3938
if (!Arch.starts_with("sm_") || Arch.substr(3).getAsInteger(10, SMVersion)) {
4039
Err = llvm::joinErrors(std::move(Err), llvm::make_error<llvm::StringError>(
4140
"Invalid CUDA architecture",
4241
llvm::inconvertibleErrorCode()));
4342
return;
4443
}
45-
}
46-
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;
44+
DeviceCI = std::move(DeviceInstance);
7345
}
7446

7547
llvm::Expected<llvm::StringRef> IncrementalCUDADeviceParser::GeneratePTX() {
@@ -172,6 +144,19 @@ llvm::Error IncrementalCUDADeviceParser::GenerateFatbinary() {
172144

173145
FatbinContent.append(PTXCode.begin(), PTXCode.end());
174146

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

clang/lib/Interpreter/DeviceOffload.h

-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class IncrementalCUDADeviceParser : public IncrementalParser {
3333
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS,
3434
llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs);
3535

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

clang/lib/Interpreter/IncrementalExecutor.h

+1-1
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

+54-15
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"
@@ -480,20 +481,34 @@ Interpreter::createWithCUDA(std::unique_ptr<CompilerInstance> CI,
480481
OverlayVFS->pushOverlay(IMVFS);
481482
CI->createFileManager(OverlayVFS);
482483

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

487491
llvm::Error Err = llvm::Error::success();
488-
auto DeviceParser = std::make_unique<IncrementalCUDADeviceParser>(
489-
std::move(DCI), *(*Interp)->getCompilerInstance(), IMVFS, Err,
490-
(*Interp)->PTUs);
492+
llvm::LLVMContext &LLVMCtx = *Interp->TSCtx->getContext();
493+
494+
auto DeviceAct =
495+
std::make_unique<IncrementalAction>(*DCI, LLVMCtx, Err, *Interp);
496+
491497
if (Err)
492498
return std::move(Err);
493499

494-
(*Interp)->DeviceParser = std::move(DeviceParser);
500+
Interp->DeviceAct = std::move(DeviceAct);
501+
502+
DCI->ExecuteAction(*Interp->DeviceAct);
503+
504+
auto DeviceParser = std::make_unique<IncrementalCUDADeviceParser>(
505+
std::move(DCI), *Interp->getCompilerInstance(), IMVFS, Err, Interp->PTUs);
506+
507+
if (Err)
508+
return std::move(Err);
495509

496-
return Interp;
510+
Interp->DeviceParser = std::move(DeviceParser);
511+
return std::move(Interp);
497512
}
498513

499514
const CompilerInstance *Interpreter::getCompilerInstance() const {
@@ -531,15 +546,17 @@ size_t Interpreter::getEffectivePTUSize() const {
531546

532547
PartialTranslationUnit &
533548
Interpreter::RegisterPTU(TranslationUnitDecl *TU,
534-
std::unique_ptr<llvm::Module> M /*={}*/) {
549+
std::unique_ptr<llvm::Module> M /*={}*/,
550+
IncrementalAction *Action) {
535551
PTUs.emplace_back(PartialTranslationUnit());
536552
PartialTranslationUnit &LastPTU = PTUs.back();
537553
LastPTU.TUPart = TU;
538554

539555
if (!M)
540-
M = GenModule();
556+
M = GenModule(Action);
541557

542-
assert((!getCodeGen() || M) && "Must have a llvm::Module at this point");
558+
assert((!getCodeGen(Action) || M) &&
559+
"Must have a llvm::Module at this point");
543560

544561
LastPTU.TheModule = std::move(M);
545562
LLVM_DEBUG(llvm::dbgs() << "compile-ptu " << PTUs.size() - 1
@@ -559,6 +576,16 @@ Interpreter::Parse(llvm::StringRef Code) {
559576
llvm::Expected<TranslationUnitDecl *> DeviceTU = DeviceParser->Parse(Code);
560577
if (auto E = DeviceTU.takeError())
561578
return std::move(E);
579+
580+
RegisterPTU(*DeviceTU, nullptr, DeviceAct.get());
581+
582+
llvm::Expected<llvm::StringRef> PTX = DeviceParser->GeneratePTX();
583+
if (!PTX)
584+
return PTX.takeError();
585+
586+
llvm::Error Err = DeviceParser->GenerateFatbinary();
587+
if (Err)
588+
return std::move(Err);
562589
}
563590

564591
// Tell the interpreter sliently ignore unused expressions since value
@@ -711,6 +738,14 @@ llvm::Error Interpreter::Undo(unsigned N) {
711738
}
712739

713740
llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
741+
#ifdef __EMSCRIPTEN__
742+
void *handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL);
743+
if (!handle) {
744+
llvm::errs() << dlerror() << '\n';
745+
return llvm::make_error<llvm::StringError>("Failed to load dynamic library",
746+
llvm::inconvertibleErrorCode());
747+
}
748+
#else
714749
auto EE = getExecutionEngine();
715750
if (!EE)
716751
return EE.takeError();
@@ -722,13 +757,15 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char *name) {
722757
EE->getMainJITDylib().addGenerator(std::move(*DLSG));
723758
else
724759
return DLSG.takeError();
760+
#endif
725761

726762
return llvm::Error::success();
727763
}
728764

729-
std::unique_ptr<llvm::Module> Interpreter::GenModule() {
765+
std::unique_ptr<llvm::Module>
766+
Interpreter::GenModule(IncrementalAction *Action) {
730767
static unsigned ID = 0;
731-
if (CodeGenerator *CG = getCodeGen()) {
768+
if (CodeGenerator *CG = getCodeGen(Action)) {
732769
// Clang's CodeGen is designed to work with a single llvm::Module. In many
733770
// cases for convenience various CodeGen parts have a reference to the
734771
// llvm::Module (TheModule or Module) which does not change when a new
@@ -750,8 +787,10 @@ std::unique_ptr<llvm::Module> Interpreter::GenModule() {
750787
return nullptr;
751788
}
752789

753-
CodeGenerator *Interpreter::getCodeGen() const {
754-
FrontendAction *WrappedAct = Act->getWrapped();
790+
CodeGenerator *Interpreter::getCodeGen(IncrementalAction *Action) const {
791+
if (!Action)
792+
Action = Act.get();
793+
FrontendAction *WrappedAct = Action->getWrapped();
755794
if (!WrappedAct->hasIRSupport())
756795
return nullptr;
757796
return static_cast<CodeGenAction *>(WrappedAct)->getCodeGenerator();

clang/lib/Interpreter/Wasm.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@ llvm::Error WasmIncrementalExecutor::cleanUp() {
144144
return llvm::Error::success();
145145
}
146146

147+
llvm::Expected<llvm::orc::ExecutorAddr>
148+
WasmIncrementalExecutor::getSymbolAddress(llvm::StringRef Name,
149+
SymbolNameKind NameKind) const {
150+
void *Sym = dlsym(RTLD_DEFAULT, Name.str().c_str());
151+
if (!Sym) {
152+
return llvm::make_error<llvm::StringError>("dlsym failed for symbol: " +
153+
Name.str(),
154+
llvm::inconvertibleErrorCode());
155+
}
156+
157+
return llvm::orc::ExecutorAddr::fromPtr(Sym);
158+
}
159+
147160
WasmIncrementalExecutor::~WasmIncrementalExecutor() = default;
148161

149162
} // namespace clang

clang/lib/Interpreter/Wasm.h

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class WasmIncrementalExecutor : public IncrementalExecutor {
2929
llvm::Error removeModule(PartialTranslationUnit &PTU) override;
3030
llvm::Error runCtors() const override;
3131
llvm::Error cleanUp() override;
32+
llvm::Expected<llvm::orc::ExecutorAddr>
33+
getSymbolAddress(llvm::StringRef Name,
34+
SymbolNameKind NameKind) const override;
3235

3336
~WasmIncrementalExecutor() override;
3437
};

clang/lib/Parse/ParseExpr.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -2237,8 +2237,6 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
22372237
if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
22382238
RunSignatureHelp();
22392239
LHS = ExprError();
2240-
} else if (!HasError && HasTrailingComma) {
2241-
Diag(Tok, diag::err_expected_expression);
22422240
} else if (LHS.isInvalid()) {
22432241
for (auto &E : ArgExprs)
22442242
Actions.CorrectDelayedTyposInExpr(E);
@@ -3738,7 +3736,6 @@ bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
37383736
if (Tok.is(tok::r_paren)) {
37393737
if (HasTrailingComma)
37403738
*HasTrailingComma = true;
3741-
break;
37423739
}
37433740
}
37443741
if (SawError) {

clang/test/Parser/recovery.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,21 @@ void k() {
222222
func(1, ); // expected-error {{expected expression}}
223223
}
224224
}
225+
226+
namespace GH136254 {
227+
228+
void call() {
229+
[a(42, )]() {} (); // expected-error {{expected expression}}
230+
231+
int *b = new int(42, ); // expected-error {{expected expression}}
232+
233+
struct S {
234+
int c;
235+
236+
S() : c(42, ) {} // expected-error {{expected expression}}
237+
};
238+
239+
int d(42, ); // expected-error {{expected expression}}
240+
}
241+
242+
}

cmake/Modules/LLVMVersion.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if(NOT DEFINED LLVM_VERSION_MINOR)
77
set(LLVM_VERSION_MINOR 1)
88
endif()
99
if(NOT DEFINED LLVM_VERSION_PATCH)
10-
set(LLVM_VERSION_PATCH 4)
10+
set(LLVM_VERSION_PATCH 5)
1111
endif()
1212
if(NOT DEFINED LLVM_VERSION_SUFFIX)
1313
set(LLVM_VERSION_SUFFIX)

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array.pass.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// ADDITIONAL_COMPILE_FLAGS(apple-clang-17): -fsized-deallocation
1818
// ADDITIONAL_COMPILE_FLAGS(target=x86_64-w64-windows-gnu): -fsized-deallocation
1919
// ADDITIONAL_COMPILE_FLAGS(target=i686-w64-windows-gnu): -fsized-deallocation
20+
// ADDITIONAL_COMPILE_FLAGS(target=aarch64-w64-windows-gnu): -fsized-deallocation
21+
// ADDITIONAL_COMPILE_FLAGS(target=armv7-w64-windows-gnu): -fsized-deallocation
2022

2123
// Android clang-r536225 identifies as clang-19.0 but it predates the real
2224
// LLVM 19.0.0, so it also leaves sized deallocation off by default.

libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete.pass.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// ADDITIONAL_COMPILE_FLAGS(apple-clang-17): -fsized-deallocation
1818
// ADDITIONAL_COMPILE_FLAGS(target=x86_64-w64-windows-gnu): -fsized-deallocation
1919
// ADDITIONAL_COMPILE_FLAGS(target=i686-w64-windows-gnu): -fsized-deallocation
20+
// ADDITIONAL_COMPILE_FLAGS(target=aarch64-w64-windows-gnu): -fsized-deallocation
21+
// ADDITIONAL_COMPILE_FLAGS(target=armv7-w64-windows-gnu): -fsized-deallocation
2022

2123
// Android clang-r536225 identifies as clang-19.0 but it predates the real
2224
// LLVM 19.0.0, so it also leaves sized deallocation off by default.

lldb/tools/lldb-server/lldb-platform.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
3232
#include "lldb/Host/ConnectionFileDescriptor.h"
3333
#include "lldb/Host/HostGetOpt.h"
34+
#include "lldb/Host/HostInfo.h"
3435
#include "lldb/Host/MainLoop.h"
3536
#include "lldb/Host/OptionParser.h"
3637
#include "lldb/Host/Socket.h"
@@ -256,8 +257,9 @@ static void client_handle(GDBRemoteCommunicationServerPlatform &platform,
256257
printf("Disconnected.\n");
257258
}
258259

259-
static Status spawn_process(const char *progname, const Socket *conn_socket,
260-
uint16_t gdb_port, const lldb_private::Args &args,
260+
static Status spawn_process(const char *progname, const FileSpec &prog,
261+
const Socket *conn_socket, uint16_t gdb_port,
262+
const lldb_private::Args &args,
261263
const std::string &log_file,
262264
const StringRef log_channels, MainLoop &main_loop) {
263265
Status error;
@@ -267,9 +269,10 @@ static Status spawn_process(const char *progname, const Socket *conn_socket,
267269

268270
ProcessLaunchInfo launch_info;
269271

270-
FileSpec self_spec(progname, FileSpec::Style::native);
271-
launch_info.SetExecutableFile(self_spec, true);
272+
launch_info.SetExecutableFile(prog, false);
273+
launch_info.SetArg0(progname);
272274
Args &self_args = launch_info.GetArguments();
275+
self_args.AppendArgument(progname);
273276
self_args.AppendArgument(llvm::StringRef("platform"));
274277
self_args.AppendArgument(llvm::StringRef("--child-platform-fd"));
275278
self_args.AppendArgument(llvm::to_string(shared_socket.GetSendableFD()));
@@ -551,9 +554,10 @@ int main_platform(int argc, char *argv[]) {
551554
log_channels, &main_loop,
552555
&platform_handles](std::unique_ptr<Socket> sock_up) {
553556
printf("Connection established.\n");
554-
Status error = spawn_process(progname, sock_up.get(),
555-
gdbserver_port, inferior_arguments,
556-
log_file, log_channels, main_loop);
557+
Status error = spawn_process(
558+
progname, HostInfo::GetProgramFileSpec(), sock_up.get(),
559+
gdbserver_port, inferior_arguments, log_file, log_channels,
560+
main_loop);
557561
if (error.Fail()) {
558562
Log *log = GetLog(LLDBLog::Platform);
559563
LLDB_LOGF(log, "spawn_process failed: %s", error.AsCString());

0 commit comments

Comments
 (0)