Skip to content

Commit b17f355

Browse files
committed
[Clang] Disable RTTI for offloading at the frontend level
Summary: Currently we force this to be off in `-cc1`, but I feel like this should be something the driver informs the compiler of. It's not *inconcievable* that RTTI might 'work' on the GPU some day, but mostly I just don't like having these kinds of checks hard-coded on a triple + language.
1 parent c4ed95c commit b17f355

File tree

7 files changed

+21
-17
lines changed

7 files changed

+21
-17
lines changed

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,10 +1065,7 @@ class CodeGenModule : public CodeGenTypeCache {
10651065

10661066
// Return whether RTTI information should be emitted for this target.
10671067
bool shouldEmitRTTI(bool ForEH = false) {
1068-
return (ForEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
1069-
!(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
1070-
(getTriple().isNVPTX() || getTriple().isAMDGPU() ||
1071-
getTriple().isSPIRV()));
1068+
return (ForEH || getLangOpts().RTTI);
10721069
}
10731070

10741071
/// Get the address of the RTTI descriptor for the given type.

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7117,6 +7117,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
71177117
}
71187118
}
71197119

7120+
// The offloading devices do not support RTTI.
7121+
if (IsCudaDevice || IsHIPDevice ||
7122+
(IsOpenMPDevice &&
7123+
(Triple.isNVPTX() || Triple.isAMDGCN() || Triple.isSPIRV()))) {
7124+
CmdArgs.push_back("-fno-rtti");
7125+
}
7126+
71207127
// Forward --no-offloadlib to -cc1.
71217128
if (!Args.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib, true))
71227129
CmdArgs.push_back("--no-offloadlib");

clang/test/CodeGenCUDA/device-vtable.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s \
1010
// RUN: | FileCheck %s -check-prefix=CHECK-HOST -check-prefix=CHECK-BOTH
11-
// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -emit-llvm -o - %s \
11+
// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -fno-rtti -emit-llvm -o - %s \
1212
// RUN: | FileCheck %s -check-prefix=CHECK-DEVICE -check-prefix=CHECK-BOTH
1313

1414
#include "Inputs/cuda.h"

clang/test/CodeGenCUDA/record-layout.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// RUN: cat %t | FileCheck --check-prefixes=CHECK,HOST %s
44
// RUN: %clang_cc1 -fcuda-is-device -triple amdgcn-amd-amdhsa -target-cpu gfx1100 \
55
// RUN: -emit-llvm -fdump-record-layouts -aux-triple x86_64-pc-windows-msvc \
6-
// RUN: -o %t -xhip %s | FileCheck %s --check-prefix=AST
6+
// RUN: -fno-rtti -o %t -xhip %s | FileCheck %s --check-prefix=AST
77
// RUN: cat %t | FileCheck --check-prefixes=CHECK,DEV %s
88

99
#include "Inputs/cuda.h"

clang/test/Driver/openmp-offload-gpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226

227227
// verify the tools invocations
228228
// CHECK: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-emit-llvm-bc"{{.*}}"-x" "c"
229-
// CHECK: "-cc1" "-triple" "nvptx64-nvidia-cuda" "-aux-triple" "x86_64-unknown-linux-gnu"{{.*}}"-target-cpu" "sm_52"
229+
// CHECK: "-cc1" "-triple" "nvptx64-nvidia-cuda" "-aux-triple" "x86_64-unknown-linux-gnu"{{.*}}"-target-cpu" "sm_52"{{.*}}"-fno-rtti"
230230
// CHECK: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-emit-obj"
231231
// CHECK: clang-linker-wrapper{{.*}} "-o" "a.out"
232232

