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"}); } 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,