@@ -555,6 +555,7 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
555555 {" libsycl-asan-cpu" , " internal" },
556556 {" libsycl-asan-dg2" , " internal" },
557557 {" libsycl-asan-pvc" , " internal" }};
558+ const SYCLDeviceLibsList SYCLDeviceMsanLibs = {{" libsycl-msan" , " internal" }};
558559#endif
559560
560561 const SYCLDeviceLibsList SYCLNativeCpuDeviceLibs = {
@@ -670,12 +671,15 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
670671 };
671672
672673 std::string SanitizeVal;
674+ std::string SanitizeArg;
673675 size_t sanitizer_lib_idx = getSingleBuildTarget ();
674676 if (Arg *A = Args.getLastArg (options::OPT_fsanitize_EQ,
675677 options::OPT_fno_sanitize_EQ)) {
676678 if (A->getOption ().matches (options::OPT_fsanitize_EQ) &&
677- A->getValues ().size () == 1 )
679+ A->getValues ().size () == 1 ) {
678680 SanitizeVal = A->getValue ();
681+ SanitizeArg = A->getAsString (Args);
682+ }
679683 } else {
680684 // User can pass -fsanitize=address to device compiler via
681685 // -Xsycl-target-frontend, sanitize device library must be
@@ -699,14 +703,21 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
699703 for (const std::string &Arg : ArgVals) {
700704 if (Arg.find (" -fsanitize=address" ) != std::string::npos) {
701705 SanitizeVal = " address" ;
706+ SanitizeArg = Arg;
707+ break ;
708+ }
709+ if (Arg.find (" -fsanitize=memory" ) != std::string::npos) {
710+ SanitizeVal = " memory" ;
711+ SanitizeArg = Arg;
702712 break ;
703713 }
704714 }
705715 }
706716
707717 if (SanitizeVal == " address" )
708718 addSingleLibrary (SYCLDeviceAsanLibs[sanitizer_lib_idx]);
709-
719+ else if (SanitizeVal == " memory" )
720+ addLibraries (SYCLDeviceMsanLibs);
710721#endif
711722
712723 if (isNativeCPU)
@@ -826,6 +837,7 @@ static llvm::SmallVector<StringRef, 16> SYCLDeviceLibList{
826837 " asan-pvc" ,
827838 " asan-cpu" ,
828839 " asan-dg2" ,
840+ " msan" ,
829841#endif
830842 " imf" ,
831843 " imf-fp64" ,
@@ -1665,11 +1677,11 @@ SYCLToolChain::SYCLToolChain(const Driver &D, const llvm::Triple &Triple,
16651677 if (SupportedByNativeCPU (*this , Opt))
16661678 continue ;
16671679 // All sanitizer options are not currently supported, except
1668- // AddressSanitizer
1680+ // AddressSanitizer and MemorySanitizer
16691681 if (A->getOption ().getID () == options::OPT_fsanitize_EQ &&
16701682 A->getValues ().size () == 1 ) {
16711683 std::string SanitizeVal = A->getValue ();
1672- if (SanitizeVal == " address" )
1684+ if (SanitizeVal == " address" || SanitizeVal == " memory " )
16731685 continue ;
16741686 }
16751687 D.Diag (clang::diag::warn_drv_unsupported_option_for_target)
@@ -1710,7 +1722,7 @@ SYCLToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
17101722 if (Opt.getID () == options::OPT_fsanitize_EQ &&
17111723 A->getValues ().size () == 1 ) {
17121724 std::string SanitizeVal = A->getValue ();
1713- if (SanitizeVal == " address" ) {
1725+ if (SanitizeVal == " address" || SanitizeVal == " memory " ) {
17141726 if (IsNewDAL)
17151727 DAL->append (A);
17161728 continue ;
@@ -2119,5 +2131,5 @@ void SYCLToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &Args,
21192131}
21202132
21212133SanitizerMask SYCLToolChain::getSupportedSanitizers () const {
2122- return SanitizerKind::Address;
2134+ return SanitizerKind::Address | SanitizerKind::Memory ;
21232135}
0 commit comments