https://github.com/LuoYuanke created https://github.com/llvm/llvm-project/pull/244791
nvcc accepts both `#pragma unroll N` and `#pragma unroll (N)` and generates identical code, and the CUDA C++ Programming Guide documents the parenthesized form. Assisted-By Claude >From e7c5e2548182ccf17a546996331f784224b5aaa9 Mon Sep 17 00:00:00 2001 From: Yuanke Luo <[email protected]> Date: Fri, 20 Nov 2026 17:13:05 +0800 Subject: [PATCH] Remove parenthesized #pragma unroll warning nvcc accepts both `#pragma unroll N` and `#pragma unroll (N)` and generates identical code, and the CUDA C++ Programming Guide documents the parenthesized form. Assisted-By Claude --- clang/docs/ReleaseNotes.md | 5 ++++ .../clang/Basic/DiagnosticParseKinds.td | 5 ---- clang/lib/Parse/ParsePragma.cpp | 6 ----- clang/test/Parser/pragma-unroll-cuda.cu | 25 +++++++++++++++++++ clang/test/Parser/warn-cuda-compat.cu | 13 ---------- 5 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 clang/test/Parser/pragma-unroll-cuda.cu delete mode 100644 clang/test/Parser/warn-cuda-compat.cu diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 4f4cfaf7af73a5..e1957443391458 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -1537,6 +1537,11 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and - Added `--cuda-emit-nvcc-abi` to emit the NVCC-compatible host registration ABI (`__cudaRegisterLinkedBinary`). +- Removed the `-Wcuda-compat` warning about a parenthesized argument to + `#pragma unroll` in CUDA and HIP. `nvcc` accepts both `#pragma unroll N` and + `#pragma unroll (N)` with identical results, and the CUDA C++ Programming + Guide documents the parenthesized form, so the warning was incorrect. + - Fixed CUDA built-in variables such as `threadIdx` and `blockDim` being incorrectly treated as having side effects in assumptions. (#GH181340) - Clang now provides device-side definitions of `__cxa_pure_virtual()` and diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 2be6ff8344cd6d..c15abf61fb01f0 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -1625,11 +1625,6 @@ def err_pragma_pipeline_invalid_keyword : Error< // API notes. def err_type_unparsed : Error<"unparsed tokens following type">; -// Pragma unroll support. -def warn_pragma_unroll_cuda_value_in_parens : Warning< - "argument to '#pragma unroll' should not be in parentheses in CUDA C/C++">, - InGroup<CudaCompat>; - def err_ptrauth_qualifier_bad_arg_count : Error< "'__ptrauth' qualifier must take between 1 and 3 arguments">; diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp index dd05bd3c21442a..0b13731e3d8bbc 100644 --- a/clang/lib/Parse/ParsePragma.cpp +++ b/clang/lib/Parse/ParsePragma.cpp @@ -3808,12 +3808,6 @@ void PragmaUnrollHintHandler::HandlePragma(Preprocessor &PP, if (ParseLoopHintValue(PP, Tok, PragmaName, Option, ValueInParens, *Info)) return; - // In CUDA, the argument to '#pragma unroll' should not be contained in - // parentheses. - if (PP.getLangOpts().CUDA && ValueInParens) - PP.Diag(Info->Toks[0].getLocation(), - diag::warn_pragma_unroll_cuda_value_in_parens); - if (Tok.isNot(tok::eod)) { PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "unroll"; diff --git a/clang/test/Parser/pragma-unroll-cuda.cu b/clang/test/Parser/pragma-unroll-cuda.cu new file mode 100644 index 00000000000000..e0acc0a8934091 --- /dev/null +++ b/clang/test/Parser/pragma-unroll-cuda.cu @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -x cuda -verify -Werror %s +// RUN: %clang_cc1 -x hip -verify -Werror %s + +// The argument to '#pragma unroll' may be parenthesized in CUDA/HIP. nvcc +// accepts both forms and generates identical code, and the CUDA C++ Programming +// Guide documents the parenthesized form, so this must not diagnose. + +// expected-no-diagnostics + +void test(int *List, int Length) { +#pragma unroll(4) + for (int i = 0; i < Length; ++i) { + List[i] = i; + } + +#pragma unroll 4 + for (int i = 0; i < Length; ++i) { + List[i] = i; + } + +#pragma unroll (2 + 2) + for (int i = 0; i < Length; ++i) { + List[i] = i; + } +} diff --git a/clang/test/Parser/warn-cuda-compat.cu b/clang/test/Parser/warn-cuda-compat.cu deleted file mode 100644 index c3aad6f6636054..00000000000000 --- a/clang/test/Parser/warn-cuda-compat.cu +++ /dev/null @@ -1,13 +0,0 @@ -// RUN: %clang_cc1 -Wno-cuda-compat -Werror %s -// RUN: %clang_cc1 -Wcuda-compat -verify %s -// RUN: %clang_cc1 -x c++ -Wcuda-compat -Werror %s - -// Note that this puts the expected lines before the directives to work around -// limitations in the -verify mode. - -void test(int *List, int Length) { -/* expected-warning {{argument to '#pragma unroll' should not be in parentheses in CUDA C/C++}} */#pragma unroll(4) - for (int i = 0; i < Length; ++i) { - List[i] = i; - } -} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
