@@ -950,6 +950,11 @@ void ROCMToolChain::addClangTargetOptions(
950950 ABIVer))
951951 return ;
952952
953+ std::tuple<bool , const SanitizerArgs> GPUSan (
954+ DriverArgs.hasFlag (options::OPT_fgpu_sanitize,
955+ options::OPT_fno_gpu_sanitize, true ),
956+ getSanitizerArgs (DriverArgs));
957+
953958 bool Wave64 = isWave64 (DriverArgs, Kind);
954959
955960 // TODO: There are way too many flags that change this. Do we need to check
@@ -965,21 +970,19 @@ void ROCMToolChain::addClangTargetOptions(
965970 DriverArgs.hasArg (options::OPT_cl_fp32_correctly_rounded_divide_sqrt);
966971
967972 // Add the OpenCL specific bitcode library.
968- llvm::SmallVector<std::string , 12 > BCLibs;
969- BCLibs.push_back (RocmInstallation->getOpenCLPath ().str ());
973+ llvm::SmallVector<BitCodeLibraryInfo , 12 > BCLibs;
974+ BCLibs.emplace_back (RocmInstallation->getOpenCLPath ().str ());
970975
971976 // Add the generic set of libraries.
972977 BCLibs.append (RocmInstallation->getCommonBitcodeLibs (
973978 DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
974- FastRelaxedMath, CorrectSqrt, ABIVer, false ));
979+ FastRelaxedMath, CorrectSqrt, ABIVer, GPUSan, false ));
975980
976- if (getSanitizerArgs (DriverArgs).needsAsanRt ()) {
977- CC1Args.push_back (" -mlink-bitcode-file" );
978- CC1Args.push_back (
979- DriverArgs.MakeArgString (RocmInstallation->getAsanRTLPath ()));
980- }
981- for (StringRef BCFile : BCLibs) {
982- CC1Args.push_back (" -mlink-builtin-bitcode" );
981+ for (auto [BCFile, Internalize] : BCLibs) {
982+ if (Internalize)
983+ CC1Args.push_back (" -mlink-builtin-bitcode" );
984+ else
985+ CC1Args.push_back (" -mlink-bitcode-file" );
983986 CC1Args.push_back (DriverArgs.MakeArgString (BCFile));
984987 }
985988}
@@ -1002,18 +1005,35 @@ bool RocmInstallationDetector::checkCommonBitcodeLibs(
10021005 return true ;
10031006}
10041007
1005- llvm::SmallVector<std::string , 12 >
1008+ llvm::SmallVector<ToolChain::BitCodeLibraryInfo , 12 >
10061009RocmInstallationDetector::getCommonBitcodeLibs (
10071010 const llvm::opt::ArgList &DriverArgs, StringRef LibDeviceFile, bool Wave64,
10081011 bool DAZ, bool FiniteOnly, bool UnsafeMathOpt, bool FastRelaxedMath,
1009- bool CorrectSqrt, DeviceLibABIVersion ABIVer, bool isOpenMP = false ) const {
1010- llvm::SmallVector<std::string, 12 > BCLibs;
1011-
1012- auto AddBCLib = [&](StringRef BCFile) { BCLibs.push_back (BCFile.str ()); };
1012+ bool CorrectSqrt, DeviceLibABIVersion ABIVer,
1013+ const std::tuple<bool , const SanitizerArgs> &GPUSan,
1014+ bool isOpenMP = false ) const {
1015+ llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12 > BCLibs;
1016+
1017+ auto GPUSanEnabled = [GPUSan]() { return std::get<bool >(GPUSan); };
1018+ auto AddBCLib = [&](ToolChain::BitCodeLibraryInfo BCLib,
1019+ bool Internalize = true ) {
1020+ BCLib.ShouldInternalize = Internalize;
1021+ BCLibs.emplace_back (BCLib);
1022+ };
1023+ auto AddSanBCLibs = [&]() {
1024+ if (GPUSanEnabled ()) {
1025+ auto SanArgs = std::get<const SanitizerArgs>(GPUSan);
1026+ if (SanArgs.needsAsanRt ())
1027+ AddBCLib (getAsanRTLPath (), false );
1028+ }
1029+ };
10131030
1031+ AddSanBCLibs ();
10141032 AddBCLib (getOCMLPath ());
10151033 if (!isOpenMP)
10161034 AddBCLib (getOCKLPath ());
1035+ else if (GPUSanEnabled () && isOpenMP)
1036+ AddBCLib (getOCKLPath (), false );
10171037 AddBCLib (getDenormalsAreZeroPath (DAZ));
10181038 AddBCLib (getUnsafeMathPath (UnsafeMathOpt || FastRelaxedMath));
10191039 AddBCLib (getFiniteOnlyPath (FiniteOnly || FastRelaxedMath));
@@ -1027,7 +1047,7 @@ RocmInstallationDetector::getCommonBitcodeLibs(
10271047 return BCLibs;
10281048}
10291049
1030- llvm::SmallVector<std::string , 12 >
1050+ llvm::SmallVector<ToolChain::BitCodeLibraryInfo , 12 >
10311051ROCMToolChain::getCommonDeviceLibNames (const llvm::opt::ArgList &DriverArgs,
10321052 const std::string &GPUArch,
10331053 bool isOpenMP) const {
@@ -1044,6 +1064,10 @@ ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
10441064 // If --hip-device-lib is not set, add the default bitcode libraries.
10451065 // TODO: There are way too many flags that change this. Do we need to check
10461066 // them all?
1067+ std::tuple<bool , const SanitizerArgs> GPUSan (
1068+ DriverArgs.hasFlag (options::OPT_fgpu_sanitize,
1069+ options::OPT_fno_gpu_sanitize, true ),
1070+ getSanitizerArgs (DriverArgs));
10471071 bool DAZ = DriverArgs.hasFlag (options::OPT_fgpu_flush_denormals_to_zero,
10481072 options::OPT_fno_gpu_flush_denormals_to_zero,
10491073 getDefaultDenormsAreZeroForTarget (Kind));
@@ -1061,7 +1085,7 @@ ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
10611085
10621086 return RocmInstallation->getCommonBitcodeLibs (
10631087 DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
1064- FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
1088+ FastRelaxedMath, CorrectSqrt, ABIVer, GPUSan, isOpenMP);
10651089}
10661090
10671091bool AMDGPUToolChain::shouldSkipSanitizeOption (
0 commit comments