]> granicus.if.org Git - clang/commitdiff
[OpenCL] Enable -fblocks by default for OpenCL 2.0 and above.
authorYaxun Liu <Yaxun.Liu@amd.com>
Tue, 14 Jun 2016 21:43:01 +0000 (21:43 +0000)
committerYaxun Liu <Yaxun.Liu@amd.com>
Tue, 14 Jun 2016 21:43:01 +0000 (21:43 +0000)
Reviewed as part of http://reviews.llvm.org/D20444

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272720 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Frontend/CompilerInvocation.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaType.cpp
test/Frontend/opencl-blocks.cl [new file with mode: 0644]

index e15ef150ab85160dcd8102912624c72cca299eb0..f74004fb2faf51f8ad4586be3d602e23ef11608f 100644 (file)
@@ -7349,7 +7349,7 @@ def err_generic_sel_multi_match : Error<
 
 // Blocks
 def err_blocks_disable : Error<"blocks support disabled - compile with -fblocks"
-  " or pick a deployment target that supports them">;
+  " or %select{pick a deployment target that supports them|for OpenCL 2.0 or above}0">;
 def err_block_returning_array_function : Error<
   "block cannot return %select{array|function}0 type %1">;
 
index b217db96c7e59404c922bccb4fbdae21cdbbb625..581dd8160e452e0cd7ac70d8dad34208f3b23e1a 100644 (file)
@@ -1827,7 +1827,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
 
   Opts.RTTI = Opts.CPlusPlus && !Args.hasArg(OPT_fno_rtti);
   Opts.RTTIData = Opts.RTTI && !Args.hasArg(OPT_fno_rtti_data);
-  Opts.Blocks = Args.hasArg(OPT_fblocks);
+  Opts.Blocks = Args.hasArg(OPT_fblocks) || (Opts.OpenCL
+    && Opts.OpenCLVersion >= 200);
   Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional);
   Opts.Coroutines = Args.hasArg(OPT_fcoroutines);
   Opts.Modules = Args.hasArg(OPT_fmodules);
index 8f0f6017b3120e4c9b3fd70d84ae4556256f2878..6f23115f02a897a9f06afbc70a2ef0d5c73f6043 100644 (file)
@@ -12066,7 +12066,7 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc,
                                     Stmt *Body, Scope *CurScope) {
   // If blocks are disabled, emit an error.
   if (!LangOpts.Blocks)
-    Diag(CaretLoc, diag::err_blocks_disable);
+    Diag(CaretLoc, diag::err_blocks_disable) << LangOpts.OpenCL;
 
   // Leave the expression-evaluation context.
   if (hasAnyUnrecoverableErrorsInThisFunction())
index ddcdef843100e550ced993c7f66b4a106bdd876d..84ebb9bc8664549bc90533458850ab591d663847 100644 (file)
@@ -3811,7 +3811,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
     case DeclaratorChunk::BlockPointer:
       // If blocks are disabled, emit an error.
       if (!LangOpts.Blocks)
-        S.Diag(DeclType.Loc, diag::err_blocks_disable);
+        S.Diag(DeclType.Loc, diag::err_blocks_disable) << LangOpts.OpenCL;
 
       // Handle pointer nullability.
       inferPointerNullability(SimplePointerKind::BlockPointer,
diff --git a/test/Frontend/opencl-blocks.cl b/test/Frontend/opencl-blocks.cl
new file mode 100644 (file)
index 0000000..b514efa
--- /dev/null
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.1
+// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.2
+// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -fsyntax-only -fblocks -DBLOCKS
+// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.1 -fblocks -DBLOCKS
+// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.2 -fblocks -DBLOCKS
+// RUN: %clang_cc1 %s -triple amdgcn--amdhsa -x c -std=c99 -verify -fsyntax-only
+
+void f(void (^g)(void)) {
+#ifdef __OPENCL_C_VERSION__
+#if __OPENCL_C_VERSION__ < CL_VERSION_2_0 && !defined(BLOCKS)
+  // expected-error@-3{{blocks support disabled - compile with -fblocks or for OpenCL 2.0 or above}}
+#else
+  // expected-no-diagnostics
+#endif
+#else
+  // expected-error@-8{{blocks support disabled - compile with -fblocks or pick a deployment target that supports them}}
+#endif
+}