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(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"); Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/readability-static-accessed-through-instance/__clang_cuda_builtin_vars.h =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/Inputs/readability-static-accessed-through-instance/__clang_cuda_builtin_vars.h @@ -0,0 +1,36 @@ +//===--- __clang_cuda_builtin_vars.h - Stub header for tests ----*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef ___CLANG_CUDA_BUILTIN_VARS_H_ +#define ___CLANG_CUDA_BUILTIN_VARS_H_ + +#define __CUDA_DEVICE_BUILTIN(FIELD) \ + static unsigned int FIELD; + +struct __cuda_builtin_threadIdx_t { + __CUDA_DEVICE_BUILTIN(x); +}; + +struct __cuda_builtin_blockIdx_t { + __CUDA_DEVICE_BUILTIN(x); +}; + +struct __cuda_builtin_blockDim_t { + __CUDA_DEVICE_BUILTIN(x); +}; + +struct __cuda_builtin_gridDim_t { + __CUDA_DEVICE_BUILTIN(x); +}; + +__cuda_builtin_threadIdx_t threadIdx; +__cuda_builtin_blockIdx_t blockIdx; +__cuda_builtin_blockDim_t blockDim; +__cuda_builtin_gridDim_t gridDim; + +#endif // ___CLANG_CUDA_BUILTIN_VARS_H_ 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 @@ -1,4 +1,5 @@ -// RUN: %check_clang_tidy %s readability-static-accessed-through-instance %t +// RUN: %check_clang_tidy %s readability-static-accessed-through-instance %t -- -- -isystem %S/Inputs/readability-static-accessed-through-instance +#include <__clang_cuda_builtin_vars.h> struct C { static void foo(); @@ -248,3 +249,17 @@ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member // CHECK-FIXES: {{^}} Outer::S::I;{{$}} } + +// https://bugs.llvm.org/show_bug.cgi?id=48758 +namespace Bugzilla_48758 { + +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 Bugzilla_48758