[PATCH] D120132: [HIP] Fix HIP include path
Yaxun Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 18 07:20:52 PST 2022
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added subscribers: kerbowa, jvesely.
yaxunl requested review of this revision.
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,
when we know the path will be included anyway, we can skip adding it
to the list.
Patch by Cordell Bloor.
https://reviews.llvm.org/D120132
Files:
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/ROCm.h
Index: clang/lib/Driver/ToolChains/ROCm.h
===================================================================
--- clang/lib/Driver/ToolChains/ROCm.h
+++ clang/lib/Driver/ToolChains/ROCm.h
@@ -154,6 +154,8 @@
llvm::SmallString<0> findSPACKPackage(const Candidate &Cand,
StringRef PackageName);
+ static bool isStdlibIncludePath(StringRef PathString);
+
public:
RocmInstallationDetector(const Driver &D, const llvm::Triple &HostTriple,
const llvm::opt::ArgList &Args,
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -483,6 +483,14 @@
<< DetectedVersion << '\n';
}
+/*static*/ bool
+RocmInstallationDetector::isStdlibIncludePath(StringRef PathString) {
+ static const StringRef SystemDirs[] = {"/usr/local/include", "/usr/include"};
+
+ return std::find(std::begin(SystemDirs), std::end(SystemDirs), PathString) !=
+ std::end(SystemDirs);
+}
+
void RocmInstallationDetector::AddHIPIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
bool UsesRuntimeWrapper = VersionMajorMinor > llvm::VersionTuple(3, 5) &&
@@ -517,8 +525,12 @@
return;
}
- CC1Args.push_back("-internal-isystem");
- CC1Args.push_back(DriverArgs.MakeArgString(getIncludePath()));
+ const char *HipIncludePath = DriverArgs.MakeArgString(getIncludePath());
+ if (!isStdlibIncludePath(HipIncludePath) ||
+ DriverArgs.hasArg(options::OPT_nostdlibinc)) {
+ CC1Args.push_back("-internal-isystem");
+ CC1Args.push_back(HipIncludePath);
+ }
if (UsesRuntimeWrapper)
CC1Args.append({"-include", "__clang_hip_runtime_wrapper.h"});
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120132.409929.patch
Type: text/x-patch
Size: 1847 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220218/215e8230/attachment.bin>
More information about the cfe-commits
mailing list