Index: clang/lib/Driver/ToolChains/Linux.cpp =================================================================== --- clang/lib/Driver/ToolChains/Linux.cpp +++ clang/lib/Driver/ToolChains/Linux.cpp @@ -681,11 +681,11 @@ void Linux::AddHIPRuntimeLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { + // HIP needs compiler-rt for _Float16 conversion functions. CmdArgs.append( {Args.MakeArgString(StringRef("-L") + RocmInstallation.getLibPath()), - "-rpath", Args.MakeArgString(RocmInstallation.getLibPath())}); - - CmdArgs.push_back("-lamdhip64"); + "-rpath", Args.MakeArgString(RocmInstallation.getLibPath()), + "-lamdhip64", Args.MakeArgString(getCompilerRT(Args, "builtins"))}); } void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs, Index: clang/lib/Driver/ToolChains/MSVC.cpp =================================================================== --- clang/lib/Driver/ToolChains/MSVC.cpp +++ clang/lib/Driver/ToolChains/MSVC.cpp @@ -479,9 +479,11 @@ void MSVCToolChain::AddHIPRuntimeLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { + // HIP needs compiler-rt for _Float16 conversion functions. CmdArgs.append({Args.MakeArgString(StringRef("-libpath:") + RocmInstallation.getLibPath()), - "amdhip64.lib"}); + "amdhip64.lib", + Args.MakeArgString(getCompilerRT(Args, "builtins"))}); } void MSVCToolChain::printVerboseInfo(raw_ostream &OS) const { Index: clang/test/Driver/hip-runtime-libs-linux.hip =================================================================== --- clang/test/Driver/hip-runtime-libs-linux.hip +++ clang/test/Driver/hip-runtime-libs-linux.hip @@ -2,15 +2,19 @@ // RUN: touch %t.o +// Get compiler-rt library full path. +// RUN: %clang -target x86_64-linux-gnu -rtlib=compiler-rt \ +// RUN: -print-libgcc-file-name >%t.1 + // Test HIP runtime lib args specified by --rocm-path. // RUN: %clang -### --hip-link -target x86_64-linux-gnu \ -// RUN: --rocm-path=%S/Inputs/rocm %t.o 2>&1 \ -// RUN: | FileCheck -check-prefixes=ROCM-PATH %s +// RUN: --rocm-path=%S/Inputs/rocm %t.o >%t.2 2>&1 +// RUN: cat %t.1 %t.2 | FileCheck -check-prefixes=ROCM-PATH,COMMON %s // Test HIP runtime lib args specified by environment variable ROCM_PATH. // RUN: env ROCM_PATH=%S/Inputs/rocm %clang -### --hip-link \ -// RUN: -target x86_64-linux-gnu %t.o 2>&1 \ -// RUN: | FileCheck -check-prefixes=ROCM-PATH %s +// RUN: -target x86_64-linux-gnu %t.o >%t.2 2>&1 +// RUN: cat %t.1 %t.2 | FileCheck -check-prefixes=ROCM-PATH,COMMON %s // Test detecting latest /opt/rocm-{release} directory. // RUN: rm -rf %T/opt @@ -18,8 +22,8 @@ // RUN: cp -r %S/Inputs/rocm %T/opt/rocm-3.9.0-1234 // RUN: cp -r %S/Inputs/rocm %T/opt/rocm-3.10.0 // RUN: %clang -### --hip-link -target x86_64-linux-gnu \ -// RUN: --sysroot=%T %t.o 2>&1 \ -// RUN: | FileCheck -check-prefixes=ROCM-REL %s +// RUN: --sysroot=%T %t.o >%t.2 2>&1 +// RUN: cat %t.1 %t.2 | FileCheck -check-prefixes=ROCM-REL,COMMON %s // Test HIP runtime lib is not linked without --hip-link. // RUN: %clang -### -target x86_64-linux-gnu \ @@ -36,8 +40,12 @@ // RUN: --rocm-path=%S/Inputs/rocm %t.o 2>&1 \ // RUN: | FileCheck -check-prefixes=NOHIPRT %s +// COMMON: [[COMPILER_RT:/.*/libclang_rt\.builtins.*]] // ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64" // ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64" +// COMMON-SAME: "[[COMPILER_RT]]" + // NOHIPRT-NOT: "-L{{.*/Inputs/rocm/lib}}" // NOHIPRT-NOT: "-rpath" "{{.*/Inputs/rocm/lib}}" // NOHIPRT-NOT: "-lamdhip64" +// NOHIPRT-NOT: "{{/[^"]*clang_rt\.builtins[^"]*}}" Index: clang/test/Driver/hip-runtime-libs-msvc.hip =================================================================== --- clang/test/Driver/hip-runtime-libs-msvc.hip +++ clang/test/Driver/hip-runtime-libs-msvc.hip @@ -2,9 +2,15 @@ // RUN: touch %t.o +// Get compiler-rt library full path. +// RUN: %clang -target x86_64-pc-windows-msvc -rtlib=compiler-rt \ +// RUN: -print-libgcc-file-name >%t.1 + // Test HIP runtime lib args specified by --rocm-path. // RUN: %clang -### --hip-link -target x86_64-pc-windows-msvc \ -// RUN: --rocm-path=%S/Inputs/rocm %t.o 2>&1 \ -// RUN: | FileCheck %s +// RUN: --rocm-path=%S/Inputs/rocm %t.o >%t.2 2>&1 +// RUN: cat %t.1 %t.2 | FileCheck %s +// CHECK: [[COMPILER_RT:.*clang_rt\.builtins.*]] // CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib" +// CHECK-SAME: "[[COMPILER_RT]]"