@@ -658,43 +658,44 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
658658 addLibraries (SYCLDeviceAnnotationLibs);
659659
660660#if !defined(_WIN32)
661+ std::string SanitizeVal;
661662 size_t sanitizer_lib_idx = getSingleBuildTarget ();
662663 if (Arg *A = Args.getLastArg (options::OPT_fsanitize_EQ,
663664 options::OPT_fno_sanitize_EQ)) {
664665 if (A->getOption ().matches (options::OPT_fsanitize_EQ) &&
665- A->getValues ().size () == 1 ) {
666- std::string SanitizeVal = A->getValue ();
667- if (SanitizeVal == " address" )
668- addSingleLibrary (SYCLDeviceAsanLibs[sanitizer_lib_idx]);
669- }
666+ A->getValues ().size () == 1 )
667+ SanitizeVal = A->getValue ();
670668 } else {
671669 // User can pass -fsanitize=address to device compiler via
672670 // -Xsycl-target-frontend, sanitize device library must be
673671 // linked with user's device image if so.
674- bool IsDeviceAsanEnabled = false ;
675- auto SyclFEArg = Args.getAllArgValues (options::OPT_Xsycl_frontend);
676- IsDeviceAsanEnabled = (std::count (SyclFEArg.begin (), SyclFEArg.end (),
677- " -fsanitize=address" ) > 0 );
678- if (!IsDeviceAsanEnabled) {
679- auto SyclFEArgEq = Args.getAllArgValues (options::OPT_Xsycl_frontend_EQ);
680- IsDeviceAsanEnabled = (std::count (SyclFEArgEq.begin (), SyclFEArgEq.end (),
681- " -fsanitize=address" ) > 0 );
682- }
683-
684- // User can also enable asan for SYCL device via -Xarch_device option.
685- if (!IsDeviceAsanEnabled) {
686- auto DeviceArchVals = Args.getAllArgValues (options::OPT_Xarch_device);
687- for (auto DArchVal : DeviceArchVals) {
688- if (DArchVal.find (" -fsanitize=address" ) != std::string::npos) {
689- IsDeviceAsanEnabled = true ;
690- break ;
691- }
672+ std::vector<std::string> EnabledDeviceSanitizers;
673+
674+ // NOTE: "-fsanitize=" applies to all device targets
675+ auto SyclFEArgVals = Args.getAllArgValues (options::OPT_Xsycl_frontend);
676+ auto SyclFEEQArgVals = Args.getAllArgValues (options::OPT_Xsycl_frontend_EQ);
677+ auto ArchDeviceVals = Args.getAllArgValues (options::OPT_Xarch_device);
678+
679+ std::vector<std::string> ArgVals (
680+ SyclFEArgVals.size () + SyclFEEQArgVals.size () + ArchDeviceVals.size ());
681+ ArgVals.insert (ArgVals.end (), SyclFEArgVals.begin (), SyclFEArgVals.end ());
682+ ArgVals.insert (ArgVals.end (), SyclFEEQArgVals.begin (),
683+ SyclFEEQArgVals.end ());
684+ ArgVals.insert (ArgVals.end (), ArchDeviceVals.begin (), ArchDeviceVals.end ());
685+
686+ // Driver will report error if address sanitizer and memory sanitizer are
687+ // both enabled, so we only need to check first one here.
688+ for (const std::string &Arg : ArgVals) {
689+ if (Arg.find (" -fsanitize=address" ) != std::string::npos) {
690+ SanitizeVal = " address" ;
691+ break ;
692692 }
693693 }
694-
695- if (IsDeviceAsanEnabled)
696- addSingleLibrary (SYCLDeviceAsanLibs[sanitizer_lib_idx]);
697694 }
695+
696+ if (SanitizeVal == " address" )
697+ addSingleLibrary (SYCLDeviceAsanLibs[sanitizer_lib_idx]);
698+
698699#endif
699700
700701 if (isNativeCPU)
@@ -1617,6 +1618,23 @@ static std::vector<OptSpecifier> getUnsupportedOpts(void) {
16171618 return UnsupportedOpts;
16181619}
16191620
1621+ // Currently supported options by SYCL NativeCPU device compilation
1622+ static inline bool SupportedByNativeCPU (const SYCLToolChain &TC,
1623+ const OptSpecifier &Opt) {
1624+ if (!TC.IsSYCLNativeCPU )
1625+ return false ;
1626+
1627+ switch (Opt.getID ()) {
1628+ case options::OPT_fcoverage_mapping:
1629+ case options::OPT_fno_coverage_mapping:
1630+ case options::OPT_fprofile_instr_generate:
1631+ case options::OPT_fprofile_instr_generate_EQ:
1632+ case options::OPT_fno_profile_instr_generate:
1633+ return true ;
1634+ }
1635+ return false ;
1636+ }
1637+
16201638SYCLToolChain::SYCLToolChain (const Driver &D, const llvm::Triple &Triple,
16211639 const ToolChain &HostTC, const ArgList &Args)
16221640 : ToolChain(D, Triple, Args), HostTC(HostTC),
@@ -1628,6 +1646,9 @@ SYCLToolChain::SYCLToolChain(const Driver &D, const llvm::Triple &Triple,
16281646 // Diagnose unsupported options only once.
16291647 for (OptSpecifier Opt : getUnsupportedOpts ()) {
16301648 if (const Arg *A = Args.getLastArg (Opt)) {
1649+ // Native CPU can support options unsupported by other targets.
1650+ if (SupportedByNativeCPU (*this , Opt))
1651+ continue ;
16311652 // All sanitizer options are not currently supported, except
16321653 // AddressSanitizer
16331654 if (A->getOption ().getID () == options::OPT_fsanitize_EQ &&
@@ -1668,6 +1689,9 @@ SYCLToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
16681689 bool Unsupported = false ;
16691690 for (OptSpecifier UnsupportedOpt : getUnsupportedOpts ()) {
16701691 if (Opt.matches (UnsupportedOpt)) {
1692+ // NativeCPU should allow most normal cpu options.
1693+ if (SupportedByNativeCPU (*this , Opt.getID ()))
1694+ continue ;
16711695 if (Opt.getID () == options::OPT_fsanitize_EQ &&
16721696 A->getValues ().size () == 1 ) {
16731697 std::string SanitizeVal = A->getValue ();
0 commit comments