[PATCH] D51296: [Sema] Traverse vector types for ocl extensions support

Viktoria Maximova via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 27 05:00:31 PDT 2018

vmaksimo created this revision.
vmaksimo added reviewers: bader, Anastasia, AlexeySotkin.
vmaksimo created this object with edit policy "Only User: vmaksimo (Viktoria Maximova)".
Herald added a subscriber: cfe-commits.

Given the following kernel:
__kernel void foo()

  double d;
  double4 dd;


and `cl_khr_fp64` disabled, the compilation would fail due to
the presence of 'double d', but when removed, it passes.

The expectation is that extended vector types of unsupported types
will also be unsupported.

This patch adds this check for this scenario.

  rC Clang



Index: test/SemaOpenCL/extensions.cl
--- test/SemaOpenCL/extensions.cl
+++ test/SemaOpenCL/extensions.cl
@@ -70,6 +70,13 @@
 // expected-error at -2{{use of type 'double' requires cl_khr_fp64 extension to be enabled}}
+  typedef double double4 __attribute__((ext_vector_type(4)));
+  double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f};
+#ifdef NOFP64
+// expected-error at -3 {{use of type 'double' requires cl_khr_fp64 extension to be enabled}}
+// expected-error at -3 {{use of type 'double4' (vector of 4 'double' values) requires cl_khr_fp64 extension to be enabled}}
   (void) 1.0;
 #ifdef NOFP64
Index: lib/Sema/Sema.cpp
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -39,6 +39,7 @@
 #include "clang/Sema/TemplateDeduction.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallSet.h"
 using namespace clang;
 using namespace sema;
@@ -1852,6 +1853,14 @@
   if (auto TagT = dyn_cast<TagType>(QT.getCanonicalType().getTypePtr()))
     Decl = TagT->getDecl();
   auto Loc = DS.getTypeSpecTypeLoc();
+  // Check extensions for vector types.
+  // e.g. double4 is not allowed when cl_khr_fp64 is absent.
+  if (QT->isExtVectorType()) {
+    auto TypePtr = QT->castAs<ExtVectorType>()->getElementType().getTypePtr();
+    return checkOpenCLDisabledTypeOrDecl(TypePtr, Loc, QT, OpenCLTypeExtMap);
+  }
   if (checkOpenCLDisabledTypeOrDecl(Decl, Loc, QT, OpenCLDeclExtMap))
     return true;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51296.162656.patch
Type: text/x-patch
Size: 1542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180827/00a0688d/attachment-0001.bin>

More information about the cfe-commits mailing list