[PATCH] D92893: [CUDA] Do not diagnose host/device variable access in dependent types.

Artem Belevich via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 8 15:17:21 PST 2020


tra created this revision.
tra added reviewers: yaxunl, hliao.
Herald added a subscriber: bixia.
tra requested review of this revision.
Herald added a project: clang.

`isCUDADeviceBuiltinSurfaceType()`/`isCUDADeviceBuiltinTextureType()` do not
work on dependent types as they rely on specific type attributes and that 
results in mis-diagnosing access when the check happens on class templates used as texture references.
 https://godbolt.org/z/B7rtxR


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92893

Files:
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExpr.cpp


Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -362,8 +362,9 @@
     auto Target = IdentifyCUDATarget(FD);
     if (FD && Target != CFT_Host) {
       const auto *VD = dyn_cast<VarDecl>(D);
-      if (VD && VD->hasGlobalStorage() && !VD->hasAttr<CUDADeviceAttr>() &&
-          !VD->hasAttr<CUDAConstantAttr>() && !VD->hasAttr<CUDASharedAttr>() &&
+      if (VD && VD->hasGlobalStorage() && !VD->getType()->isDependentType() &&
+          !VD->hasAttr<CUDADeviceAttr>() && !VD->hasAttr<CUDAConstantAttr>() &&
+          !VD->hasAttr<CUDASharedAttr>() &&
           !VD->getType()->isCUDADeviceBuiltinSurfaceType() &&
           !VD->getType()->isCUDADeviceBuiltinTextureType() &&
           !VD->isConstexpr() && !VD->getType().isConstQualified())
Index: clang/lib/AST/Type.cpp
===================================================================
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -4299,6 +4299,7 @@
 
 /// Check if the specified type is the CUDA device builtin surface type.
 bool Type::isCUDADeviceBuiltinSurfaceType() const {
+  assert(!isDependentType());
   if (const auto *RT = getAs<RecordType>())
     return RT->getDecl()->hasAttr<CUDADeviceBuiltinSurfaceTypeAttr>();
   return false;
@@ -4306,6 +4307,7 @@
 
 /// Check if the specified type is the CUDA device builtin texture type.
 bool Type::isCUDADeviceBuiltinTextureType() const {
+  assert(!isDependentType());
   if (const auto *RT = getAs<RecordType>())
     return RT->getDecl()->hasAttr<CUDADeviceBuiltinTextureTypeAttr>();
   return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92893.310364.patch
Type: text/x-patch
Size: 1655 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201208/7ba5b616/attachment.bin>


More information about the cfe-commits mailing list