[clang] [llvm] Reland - [Driver][SYCL] Add initial SYCL offload compilation support … (PR #117268)

Tom Honermann via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 9 09:20:46 PST 2024


================
@@ -6591,6 +6681,18 @@ const ToolChain &Driver::getOffloadingDeviceToolChain(
                                                            HostTC, Args);
       break;
     }
+    case Action::OFK_SYCL:
+      switch (Target.getArch()) {
+      case llvm::Triple::spir:
+      case llvm::Triple::spir64:
+      case llvm::Triple::spirv32:
+      case llvm::Triple::spirv64:
+        TC = std::make_unique<toolchains::SYCLToolChain>(*this, Target, HostTC,
+                                                         Args);
+        break;
+      default:
+        break;
+      }
     default:
       break;
----------------
tahonermann wrote:

The `assert()` at that location happens too late. C++ doesn't acknowledge the possibility of a null reference and attempting to construct one results in undefined behavior. A conforming compiler is allowed to assume that taking the address of a reference results in a non-null pointer and may thus elide any actual check for null as an always-false condition; a compiler can therefore conclude that `HIPTC` is always non-null in `assert(HIPTC && ...)` without actually checking. The fix that is actually needed is to `assert(TC && "Could not create offloading device tool chain.")` below before the return of `*TC`. The `assert(HIPTC && ...)` and added `assert(SYCLTC && ...)` statements can then be removed.

https://github.com/llvm/llvm-project/pull/117268


More information about the llvm-commits mailing list