[clang] [clang-tidy] Fix assertion failure when processing CUDA files (PR #173762)

via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 27 23:58:57 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: mitchell (zeyi2)

<details>
<summary>Changes</summary>

Running clang-tidy on CUDA files without specifying `--cuda-host-only` or `--cuda-device-only` would trigger an assertion failure in `Actions.size() > 1`, a related discussion: https://github.com/llvm/llvm-project/pull/173699#discussion_r2649279975.

This occurred because the Clang Driver generates a single top-level `OffloadAction` in `-fsyntax-only` mode which clang-tidy uses. This commit removes the overly strict assertions.

---
Full diff: https://github.com/llvm/llvm-project/pull/173762.diff


1 Files Affected:

- (modified) clang/lib/Tooling/Tooling.cpp (+4-13) 


``````````diff
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index f10aa524674da..f19f2d36bb60e 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -102,19 +102,10 @@ static bool ignoreExtraCC1Commands(const driver::Compilation *Compilation) {
       if (isa<driver::BindArchAction>(A))
         A = *A->input_begin();
       if (isa<driver::OffloadAction>(A)) {
-        // Offload compilation has 2 top-level actions, one (at the front) is
-        // the original host compilation and the other is offload action
-        // composed of at least one device compilation. For such case, general
-        // tooling will consider host-compilation only. For tooling on device
-        // compilation, device compilation only option, such as
-        // `--cuda-device-only`, needs specifying.
-        assert(Actions.size() > 1);
-        assert(
-            isa<driver::CompileJobAction>(Actions.front()) ||
-            // On MacOSX real actions may end up being wrapped in
-            // BindArchAction.
-            (isa<driver::BindArchAction>(Actions.front()) &&
-             isa<driver::CompileJobAction>(*Actions.front()->input_begin())));
+        // For offload compilation, general tooling will consider host
+        // compilation only. For tooling on device compilation, device
+        // compilation only option, such as `--cuda-device-only`, needs
+        // specifying.
         OffloadCompilation = true;
         break;
       }

``````````

</details>


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


More information about the cfe-commits mailing list