clang/test/Headers/hip-header.hip

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,47 @@
33
// RUN: -internal-isystem %S/../../lib/Headers/cuda_wrappers \
44
// RUN: -internal-isystem %S/Inputs/include \
55
// RUN: -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
6-
// RUN: -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
6+
// RUN: -target-cpu gfx906 -emit-llvm %s -fno-rtti -fcuda-is-device -o - \
77
// RUN: -D__HIPCC_RTC__ | FileCheck -check-prefixes=CHECK,NOMALLOC %s
88
// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
99
// RUN: -internal-isystem %S/../../lib/Headers/cuda_wrappers \
1010
// RUN: -internal-isystem %S/Inputs/include \
1111
// RUN: -include cmath \
1212
// RUN: -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
13-
// RUN: -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
13+
// RUN: -target-cpu gfx906 -emit-llvm %s -fno-rtti -fcuda-is-device -o - \
1414
// RUN: -D__HIPCC_RTC__ | FileCheck %s -check-prefixes=AMD_BOOL_RETURN
1515
// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
1616
// RUN: -internal-isystem %S/../../lib/Headers/cuda_wrappers \
1717
// RUN: -internal-isystem %S/Inputs/include \
1818
// RUN: -include cmath \
1919
// RUN: -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
20-
// RUN: -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
20+
// RUN: -target-cpu gfx906 -emit-llvm %s -fno-rtti -fcuda-is-device -o - \
2121
// RUN: -D__HIPCC_RTC__ -DUSE_ISNAN_WITH_INT_RETURN | FileCheck %s -check-prefixes=AMD_INT_RETURN
2222
// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
2323
// RUN: -internal-isystem %S/../../lib/Headers/cuda_wrappers \
2424
// RUN: -internal-isystem %S/Inputs/include \
2525
// RUN: -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
26-
// RUN: -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
26+
// RUN: -target-cpu gfx906 -emit-llvm %s -fno-rtti -fcuda-is-device -o - \
2727
// RUN: -D__HIPCC_RTC__ -std=c++14 | FileCheck -check-prefixes=CHECK,CXX14 %s
2828
// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
2929
// RUN: -internal-isystem %S/../../lib/Headers/cuda_wrappers \
3030
// RUN: -internal-isystem %S/Inputs/include \
3131
// RUN: -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
32-
// RUN: -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
32+
// RUN: -target-cpu gfx906 -emit-llvm %s -fno-rtti -fcuda-is-device -o - \
3333
// RUN: -DHIP_VERSION_MAJOR=4 -DHIP_VERSION_MINOR=5 \
3434
// RUN: -D__HIPCC_RTC__ -disable-llvm-passes | FileCheck -check-prefixes=MALLOC %s
3535
// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
3636
// RUN: -internal-isystem %S/../../lib/Headers/cuda_wrappers \
3737
// RUN: -internal-isystem %S/Inputs/include \
3838
// RUN: -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
39-
// RUN: -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
39+
// RUN: -target-cpu gfx906 -emit-llvm %s -fno-rtti -fcuda-is-device -o - \
4040
// RUN: -DHIP_VERSION_MAJOR=4 -DHIP_VERSION_MINOR=5 \
4141
// RUN: -disable-llvm-passes | FileCheck -check-prefixes=MALLOC %s
4242
// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
4343
// RUN: -internal-isystem %S/../../lib/Headers/cuda_wrappers \
4444
// RUN: -internal-isystem %S/Inputs/include \
4545
// RUN: -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
46-
// RUN: -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
46+
// RUN: -target-cpu gfx906 -emit-llvm %s -fno-rtti -fcuda-is-device -o - \
4747
// RUN: -DHIP_VERSION_MAJOR=4 -DHIP_VERSION_MINOR=5 \
4848
// RUN: -fsanitize=address -disable-llvm-passes -D__HIPCC_RTC__ \
4949
// RUN: | FileCheck -check-prefixes=MALLOC-ASAN %s

clang/test/OpenMP/nvptx_target_pure_deleted_codegen.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Test target codegen - host bc file has to be created first.
22
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
3-
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-target-device -fvisibility=protected -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
3+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fno-rtti -fopenmp-is-target-device -fvisibility=protected -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
44
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
5-
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-target-device -fvisibility=protected -fopenmp-host-ir-file-path %t-x86-host.bc -o - -fno-rtti | FileCheck %s
6-
// RUN: %clang_cc1 -verify -fopenmp -fexceptions -fcxx-exceptions -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-target-device -fvisibility=protected -fopenmp-host-ir-file-path %t-x86-host.bc -o - -fno-rtti | FileCheck %s
5+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fno-rtti -fopenmp-is-target-device -fvisibility=protected -fopenmp-host-ir-file-path %t-x86-host.bc -o - -fno-rtti | FileCheck %s
6+
// RUN: %clang_cc1 -verify -fopenmp -fexceptions -fcxx-exceptions -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fno-rtti -fopenmp-is-target-device -fvisibility=protected -fopenmp-host-ir-file-path %t-x86-host.bc -o - -fno-rtti | FileCheck %s
77
// expected-no-diagnostics
88

99
#ifndef HEADER

0 commit comments

Comments
 (0)