Skip to content

Commit 6730b44

Browse files
committed
[HIP] Fix HIP include path
The clang compiler prepends the HIP header include paths to the search list using -internal-isystem when building for the HIP language. This prevents warnings related to things like reserved identifiers when including the HIP headers even when ROCm is installed in a non-system directory, such as /opt/rocm. However, when HIP is installed in /usr, then the prepended include path would be /usr/include. That is a problem, because the C standard library headers are stored in /usr/include and the C++ standard library headers must come before the C library headers in the search path list (because the C++ standard library headers use #include_next to include the C standard library headers). While the HIP wrapper headers _do_ need to be earlier in the search than the C++ headers, those headers get their own subdirectory and their own explicit -internal-isystem argument. This include path is for <hip/hip_runtime_api.h> and <hip/hip_runtime.h>, which do not require a particular search ordering with respect to the C or C++ headers. Thus, HIP include path is added after other system include paths. With contribution from Cordell Bloor. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D120132
1 parent 9066a88 commit 6730b44

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ void RocmInstallationDetector::AddHIPIncludeArgs(const ArgList &DriverArgs,
517517
return;
518518
}
519519

520-
CC1Args.push_back("-internal-isystem");
520+
CC1Args.push_back("-idirafter");
521521
CC1Args.push_back(DriverArgs.MakeArgString(getIncludePath()));
522522
if (UsesRuntimeWrapper)
523523
CC1Args.append({"-include", "__clang_hip_runtime_wrapper.h"});

clang/test/Driver/hip-include-path.hip

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@
1919
// COMMON-LABEL: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
2020
// CLANG-SAME: "-internal-isystem" "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include/cuda_wrappers"
2121
// NOCLANG-NOT: "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include/cuda_wrappers"
22-
// HIP-SAME: "-internal-isystem" "{{[^"]*}}Inputs/rocm/include"
23-
// NOHIP-NOT: "{{.*}}Inputs/rocm/include"
22+
// HIP-SAME: "-idirafter" "{{[^"]*}}Inputs/rocm/include"
2423
// HIP-SAME: "-include" "__clang_hip_runtime_wrapper.h"
2524
// NOHIP-NOT: "-include" "__clang_hip_runtime_wrapper.h"
2625
// skip check of standard C++ include path
2726
// CLANG-SAME: "-internal-isystem" "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include"
2827
// NOCLANG-NOT: "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include"
28+
// NOHIP-NOT: "{{.*}}Inputs/rocm/include"
2929

3030
// COMMON-LABEL: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
3131
// CLANG-SAME: "-internal-isystem" "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include/cuda_wrappers"
3232
// NOCLANG-NOT: "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include/cuda_wrappers"
33-
// HIP-SAME: "-internal-isystem" "{{[^"]*}}Inputs/rocm/include"
34-
// NOHIP-NOT: "{{.*}}Inputs/rocm/include"
33+
// HIP-SAME: "-idirafter" "{{[^"]*}}Inputs/rocm/include"
3534
// HIP-SAME: "-include" "__clang_hip_runtime_wrapper.h"
3635
// NOHIP-NOT: "-include" "__clang_hip_runtime_wrapper.h"
3736
// skip check of standard C++ include path
3837
// CLANG-SAME: "-internal-isystem" "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include"
3938
// NOCLANG-NOT: "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include"
39+
// NOHIP-NOT: "{{.*}}Inputs/rocm/include"
4040

4141
// RUN: %clang -c -### -target x86_64-unknown-linux-gnu --cuda-gpu-arch=gfx900 \
4242
// RUN: -std=c++11 --rocm-path=%S/Inputs/rocm -nogpulib %s 2>&1 \
@@ -45,7 +45,7 @@
4545
// ROCM35-LABEL: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
4646
// ROCM35-NOT: "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include/cuda_wrappers"
4747
// ROCM35-SAME: "-internal-isystem" "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}"
48-
// ROCM35-SAME: "-internal-isystem" "{{[^"]*}}Inputs/rocm/include"
48+
// ROCM35-SAME: "-idirafter" "{{[^"]*}}Inputs/rocm/include"
4949
// ROCM35-NOT: "-include" "__clang_hip_runtime_wrapper.h"
5050
// skip check of standard C++ include path
5151
// ROCM35-SAME: "-internal-isystem" "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include"

clang/test/Driver/rocm-detect.hip

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
// SPACK: Found HIP installation: [[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
9191
// SPACK: "-triple" "amdgcn-amd-amdhsa"
9292
// SPACK-SAME: "-mlink-builtin-bitcode" "[[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/hip.bc"
93-
// SPACK-SAME: "-internal-isystem" "[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
93+
// SPACK-SAME: "-idirafter" "[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
9494

9595
// SPACK-MULT: InstalledDir: [[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
9696
// SPACK-MULT-DAG: Cannot use SPACK package hip-4.0.0 at [[DIR]] due to multiple installations for the same version
@@ -101,12 +101,12 @@
101101
// SPACK-SET: Found HIP installation: [[DIR]]/hip-4.0.0-abcd, version 4.0.20214-a2917cd
102102
// SPACK-SET: "-triple" "amdgcn-amd-amdhsa"
103103
// SPACK-SET-SAME: "-mlink-builtin-bitcode" "[[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/hip.bc"
104-
// SPACK-SET-SAME: "-internal-isystem" "[[DIR]]/hip-4.0.0-abcd/include"
104+
// SPACK-SET-SAME: "-idirafter" "[[DIR]]/hip-4.0.0-abcd/include"
105105

106106
// SPACK-MISS: InstalledDir: [[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
107107
// SPACK-MISS-DAG: SPACK package hip-4.0.0 not found at [[DIR]]
108108
// SPACK-MISS-NOT: Found HIP installation: [[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
109-
// SPACK-MISS-NOT: "-internal-isystem" "[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
109+
// SPACK-MISS-NOT: "-idirafter" "[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
110110

111111
// SPACK-MISS-SILENT-NOT: SPACK package hip-{{.*}} not found at
112112
// SPACK-MISS-SILENT-NOT: Found HIP installation

0 commit comments

Comments
 (0)