@@ -950,13 +950,7 @@ 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-
958953 bool Wave64 = isWave64 (DriverArgs, Kind);
959-
960954 // TODO: There are way too many flags that change this. Do we need to check
961955 // them all?
962956 bool DAZ = DriverArgs.hasArg (options::OPT_cl_denorms_are_zero) ||
@@ -969,6 +963,12 @@ void ROCMToolChain::addClangTargetOptions(
969963 bool CorrectSqrt =
970964 DriverArgs.hasArg (options::OPT_cl_fp32_correctly_rounded_divide_sqrt);
971965
966+ // GPU Sanitizer currently only supports ASan and is enabled through host
967+ // ASan.
968+ bool GPUSan = DriverArgs.hasFlag (options::OPT_fgpu_sanitize,
969+ options::OPT_fno_gpu_sanitize, true ) &&
970+ getSanitizerArgs (DriverArgs).needsAsanRt ();
971+
972972 // Add the OpenCL specific bitcode library.
973973 llvm::SmallVector<BitCodeLibraryInfo, 12 > BCLibs;
974974 BCLibs.emplace_back (RocmInstallation->getOpenCLPath ().str ());
@@ -1009,30 +1009,25 @@ llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12>
10091009RocmInstallationDetector::getCommonBitcodeLibs (
10101010 const llvm::opt::ArgList &DriverArgs, StringRef LibDeviceFile, bool Wave64,
10111011 bool DAZ, bool FiniteOnly, bool UnsafeMathOpt, bool FastRelaxedMath,
1012- bool CorrectSqrt, DeviceLibABIVersion ABIVer,
1013- const std::tuple<bool , const SanitizerArgs> &GPUSan,
1014- bool isOpenMP = false ) const {
1012+ bool CorrectSqrt, DeviceLibABIVersion ABIVer, bool GPUSan,
1013+ bool isOpenMP) const {
10151014 llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12 > BCLibs;
10161015
1017- auto GPUSanEnabled = [GPUSan]() { return std::get<bool >(GPUSan); };
10181016 auto AddBCLib = [&](ToolChain::BitCodeLibraryInfo BCLib,
10191017 bool Internalize = true ) {
10201018 BCLib.ShouldInternalize = Internalize;
10211019 BCLibs.emplace_back (BCLib);
10221020 };
10231021 auto AddSanBCLibs = [&]() {
1024- if (GPUSanEnabled ()) {
1025- auto SanArgs = std::get<const SanitizerArgs>(GPUSan);
1026- if (SanArgs.needsAsanRt ())
1027- AddBCLib (getAsanRTLPath (), false );
1028- }
1022+ if (GPUSan)
1023+ AddBCLib (getAsanRTLPath (), false );
10291024 };
10301025
10311026 AddSanBCLibs ();
10321027 AddBCLib (getOCMLPath ());
10331028 if (!isOpenMP)
10341029 AddBCLib (getOCKLPath ());
1035- else if (GPUSanEnabled () && isOpenMP)
1030+ else if (GPUSan && isOpenMP)
10361031 AddBCLib (getOCKLPath (), false );
10371032 AddBCLib (getDenormalsAreZeroPath (DAZ));
10381033 AddBCLib (getUnsafeMathPath (UnsafeMathOpt || FastRelaxedMath));
@@ -1064,10 +1059,6 @@ ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
10641059 // If --hip-device-lib is not set, add the default bitcode libraries.
10651060 // TODO: There are way too many flags that change this. Do we need to check
10661061 // them all?
1067- std::tuple<bool , const SanitizerArgs> GPUSan (
1068- DriverArgs.hasFlag (options::OPT_fgpu_sanitize,
1069- options::OPT_fno_gpu_sanitize, false ),
1070- getSanitizerArgs (DriverArgs));
10711062 bool DAZ = DriverArgs.hasFlag (options::OPT_fgpu_flush_denormals_to_zero,
10721063 options::OPT_fno_gpu_flush_denormals_to_zero,
10731064 getDefaultDenormsAreZeroForTarget (Kind));
@@ -1083,6 +1074,12 @@ ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
10831074 options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt, true );
10841075 bool Wave64 = isWave64 (DriverArgs, Kind);
10851076
1077+ // GPU Sanitizer currently only supports ASan and is enabled through host
1078+ // ASan.
1079+ bool GPUSan = DriverArgs.hasFlag (options::OPT_fgpu_sanitize,
1080+ options::OPT_fno_gpu_sanitize, true ) &&
1081+ getSanitizerArgs (DriverArgs).needsAsanRt ();
1082+
10861083 return RocmInstallation->getCommonBitcodeLibs (
10871084 DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
10881085 FastRelaxedMath, CorrectSqrt, ABIVer, GPUSan, isOpenMP);
@@ -1095,11 +1092,12 @@ bool AMDGPUToolChain::shouldSkipSanitizeOption(
10951092 if (TargetID.empty ())
10961093 return false ;
10971094 Option O = A->getOption ();
1095+
10981096 if (!O.matches (options::OPT_fsanitize_EQ))
10991097 return false ;
11001098
11011099 if (!DriverArgs.hasFlag (options::OPT_fgpu_sanitize,
1102- options::OPT_fno_gpu_sanitize, false ))
1100+ options::OPT_fno_gpu_sanitize, true ))
11031101 return true ;
11041102
11051103 auto &Diags = TC.getDriver ().getDiags ();
0 commit comments