summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnastasia Stulova <anastasia.stulova@arm.com>2018-11-29 14:11:15 +0000
committerAnastasia Stulova <anastasia.stulova@arm.com>2018-11-29 14:11:15 +0000
commit6a4c34689e2ff1ac4f65b9d0cb9136382e55046d (patch)
treee16e5b62f56a2a12730230c0b431e673ff2cd933
parent6e3be9d12e29c951df076df7f1891473de34ff8b (diff)
downloadbcm5719-llvm-6a4c34689e2ff1ac4f65b9d0cb9136382e55046d.tar.gz
bcm5719-llvm-6a4c34689e2ff1ac4f65b9d0cb9136382e55046d.zip
[OpenCL] Improve diags for addr spaces in templates
Fix ICEs on template instantiations that were leading to the creation of invalid code patterns with address spaces. Incorrect cases are now diagnosed properly. Differential Revision: https://reviews.llvm.org/D54858 llvm-svn: 347865
-rw-r--r--clang/lib/Sema/SemaDecl.cpp40
-rw-r--r--clang/lib/Sema/SemaType.cpp5
-rw-r--r--clang/lib/Sema/TreeTransform.h7
-rw-r--r--clang/test/CodeGenOpenCLCXX/template-address-spaces.cl3
-rw-r--r--clang/test/SemaOpenCLCXX/address-space-templates.cl12
5 files changed, 43 insertions, 24 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5b2d2899f81..becbb1f186d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15148,22 +15148,6 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record,
}
}
- // TR 18037 does not allow fields to be declared with address spaces.
- if (T.getQualifiers().hasAddressSpace() ||
- T->isDependentAddressSpaceType() ||
- T->getBaseElementTypeUnsafe()->isDependentAddressSpaceType()) {
- Diag(Loc, diag::err_field_with_address_space);
- D.setInvalidType();
- }
-
- // OpenCL v1.2 s6.9b,r & OpenCL v2.0 s6.12.5 - The following types cannot be
- // used as structure or union field: image, sampler, event or block types.
- if (LangOpts.OpenCL && (T->isEventT() || T->isImageType() ||
- T->isSamplerT() || T->isBlockPointerType())) {
- Diag(Loc, diag::err_opencl_type_struct_or_union_field) << T;
- D.setInvalidType();
- }
-
DiagnoseFunctionSpecifiers(D.getDeclSpec());
if (D.getDeclSpec().isInlineSpecified())
@@ -15275,12 +15259,30 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
}
}
- // OpenCL v1.2 s6.9.c: bitfields are not supported.
- if (BitWidth && getLangOpts().OpenCL) {
- Diag(Loc, diag::err_opencl_bitfields);
+ // TR 18037 does not allow fields to be declared with address space
+ if (T.getQualifiers().hasAddressSpace() || T->isDependentAddressSpaceType() ||
+ T->getBaseElementTypeUnsafe()->isDependentAddressSpaceType()) {
+ Diag(Loc, diag::err_field_with_address_space);
+ Record->setInvalidDecl();
InvalidDecl = true;
}
+ if (LangOpts.OpenCL) {
+ // OpenCL v1.2 s6.9b,r & OpenCL v2.0 s6.12.5 - The following types cannot be
+ // used as structure or union field: image, sampler, event or block types.
+ if (T->isEventT() || T->isImageType() || T->isSamplerT() ||
+ T->isBlockPointerType()) {
+ Diag(Loc, diag::err_opencl_type_struct_or_union_field) << T;
+ Record->setInvalidDecl();
+ InvalidDecl = true;
+ }
+ // OpenCL v1.2 s6.9.c: bitfields are not supported.
+ if (BitWidth) {
+ Diag(Loc, diag::err_opencl_bitfields);
+ InvalidDecl = true;
+ }
+ }
+
// Anonymous bit-fields cannot be cv-qualified (CWG 2229).
if (!InvalidDecl && getLangOpts().CPlusPlus && !II && BitWidth &&
T.hasQualifiers()) {
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 99ea2d129ef..011d0a585f0 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -7226,8 +7226,9 @@ static void deduceOpenCLImplicitAddrSpace(TypeProcessingState &State,
if (IsPointee) {
ImpAddr = LangAS::opencl_generic;
} else {
- if (D.getContext() == DeclaratorContext::TemplateArgContext) {
- // Do not deduce address space for non-pointee type in template args
+ if (D.getContext() == DeclaratorContext::TemplateArgContext ||
+ T->isDependentType()) {
+ // Do not deduce address space for non-pointee type in templates.
} else if (D.getContext() == DeclaratorContext::FileContext) {
ImpAddr = LangAS::opencl_global;
} else {
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 4011ec251cf..58f73ef1018 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -5284,6 +5284,13 @@ QualType TreeTransform<Derived>::TransformFunctionProtoType(
if (ResultType.isNull())
return QualType();
+ // Return type can not be qualified with an address space.
+ if (ResultType.getAddressSpace() != LangAS::Default) {
+ SemaRef.Diag(TL.getReturnLoc().getBeginLoc(),
+ diag::err_attribute_address_function_type);
+ return QualType();
+ }
+
if (getDerived().TransformFunctionTypeParams(
TL.getBeginLoc(), TL.getParams(),
TL.getTypePtr()->param_type_begin(),
diff --git a/clang/test/CodeGenOpenCLCXX/template-address-spaces.cl b/clang/test/CodeGenOpenCLCXX/template-address-spaces.cl
index 606ab22f69f..eb274ea4560 100644
--- a/clang/test/CodeGenOpenCLCXX/template-address-spaces.cl
+++ b/clang/test/CodeGenOpenCLCXX/template-address-spaces.cl
@@ -21,11 +21,8 @@ void bar(){
S<int> sint;
S<int*> sintptr;
S<__global int*> sintptrgl;
- // FIXME: Preserve AS in TreeTransform
- //S<__global int> sintgl;
sint.foo();
sintptr.foo();
sintptrgl.foo();
- //sintgl.foo();
}
diff --git a/clang/test/SemaOpenCLCXX/address-space-templates.cl b/clang/test/SemaOpenCLCXX/address-space-templates.cl
new file mode 100644
index 00000000000..780175bf2b9
--- /dev/null
+++ b/clang/test/SemaOpenCLCXX/address-space-templates.cl
@@ -0,0 +1,12 @@
+//RUN: %clang_cc1 %s -cl-std=c++ -pedantic -verify -fsyntax-only
+
+template <typename T>
+struct S {
+ T a; // expected-error{{field may not be qualified with an address space}}
+ T f1(); // expected-error{{function type may not be qualified with an address space}}
+ void f2(T); // expected-error{{parameter may not be qualified with an address space}}
+};
+
+void bar() {
+ S<const __global int> sintgl; // expected-note{{in instantiation of template class 'S<const __global int>' requested here}}
+}
OpenPOWER on IntegriCloud