@@ -618,6 +618,7 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
618618 // For DG2, we just use libsycl-msan as placeholder.
619619 {" libsycl-msan" , " internal" },
620620 {" libsycl-msan-pvc" , " internal" }};
621+ const SYCLDeviceLibsList SYCLDeviceTsanLibs = {{" libsycl-tsan" , " internal" }};
621622#endif
622623
623624 const SYCLDeviceLibsList SYCLNativeCpuDeviceLibs = {
@@ -758,8 +759,9 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
758759 SyclFEEQArgVals.end ());
759760 ArgVals.insert (ArgVals.end (), ArchDeviceVals.begin (), ArchDeviceVals.end ());
760761
761- // Driver will report error if address sanitizer and memory sanitizer are
762- // both enabled, so we only need to check first one here.
762+ // Driver will report error if more than one of address sanitizer, memory
763+ // sanitizer or thread sanitizer is enabled, so we only need to check first
764+ // one here.
763765 for (const std::string &Arg : ArgVals) {
764766 if (Arg.find (" -fsanitize=address" ) != std::string::npos) {
765767 SanitizeVal = " address" ;
@@ -769,13 +771,19 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
769771 SanitizeVal = " memory" ;
770772 break ;
771773 }
774+ if (Arg.find (" -fsanitize=thread" ) != std::string::npos) {
775+ SanitizeVal = " thread" ;
776+ break ;
777+ }
772778 }
773779 }
774780
775781 if (SanitizeVal == " address" )
776782 addSingleLibrary (SYCLDeviceAsanLibs[sanitizer_lib_idx]);
777783 else if (SanitizeVal == " memory" )
778784 addSingleLibrary (SYCLDeviceMsanLibs[sanitizer_lib_idx]);
785+ else if (SanitizeVal == " thread" )
786+ addLibraries (SYCLDeviceTsanLibs);
779787#endif
780788
781789 if (isNativeCPU)
@@ -898,6 +906,7 @@ static llvm::SmallVector<StringRef, 16> SYCLDeviceLibList{
898906 " msan" ,
899907 " msan-pvc" ,
900908 " msan-cpu" ,
909+ " tsan" ,
901910#endif
902911 " imf" ,
903912 " imf-fp64" ,
@@ -1739,11 +1748,12 @@ SYCLToolChain::SYCLToolChain(const Driver &D, const llvm::Triple &Triple,
17391748 if (SupportedByNativeCPU (*this , Opt))
17401749 continue ;
17411750 // All sanitizer options are not currently supported, except
1742- // AddressSanitizer and MemorySanitizer
1751+ // AddressSanitizer and MemorySanitizer and ThreadSanitizer
17431752 if (A->getOption ().getID () == options::OPT_fsanitize_EQ &&
17441753 A->getValues ().size () == 1 ) {
17451754 std::string SanitizeVal = A->getValue ();
1746- if (SanitizeVal == " address" || SanitizeVal == " memory" )
1755+ if (SanitizeVal == " address" || SanitizeVal == " memory" ||
1756+ SanitizeVal == " thread" )
17471757 continue ;
17481758 }
17491759 D.Diag (clang::diag::warn_drv_unsupported_option_for_target)
@@ -1784,7 +1794,8 @@ SYCLToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
17841794 if (Opt.getID () == options::OPT_fsanitize_EQ &&
17851795 A->getValues ().size () == 1 ) {
17861796 std::string SanitizeVal = A->getValue ();
1787- if (SanitizeVal == " address" || SanitizeVal == " memory" ) {
1797+ if (SanitizeVal == " address" || SanitizeVal == " memory" ||
1798+ SanitizeVal == " thread" ) {
17881799 if (IsNewDAL)
17891800 DAL->append (A);
17901801 continue ;
@@ -2202,5 +2213,5 @@ void SYCLToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &Args,
22022213}
22032214
22042215SanitizerMask SYCLToolChain::getSupportedSanitizers () const {
2205- return SanitizerKind::Address | SanitizerKind::Memory;
2216+ return SanitizerKind::Address | SanitizerKind::Memory | SanitizerKind::Thread ;
22062217}
0 commit comments