@@ -1365,25 +1365,14 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
13651365 // Get the list of requested offloading toolchains. If they were not
13661366 // explicitly specified we will infer them based on the offloading language
13671367 // and requested architectures.
1368- llvm::StringMap<StringRef> FoundNormalizedTriples;
1369- auto isDuplicateTargetTripleString = [&](llvm::StringRef Target) -> bool {
1370- std::string NormalizedName =
1371- C.getDriver ().getSYCLDeviceTriple (Target).normalize ();
1372- auto [TripleIt, Inserted] =
1373- FoundNormalizedTriples.try_emplace (NormalizedName, Target);
1374- if (!Inserted) {
1375- Diag (clang::diag::warn_drv_offload_target_duplicate)
1376- << Target << TripleIt->second ;
1377- return true ;
1378- }
1379- return false ;
1380- };
13811368
13821369 std::multiset<llvm::StringRef> Triples;
1370+ llvm::StringMap<StringRef> FoundNormalizedTriples;
13831371 if (C.getInputArgs ().hasArg (options::OPT_offload_targets_EQ)) {
13841372 std::vector<std::string> ArgValues =
13851373 C.getInputArgs ().getAllArgValues (options::OPT_offload_targets_EQ);
13861374 llvm::Triple TT;
1375+
13871376 for (llvm::StringRef Target : ArgValues) {
13881377 if (IsSYCL) {
13891378 StringRef TargetTripleString (Target);
@@ -1393,14 +1382,20 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
13931382 TargetTripleString = " nvptx64-nvidia-cuda" ;
13941383 else if (Target.starts_with (" amd_gpu_" ))
13951384 TargetTripleString = " amdgcn-amd-amdhsa" ;
1396-
1397- // Check for duplicate target triple strings
1398- // before inserting in Triples.
1399- if (isDuplicateTargetTripleString (Target))
1385+ std::string NormalizedName =
1386+ getSYCLDeviceTriple (TargetTripleString).normalize ();
1387+ auto [TripleIt, Inserted] =
1388+ FoundNormalizedTriples.try_emplace (NormalizedName, Target);
1389+ if (!Inserted) {
1390+ if (Target == TripleIt->second )
1391+ Diag (clang::diag::warn_drv_offload_target_duplicate)
1392+ << Target << TripleIt->second ;
14001393 continue ;
1394+ }
14011395 Triples.insert (C.getInputArgs ().MakeArgString (TargetTripleString));
1402- } else
1396+ } else {
14031397 Triples.insert (C.getInputArgs ().MakeArgString (Target));
1398+ }
14041399 }
14051400
14061401 if (ArgValues.empty ())
@@ -1414,7 +1409,6 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
14141409 Triples.insert (Derived.begin (), Derived.end ());
14151410 }
14161411 }
1417-
14181412 FoundNormalizedTriples.clear ();
14191413 // Build an offloading toolchain for every requested target and kind.
14201414 for (StringRef Target : Triples) {
@@ -1458,10 +1452,15 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
14581452 Diag (diag::err_drv_invalid_or_unsupported_offload_target) << TT.str ();
14591453 continue ;
14601454 }
1461- // Check for duplicate target triple strings.
1462- if ((Kind == Action::OFK_OpenMP || Kind == Action::OFK_SYCL) &&
1463- isDuplicateTargetTripleString (Target))
1455+
1456+ std::string NormalizedName = TT.normalize ();
1457+ auto [TripleIt, Inserted] =
1458+ FoundNormalizedTriples.try_emplace (NormalizedName, Target);
1459+ if (!Inserted) {
1460+ Diag (clang::diag::warn_drv_offload_target_duplicate)
1461+ << Target << TripleIt->second ;
14641462 continue ;
1463+ }
14651464
14661465 auto &TC = getOffloadToolChain (C.getInputArgs (), Kind, TT,
14671466 C.getDefaultToolChain ().getTriple ());
0 commit comments