[clang-tools-extra] [clang-tidy] Add documentation and smoke test for CUDA (PR #173699)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 26 20:30:28 PST 2025
https://github.com/zeyi2 created https://github.com/llvm/llvm-project/pull/173699
Closes #173677
>From 1fe8fff7fdf129c117d86d4bac19c877032b5f3d Mon Sep 17 00:00:00 2001
From: mtx <mitchell.xu2 at gmail.com>
Date: Sat, 27 Dec 2025 12:12:09 +0800
Subject: [PATCH] [clang-tidy] Add documentation and smoke test for CUDA
---
clang-tools-extra/docs/clang-tidy/index.rst | 14 ++++++++++++++
.../test/clang-tidy/infrastructure/basic-cuda.cu | 9 +++++++++
2 files changed, 23 insertions(+)
create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/basic-cuda.cu
diff --git a/clang-tools-extra/docs/clang-tidy/index.rst b/clang-tools-extra/docs/clang-tidy/index.rst
index 34da529902308..38aabc77540cf 100644
--- a/clang-tools-extra/docs/clang-tidy/index.rst
+++ b/clang-tools-extra/docs/clang-tidy/index.rst
@@ -349,6 +349,20 @@ An overview of all the command-line options:
some-check.SomeOption: 'some value'
...
+Running Clang-Tidy on CUDA Files
+--------------------------------
+
+:program:`clang-tidy` supports analyzing CUDA source files.
+To correctly process host-side code, specify the CUDA toolkit path using
+``--cuda-path`` and limit compilation to the host with ``--cuda-host-only``.
+
+.. code-block:: console
+
+ $ clang-tidy source.cu -- --cuda-path=/path/to/cuda --cuda-host-only
+
+Using ``--cuda-host-only`` is recommended as it skips device-side compilation,
+speeding up the analysis and avoiding potential device-specific errors.
+
Clang-Tidy Automation
=====================
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/basic-cuda.cu b/clang-tools-extra/test/clang-tidy/infrastructure/basic-cuda.cu
new file mode 100644
index 0000000000000..3bc605d864461
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/basic-cuda.cu
@@ -0,0 +1,9 @@
+// RUN: clang-tidy %s -checks='-*,modernize-use-nullptr' -- -nocudainc -nocudalib --cuda-host-only | FileCheck %s
+
+#define __global__ __attribute__((global))
+
+// CHECK: :[[@LINE+1]]:38: warning: use nullptr [modernize-use-nullptr]
+__global__ void kernel(int *p) { p = 0; }
+
+// CHECK: :[[@LINE+1]]:11: warning: use nullptr [modernize-use-nullptr]
+void *p = 0;
More information about the cfe-commits
mailing list