[PATCH] D112334: [clang-tidy] Suppress readability-static-access-through-instance for CUDA built-in variables
Carlos Galvez via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 25 08:38:06 PDT 2021
carlosgalvezp updated this revision to Diff 382012.
carlosgalvezp marked an inline comment as done.
carlosgalvezp added a comment.
Addressed comments.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112334/new/
https://reviews.llvm.org/D112334
Files:
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
@@ -248,3 +248,39 @@
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
// CHECK-FIXES: {{^}} Outer::S::I;{{$}}
}
+
+// https://bugs.llvm.org/show_bug.cgi?id=48758
+namespace {
+
+// From __clang_cuda_builtin_vars.h
+struct __cuda_builtin_threadIdx_t {
+ static unsigned int x;
+};
+
+struct __cuda_builtin_blockIdx_t {
+ static unsigned int x;
+};
+
+struct __cuda_builtin_blockDim_t {
+ static unsigned int x;
+};
+
+struct __cuda_builtin_gridDim_t {
+ static unsigned int x;
+};
+
+__cuda_builtin_threadIdx_t threadIdx;
+__cuda_builtin_blockIdx_t blockIdx;
+__cuda_builtin_blockDim_t blockDim;
+__cuda_builtin_gridDim_t gridDim;
+
+unsigned int x1 = threadIdx.x;
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:10: warning: static member
+unsigned int x2 = blockIdx.x;
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:10: warning: static member
+unsigned int x3 = blockDim.x;
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:10: warning: static member
+unsigned int x4 = gridDim.x;
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:10: warning: static member
+
+} // namespace
Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -9,6 +9,7 @@
#include "StaticAccessedThroughInstanceCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/StringRef.h"
using namespace clang::ast_matchers;
@@ -54,7 +55,7 @@
const Expr *BaseExpr = MemberExpression->getBase();
- // Do not warn for overlaoded -> operators.
+ // Do not warn for overloaded -> operators.
if (isa<CXXOperatorCallExpr>(BaseExpr))
return;
@@ -70,6 +71,10 @@
std::string BaseTypeName =
BaseType.getAsString(PrintingPolicyWithSupressedTag);
+ // Do not warn for CUDA built-in variables.
+ if (StringRef(BaseTypeName).startswith("__cuda_builtin_"))
+ return;
+
SourceLocation MemberExprStartLoc = MemberExpression->getBeginLoc();
auto Diag =
diag(MemberExprStartLoc, "static member accessed through instance");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112334.382012.patch
Type: text/x-patch
Size: 2583 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211025/3d06e190/attachment-0001.bin>
More information about the cfe-commits
mailing list