[clang] [clang-repl] : Fix clang-repl crash with --cuda flag (PR #136404)
Vassil Vassilev via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 19 10:55:49 PDT 2025
================
@@ -451,13 +451,44 @@ const char *const Runtimes = R"(
)";
llvm::Expected<std::unique_ptr<Interpreter>>
-Interpreter::create(std::unique_ptr<CompilerInstance> CI) {
+Interpreter::create(std::unique_ptr<CompilerInstance> CI,
+ std::unique_ptr<CompilerInstance> DeviceCI) {
llvm::Error Err = llvm::Error::success();
auto Interp =
std::unique_ptr<Interpreter>(new Interpreter(std::move(CI), Err));
if (Err)
return std::move(Err);
+ if (DeviceCI) {
+ // auto DeviceLLVMCtx = std::make_unique<llvm::LLVMContext>();
+ // auto DeviceTSCtx =
+ // std::make_unique<llvm::orc::ThreadSafeContext>(std::move(DeviceLLVMCtx));
+
+ // llvm::Error DeviceErr = llvm::Error::success();
+ // llvm::ErrorAsOutParameter EAO(&DeviceErr);
+
+ // auto DeviceAct = std::make_unique<IncrementalAction>(
+ // *DeviceCI, *DeviceTSCtx->getContext(), DeviceErr, *Interp);
+
+ // if (DeviceErr)
+ // return std::move(DeviceErr);
+
+ // DeviceCI->ExecuteAction(*DeviceAct);
+ DeviceCI->ExecuteAction(*Interp->Act);
----------------
vgvassilev wrote:
With this patch I get:
```
llvm-build $ ./bin/clang-repl --cuda
clang-repl: /home/vvassilev/workspace/sources/llvm-project/clang/lib/Frontend/FrontendAction.cpp:743: bool clang::FrontendAction::BeginSourceFile(clang::CompilerInstance&, const clang::FrontendInputFile&): Assertion `!Instance && "Already processing a source file!"' failed.
#0 0x00007ffff46daba8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/vvassilev/workspace/sources/llvm-project/llvm/lib/Support/Unix/Signals.inc:804:22
#1 0x00007ffff46dafc9 PrintStackTraceSignalHandler(void*) /home/vvassilev/workspace/sources/llvm-project/llvm/lib/Support/Unix/Signals.inc:880:1
#2 0x00007ffff46d83f7 llvm::sys::RunSignalHandlers() /home/vvassilev/workspace/sources/llvm-project/llvm/lib/Support/Signals.cpp:105:20
#3 0x00007ffff46da417 SignalHandler(int, siginfo_t*, void*) /home/vvassilev/workspace/sources/llvm-project/llvm/lib/Support/Unix/Signals.inc:418:13
#4 0x00007ffff3f73520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x00007ffff3fc79fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#6 0x00007ffff3fc79fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#7 0x00007ffff3fc79fc pthread_kill ./nptl/pthread_kill.c:89:10
#8 0x00007ffff3f73476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#9 0x00007ffff3f597f3 abort ./stdlib/abort.c:81:7
#10 0x00007ffff3f5971b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#11 0x00007ffff3f6ae96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#12 0x00007ffff65f58c3 clang::FrontendAction::BeginSourceFile(clang::CompilerInstance&, clang::FrontendInputFile const&) /home/vvassilev/workspace/sources/llvm-project/clang/lib/Frontend/FrontendAction.cpp:744:3
#13 0x00007ffff64e15c2 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/vvassilev/workspace/sources/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1055:5
#14 0x00007ffff7b50a59 clang::Interpreter::create(std::unique_ptr<clang::CompilerInstance, std::default_delete<clang::CompilerInstance>>, std::unique_ptr<clang::CompilerInstance, std::default_delete<clang::CompilerInstance>>) /home/vvassilev/workspace/sources/llvm-project/clang/lib/Interpreter/Interpreter.cpp:466:56
#15 0x00007ffff7b50e40 clang::Interpreter::createWithCUDA(std::unique_ptr<clang::CompilerInstance, std::default_delete<clang::CompilerInstance>>, std::unique_ptr<clang::CompilerInstance, std::default_delete<clang::CompilerInstance>>) /home/vvassilev/workspace/sources/llvm-project/clang/lib/Interpreter/Interpreter.cpp:501:59
#16 0x000055555555a8e0 main /home/vvassilev/workspace/sources/llvm-project/clang/tools/clang-repl/ClangRepl.cpp:208:23
#17 0x00007ffff3f5ad90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#18 0x00007ffff3f5ae40 call_init ./csu/../csu/libc-start.c:128:20
#19 0x00007ffff3f5ae40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#20 0x0000555555559925 _start (./bin/clang-repl+0x5925)
Aborted (core dumped)
```
https://github.com/llvm/llvm-project/pull/136404
More information about the cfe-commits
mailing list