[PATCH] D95840: [CUDA][HIP] Fix checking dependent initalizer
Yaxun Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 1 17:32:20 PST 2021
yaxunl created this revision.
yaxunl added a reviewer: tra.
yaxunl requested review of this revision.
Defer constant checking of dependent initializer to template instantiation
since it cannot be done for dependent values.
This is separated from https://reviews.llvm.org/D95560
https://reviews.llvm.org/D95840
Files:
clang/lib/Sema/SemaCUDA.cpp
clang/test/SemaCUDA/dependent-device-var.cu
Index: clang/test/SemaCUDA/dependent-device-var.cu
===================================================================
--- /dev/null
+++ clang/test/SemaCUDA/dependent-device-var.cu
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=host,com -x hip %s
+// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify=dev,com -x hip %s
+
+#include "Inputs/cuda.h"
+
+template<typename T>
+__device__ int fun1(T x) {
+ static __device__ int a = sizeof(x);
+ static __device__ int b = x;
+ // com-error at -1 {{dynamic initialization is not supported for __device__, __constant__, __shared__, and __managed__ variables}}
+ return a + b;
+}
+
+__device__ int fun1_caller() {
+ return fun1(1);
+ // com-note at -1 {{in instantiation of function template specialization 'fun1<int>' requested here}}
+}
Index: clang/lib/Sema/SemaCUDA.cpp
===================================================================
--- clang/lib/Sema/SemaCUDA.cpp
+++ clang/lib/Sema/SemaCUDA.cpp
@@ -530,9 +530,12 @@
if (!AllowedInit &&
(VD->hasAttr<CUDADeviceAttr>() || VD->hasAttr<CUDAConstantAttr>())) {
auto *Init = VD->getInit();
+ // isConstantInitializer cannot be called with dependent value, therefore
+ // we skip checking dependent value here. This is OK since
+ // checkAllowedCUDAInitializer is called again when the template is
+ // instantiated.
AllowedInit =
- ((VD->getType()->isDependentType() || Init->isValueDependent()) &&
- VD->isConstexpr()) ||
+ (VD->getType()->isDependentType() || Init->isValueDependent()) ||
Init->isConstantInitializer(Context,
VD->getType()->isReferenceType());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95840.320642.patch
Type: text/x-patch
Size: 1710 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210202/672755ef/attachment.bin>
More information about the cfe-commits
mailing list