Anastasia updated this revision to Diff 305724.
Anastasia added a comment.

Added full diffs.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91538/new/

https://reviews.llvm.org/D91538

Files:
  clang/include/clang/Basic/OpenCLExtensions.def
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Headers/opencl-c-base.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/test/Headers/opencl-c-header.cl
  clang/test/SemaOpenCL/extension-version.cl
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===================================================================
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -30,8 +30,8 @@
 typedef int int4 __attribute__((ext_vector_type(4)));
 typedef uint uint4 __attribute__((ext_vector_type(4)));
 typedef long long2 __attribute__((ext_vector_type(2)));
+typedef float float2 __attribute__((ext_vector_type(2)));
 #endif
-
 kernel void test_pointers(volatile global void *global_p, global const int4 *a) {
   int i;
   unsigned int ui;
@@ -143,8 +143,11 @@
 #if defined(__OPENCL_CPP_VERSION__)
   // expected-error@-2{{no matching function for call to 'get_sub_group_size'}}
   // expected-note@-3{{candidate unavailable as it requires OpenCL extension 'cl_khr_subgroups' to be enabled}}
-#else
+#elif __OPENCL_C_VERSION__ == CL_VERSION_2_0 
   // expected-error@-5{{use of declaration 'get_sub_group_size' requires cl_khr_subgroups extension to be enabled}}
+#else
+  // expected-error@-7{{implicit declaration of function 'get_sub_group_size' is invalid in OpenCL}}
+  // expected-error@-8{{implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int')}}
 #endif
 }
 
@@ -179,3 +182,50 @@
 // expected-error@-2{{implicit declaration of function 'get_enqueued_local_size' is invalid in OpenCL}}
 #endif
 }
+
+float4 basic_mipmap_image(read_only image2d_t image, sampler_t sampler, float2 coord, float lod) {
+  return read_imagef(image, sampler, coord, lod);
+#if (!defined(__OPENCL_CPP_VERSION__) && __OPENCL_C_VERSION__ < CL_VERSION_2_0) || defined(NO_HEADER)
+// expected-error@-2{{no matching function for call to 'read_imagef'}}
+// expected-note@-3{{candidate function not viable:}}
+// expected-note@-4{{candidate function not viable:}}
+// expected-note@-5{{candidate function not viable:}}
+// expected-note@-6{{candidate function not viable:}}
+// expected-note@-7{{candidate function not viable:}}
+// expected-note@-8{{candidate function not viable:}}
+// expected-note@-9{{candidate function not viable:}}
+// expected-note@-10{{candidate function not viable:}}
+// expected-note@-11{{candidate function not viable:}}
+// expected-note@-12{{candidate function not viable:}}
+// expected-note@-13{{candidate function not viable:}}
+// expected-note@-14{{candidate function not viable:}}
+// expected-note@-15{{candidate function not viable:}}
+// expected-note@-16{{candidate function not viable:}}
+// expected-note@-17{{candidate function not viable:}}
+// expected-note@-18{{candidate function not viable:}}
+// expected-note@-19{{candidate function not viable:}}
+// expected-note@-20{{candidate function not viable:}}
+// expected-note@-21{{candidate function not viable:}}
+// expected-note@-22{{candidate function not viable:}}
+// expected-note@-23{{candidate function not viable:}}
+// expected-note@-24{{candidate function not viable:}}
+// expected-note@-25{{candidate function not viable:}}
+// expected-note@-26{{candidate function not viable:}}
+// expected-note@-27{{candidate function not viable:}}
+// expected-note@-28{{candidate function not viable:}}
+// expected-note@-29{{candidate function not viable:}}
+// expected-note@-30{{candidate function not viable:}}
+// expected-note@-31{{candidate function not viable:}}
+// expected-note@-32{{candidate function not viable:}}
+#if defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+// expected-note@-34{{candidate function not viable:}}
+// expected-note@-35{{candidate function not viable:}}
+// expected-note@-36{{candidate function not viable:}}
+// expected-note@-37{{candidate function not viable:}}
+// expected-note@-38{{candidate function not viable:}}
+// expected-note@-39{{candidate function not viable:}}
+// expected-note@-40{{candidate function not viable:}}
+// expected-note@-41{{candidate function not viable:}}
+#endif
+#endif
+}
Index: clang/test/SemaOpenCL/extension-version.cl
===================================================================
--- clang/test/SemaOpenCL/extension-version.cl
+++ clang/test/SemaOpenCL/extension-version.cl
@@ -116,17 +116,10 @@
 #endif
 #pragma OPENCL EXTENSION cl_khr_gl_msaa_sharing : enable
 
-#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
-#ifndef cl_khr_mipmap_image
-#error "Missing cl_khr_mipmap_image define"
-#endif
-#else
-#ifdef cl_khr_mipmap_image
-#error "Incorrect cl_khr_mipmap_image define"
-#endif
-// expected-warning@+2{{unsupported OpenCL extension 'cl_khr_mipmap_image' - ignoring}}
-#endif
 #pragma OPENCL EXTENSION cl_khr_mipmap_image : enable
