[clang] 592abf2 - [Driver] BuildOffloadingActions: Actually stabilize iteration order

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 28 11:06:34 PDT 2024


Author: Fangrui Song
Date: 2024-06-28T11:06:29-07:00
New Revision: 592abf29f9f7f73e6be28bef4574172125e4ab3f

URL: https://github.com/llvm/llvm-project/commit/592abf29f9f7f73e6be28bef4574172125e4ab3f
DIFF: https://github.com/llvm/llvm-project/commit/592abf29f9f7f73e6be28bef4574172125e4ab3f.diff

LOG: [Driver] BuildOffloadingActions: Actually stabilize iteration order

In
```
/tmp/StaticDebug/bin/clang -ccc-print-phases -lsomelib -fopenmp=libomp --target=powerpc64-ibm-linux-gnu -fopenmp-targets=x86_64-pc-linux-gnu,powerpc64-ibm-linux-gnu clang/test/Driver/openmp-offload.c clang/test/Driver/openmp-offload.c
```

Both ToolChains have one single empty arch. llvm::sort in
LLVM_ENABLE_EXPENSIVE_CHECKS=on builds could swap the two entries.

Fixes: 255986e27fcf9f0b36f7a23fbe030fcca1ba0249

Added: 
    

Modified: 
    clang/lib/Driver/Driver.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 8fa8673b0fd69..6314bc5d61071 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4597,10 +4597,13 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
 
     // Get the product of all bound architectures and toolchains.
     SmallVector<std::pair<const ToolChain *, StringRef>> TCAndArchs;
-    for (const ToolChain *TC : ToolChains)
-      for (StringRef Arch : getOffloadArchs(C, Args, Kind, TC))
+    for (const ToolChain *TC : ToolChains) {
+      llvm::DenseSet<StringRef> Arches = getOffloadArchs(C, Args, Kind, TC);
+      SmallVector<StringRef, 0> Sorted(Arches.begin(), Arches.end());
+      llvm::sort(Sorted);
+      for (StringRef Arch : Sorted)
         TCAndArchs.push_back(std::make_pair(TC, Arch));
-    llvm::sort(TCAndArchs, llvm::less_second());
+    }
 
     for (unsigned I = 0, E = TCAndArchs.size(); I != E; ++I)
       DeviceActions.push_back(C.MakeAction<InputAction>(*InputArg, InputType));


        


More information about the cfe-commits mailing list