@@ -1366,25 +1366,14 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
13661366 // Get the list of requested offloading toolchains. If they were not
13671367 // explicitly specified we will infer them based on the offloading language
13681368 // and requested architectures.
1369- llvm::StringMap<StringRef> FoundNormalizedTriples;
1370- auto isDuplicateTargetTripleString = [&](llvm::StringRef Target) -> bool {
1371- std::string NormalizedName =
1372- C.getDriver ().getSYCLDeviceTriple (Target).normalize ();
1373- auto [TripleIt, Inserted] =
1374- FoundNormalizedTriples.try_emplace (NormalizedName, Target);
1375- if (!Inserted) {
1376- Diag (clang::diag::warn_drv_offload_target_duplicate)
1377- << Target << TripleIt->second ;
1378- return true ;
1379- }
1380- return false ;
1381- };
13821369
13831370 std::multiset<llvm::StringRef> Triples;
1371+ llvm::StringMap<StringRef> FoundNormalizedTriples;
13841372 if (C.getInputArgs ().hasArg (options::OPT_offload_targets_EQ)) {
13851373 std::vector<std::string> ArgValues =
13861374 C.getInputArgs ().getAllArgValues (options::OPT_offload_targets_EQ);
13871375 llvm::Triple TT;
1376+
13881377 for (llvm::StringRef Target : ArgValues) {
13891378 if (IsSYCL) {
13901379 StringRef TargetTripleString (Target);
@@ -1394,14 +1383,20 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
13941383 TargetTripleString = " nvptx64-nvidia-cuda" ;
13951384 else if (Target.starts_with (" amd_gpu_" ))
13961385 TargetTripleString = " amdgcn-amd-amdhsa" ;
1397-
1398- // Check for duplicate target triple strings
1399- // before inserting in Triples.
1400- if (isDuplicateTargetTripleString (Target))
1386+ std::string NormalizedName =
1387+ getSYCLDeviceTriple (TargetTripleString).normalize ();
1388+ auto [TripleIt, Inserted] =
1389+ FoundNormalizedTriples.try_emplace (NormalizedName, Target);
1390+ if (!Inserted) {
1391+ if (Target == TripleIt->second )
1392+ Diag (clang::diag::warn_drv_offload_target_duplicate)
1393+ << Target << TripleIt->second ;
14011394 continue ;
1395+ }
14021396 Triples.insert (C.getInputArgs ().MakeArgString (TargetTripleString));
1403- } else
1397+ } else {
14041398 Triples.insert (C.getInputArgs ().MakeArgString (Target));
1399+ }
14051400 }
14061401
14071402 if (ArgValues.empty ())
@@ -1415,7 +1410,6 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
14151410 Triples.insert (Derived.begin (), Derived.end ());
14161411 }
14171412 }
1418-
14191413 FoundNormalizedTriples.clear ();
14201414 // Build an offloading toolchain for every requested target and kind.
14211415 for (StringRef Target : Triples) {
@@ -1459,10 +1453,17 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
14591453 Diag (diag::err_drv_invalid_or_unsupported_offload_target) << TT.str ();
14601454 continue ;
14611455 }
1462- // Check for duplicate target triple strings.
1463- if ((Kind == Action::OFK_OpenMP || Kind == Action::OFK_SYCL) &&
1464- isDuplicateTargetTripleString (Target))
1465- continue ;
1456+
1457+ if (Kind == Action::OFK_OpenMP || Kind == Action::OFK_SYCL) {
1458+ std::string NormalizedName = TT.normalize ();
1459+ auto [TripleIt, Inserted] =
1460+ FoundNormalizedTriples.try_emplace (NormalizedName, Target);
1461+ if (!Inserted) {
1462+ Diag (clang::diag::warn_drv_offload_target_duplicate)
1463+ << Target << TripleIt->second ;
1464+ continue ;
1465+ }
1466+ }
14661467
14671468 auto &TC = getOffloadToolChain (C.getInputArgs (), Kind, TT,
14681469 C.getDefaultToolChain ().getTriple ());
0 commit comments