[clang] [clang-repl] : Fix clang-repl crash with --cuda flag (PR #136404)
Anutosh Bhat via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 24 06:08:34 PDT 2025
================
@@ -28,20 +28,21 @@ IncrementalCUDADeviceParser::IncrementalCUDADeviceParser(
std::unique_ptr<CompilerInstance> DeviceInstance,
CompilerInstance &HostInstance,
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS,
- llvm::Error &Err, const std::list<PartialTranslationUnit> &PTUs)
+ llvm::Error &Err, std::list<PartialTranslationUnit> &PTUs)
: IncrementalParser(*DeviceInstance, Err), PTUs(PTUs), VFS(FS),
CodeGenOpts(HostInstance.getCodeGenOpts()),
- TargetOpts(HostInstance.getTargetOpts()) {
+ TargetOpts(DeviceInstance->getTargetOpts()) {
----------------
anutosh491 wrote:
`TargetOpts` should be fetched from `DeviceInstance` rather than `HostInstance`
This can be seen even through the cc1 command generated through createCI (skipping some flags)
```
// FOR THE DEVICE (Skipping lot of flags just keeping the main ones)
"/Users/anutosh491/work/llvm-project/build2/bin/clang-repl" -cc1 -triple nvptx64-nvidia-cuda -aux-triple arm64-apple-darwin24.3.0 ....... -aux-target-cpu apple-m1 ........ -target-cpu sm_35 -target-feature ...... --offload-new-driver -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -fincremental-extensions -cuid=6c8ca225f780e660 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o "/var/folders/m1/cdn74f917994jd99d_2cpf440000gn/T/<<< inputs >>>-sm_35-14d471.s" -x cuda "<<< inputs >>>"
"ptxas" -m64 -O0 -v --gpu-name sm_35 --output-file "<<< inputs >>>-cuda-nvptx64-nvidia-cuda-sm_35.o" "/var/folders/m1/cdn74f917994jd99d_2cpf440000gn/T/<<< inputs >>>-sm_35-14d471.s"
```
As seen `-target-cpu sm_35` so the check below with regards to the `Arch` doesn't even make sense if we use it from the host side.
`if (!Arch.starts_with("sm_") || Arch.substr(3).getAsInteger(10, SMVersion)) {`
https://github.com/llvm/llvm-project/pull/136404
More information about the cfe-commits
mailing list