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;


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;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to