+#if defined(TEST_REDUNDANT_PRAGMA)
+// expected-warning@-2{{OpenCL extension pragma 'cl_khr_mipmap_image' has no effect - ignoring}}
+#endif
 
 #if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 #ifndef cl_khr_mipmap_image_writes
Index: clang/test/Headers/opencl-c-header.cl
===================================================================
--- clang/test/Headers/opencl-c-header.cl
+++ clang/test/Headers/opencl-c-header.cl
@@ -108,3 +108,14 @@
 #error "Incorrect cl_khr_depth_images define"
 #endif
 #endif
+
+#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200) 
+#ifndef cl_khr_mipmap_image 
+#error "Missing cl_khr_mipmap_image define" 
+#endif 
+#else 
+#ifdef cl_khr_mipmap_image 
+#error "Incorrect cl_khr_mipmap_image define" 
+#endif 
+#endif
+
Index: clang/lib/Sema/SemaLookup.cpp
===================================================================
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -751,7 +751,10 @@
                                 FunctionDecl *FDecl) {
   // Fetch extension associated with a function prototype.
   StringRef E = FunctionExtensionTable[BIDecl.Extension];
-  if (E != "")
+  if (E != "" && S.getOpenCLOptions().isKnown(E))
+    // FIXME: This doesn't seem right. The spec doesn't say that pragma should
+    // be used in order to call the functions for the extensions. This diverges
+    // from the regular headers.
     S.setOpenCLExtensionForDecl(FDecl, E);
 }
 
@@ -790,6 +793,12 @@
         (OpenCLVersion >= OpenCLBuiltin.MaxVersion))
       continue;
 
+    // Ignore this BIF if the extension macro is not defined, this indicates
+    // that extension is not supported by the target.
+    StringRef Ext = FunctionExtensionTable[OpenCLBuiltin.Extension];
+    if (!Ext.empty() && !S.getPreprocessor().isMacroDefined(Ext))
+      continue;
+
     SmallVector<QualType, 1> RetTypes;
     SmallVector<SmallVector<QualType, 1>, 5> ArgTypes;
 
Index: clang/lib/Parse/ParsePragma.cpp
===================================================================
--- clang/lib/Parse/ParsePragma.cpp
+++ clang/lib/Parse/ParsePragma.cpp
@@ -791,7 +791,7 @@
     // compatibility. Pragmas from new extensions should not be added here.
     // If the pragma does nothing it should not be added until its
     // functionality is determined.
-    StringRef DeprecatedPragmas{"cl_khr_depth_images,"};
+    StringRef DeprecatedPragmas{"cl_khr_depth_images, cl_khr_mipmap_image"};
     if (DeprecatedPragmas.find(Name) != StringRef::npos)
       PP.Diag(NameLoc, diag::warn_pragma_deprecated_extension) << Ident;
     else
Index: clang/lib/Headers/opencl-c-base.h
===================================================================
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -568,4 +568,12 @@
 #pragma OPENCL EXTENSION cl_intel_device_side_avc_motion_estimation : end
 #endif // cl_intel_device_side_avc_motion_estimation
 
+// Add predefined macros for extensions.
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0) && \
+    (!defined(__undef_cl_khr_mipmap_image) && (defined(__SPIR__) || defined(__AMDGCN__))
+ #ifndef cl_khr_mipmap_image
+ #define cl_khr_mipmap_image
+ #endif //cl_khr_mipmap_image
+#endif 
+
 #endif //_OPENCL_BASE_H_
Index: clang/lib/Basic/Targets/AMDGPU.h
===================================================================
--- clang/lib/Basic/Targets/AMDGPU.h
+++ clang/lib/Basic/Targets/AMDGPU.h
@@ -303,7 +303,6 @@
       Opts.support("cl_khr_fp16");
       Opts.support("cl_khr_int64_base_atomics");
       Opts.support("cl_khr_int64_extended_atomics");
-      Opts.support("cl_khr_mipmap_image");
       Opts.support("cl_khr_mipmap_image_writes");
       Opts.support("cl_khr_subgroups");
       Opts.support("cl_khr_3d_image_writes");
Index: clang/include/clang/Basic/OpenCLExtensions.def
===================================================================
--- clang/include/clang/Basic/OpenCLExtensions.def
+++ clang/include/clang/Basic/OpenCLExtensions.def
@@ -61,7 +61,6 @@
 OPENCLEXT_INTERNAL(cl_khr_gl_msaa_sharing, 120, ~0U)
 
 // OpenCL 2.0.
-OPENCLEXT_INTERNAL(cl_khr_mipmap_image, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_mipmap_image_writes, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_srgb_image_writes, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_subgroups, 200, ~0U)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to