r273015 - [OpenCL] Allow -std={cl|CL}{|1.1|1.2|2.0} in driver

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 17 10:19:29 PDT 2016


Author: yaxunl
Date: Fri Jun 17 12:19:28 2016
New Revision: 273015

URL: http://llvm.org/viewvc/llvm-project?rev=273015&view=rev
Log:
[OpenCL] Allow -std={cl|CL}{|1.1|1.2|2.0} in driver

Fix a regression which forbids using -std=cl|CL1.1|CL1.2|CL2.0 in driver.

Allow -std and -cl-std={cl|CL}{|1.1|1.2|2.0}.

Differential Revision: http://reviews.llvm.org/D20630

Added:
    cfe/trunk/test/Driver/opencl.cl
Modified:
    cfe/trunk/include/clang/Frontend/LangStandards.def
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/test/Frontend/stdlang.c

Modified: cfe/trunk/include/clang/Frontend/LangStandards.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/LangStandards.def?rev=273015&r1=273014&r2=273015&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/LangStandards.def (original)
+++ cfe/trunk/include/clang/Frontend/LangStandards.def Fri Jun 17 12:19:28 2016
@@ -19,6 +19,14 @@
 /// \param FEATURES - The standard features as flags, these are enums from the
 /// clang::frontend namespace, which is assumed to be be available.
 
+/// LANGSTANDARD_ALIAS(IDENT, ALIAS)
+/// \param IDENT - The name of the standard as a C++ identifier.
+/// \param ALIAS - The alias of the standard.
+
+#ifndef LANGSTANDARD_ALIAS
+#define LANGSTANDARD_ALIAS(IDENT, ALIAS)
+#endif
+
 // C89-ish modes.
 LANGSTANDARD(c89, "c89",
              "ISO C 1990",
@@ -135,19 +143,26 @@ LANGSTANDARD(gnucxx1z, "gnu++1z",
 LANGSTANDARD(opencl, "cl",
              "OpenCL 1.0",
              LineComment | C99 | Digraphs | HexFloat)
-LANGSTANDARD(opencl11, "CL1.1",
+LANGSTANDARD(opencl11, "cl1.1",
              "OpenCL 1.1",
              LineComment | C99 | Digraphs | HexFloat)
-LANGSTANDARD(opencl12, "CL1.2",
+LANGSTANDARD(opencl12, "cl1.2",
              "OpenCL 1.2",
              LineComment | C99 | Digraphs | HexFloat)
-LANGSTANDARD(opencl20, "CL2.0",
+LANGSTANDARD(opencl20, "cl2.0",
              "OpenCL 2.0",
              LineComment | C99 | Digraphs | HexFloat)
 
+LANGSTANDARD_ALIAS(opencl, "CL")
+LANGSTANDARD_ALIAS(opencl11, "CL1.1")
+LANGSTANDARD_ALIAS(opencl12, "CL1.2")
+LANGSTANDARD_ALIAS(opencl20, "CL2.0")
+
 // CUDA
 LANGSTANDARD(cuda, "cuda",
              "NVIDIA CUDA(tm)",
              LineComment | CPlusPlus | Digraphs)
 
 #undef LANGSTANDARD
+#undef LANGSTANDARD_ALIAS
+

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=273015&r1=273014&r2=273015&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Jun 17 12:19:28 2016
@@ -1450,6 +1450,13 @@ static void ParseHeaderSearchArgs(Header
     Opts.AddVFSOverlayFile(A->getValue());
 }
 
+bool isOpenCL(LangStandard::Kind LangStd) {
+  return LangStd == LangStandard::lang_opencl
+    || LangStd == LangStandard::lang_opencl11
+    || LangStd == LangStandard::lang_opencl12
+    || LangStd == LangStandard::lang_opencl20;
+}
+
 void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
                                          const llvm::Triple &T,
                                          LangStandard::Kind LangStd) {
@@ -1517,7 +1524,7 @@ void CompilerInvocation::setLangDefaults
   Opts.ImplicitInt = Std.hasImplicitInt();
 
   // Set OpenCL Version.
-  Opts.OpenCL = LangStd == LangStandard::lang_opencl || IK == IK_OpenCL;
+  Opts.OpenCL = isOpenCL(LangStd) || IK == IK_OpenCL;
   if (LangStd == LangStandard::lang_opencl)
     Opts.OpenCLVersion = 100;
   else if (LangStd == LangStandard::lang_opencl11)
@@ -1589,6 +1596,8 @@ static void ParseLangArgs(LangOptions &O
     LangStd = llvm::StringSwitch<LangStandard::Kind>(A->getValue())
 #define LANGSTANDARD(id, name, desc, features) \
       .Case(name, LangStandard::lang_##id)
+#define LANGSTANDARD_ALIAS(id, alias) \
+      .Case(alias, LangStandard::lang_##id)
 #include "clang/Frontend/LangStandards.def"
       .Default(LangStandard::lang_unspecified);
     if (LangStd == LangStandard::lang_unspecified)
@@ -1616,8 +1625,9 @@ static void ParseLangArgs(LangOptions &O
             << A->getAsString(Args) << "C++/ObjC++";
         break;
       case IK_OpenCL:
-        Diags.Report(diag::err_drv_argument_not_allowed_with)
-          << A->getAsString(Args) << "OpenCL";
+        if (!isOpenCL(LangStd))
+          Diags.Report(diag::err_drv_argument_not_allowed_with)
+            << A->getAsString(Args) << "OpenCL";
         break;
       case IK_CUDA:
       case IK_PreprocessedCuda:
@@ -1636,10 +1646,10 @@ static void ParseLangArgs(LangOptions &O
   if (const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) {
     LangStandard::Kind OpenCLLangStd
     = llvm::StringSwitch<LangStandard::Kind>(A->getValue())
-    .Case("CL", LangStandard::lang_opencl)
-    .Case("CL1.1", LangStandard::lang_opencl11)
-    .Case("CL1.2", LangStandard::lang_opencl12)
-    .Case("CL2.0", LangStandard::lang_opencl20)
+    .Cases("cl", "CL", LangStandard::lang_opencl)
+    .Cases("cl1.1", "CL1.1", LangStandard::lang_opencl11)
+    .Cases("cl1.2", "CL1.2", LangStandard::lang_opencl12)
+    .Cases("cl2.0", "CL2.0", LangStandard::lang_opencl20)
     .Default(LangStandard::lang_unspecified);
 
     if (OpenCLLangStd == LangStandard::lang_unspecified) {

Added: cfe/trunk/test/Driver/opencl.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/opencl.cl?rev=273015&view=auto
==============================================================================
--- cfe/trunk/test/Driver/opencl.cl (added)
+++ cfe/trunk/test/Driver/opencl.cl Fri Jun 17 12:19:28 2016
@@ -0,0 +1,15 @@
+// RUN: %clang %s
+// RUN: %clang -std=cl %s
+// RUN: %clang -std=cl1.1 %s
+// RUN: %clang -std=cl1.2 %s
+// RUN: %clang -std=cl2.0 %s
+// RUN: %clang -std=CL %s
+// RUN: %clang -std=CL1.1 %s
+// RUN: %clang -std=CL1.2 %s
+// RUN: %clang -std=CL2.0 %s
+// RUN: not %clang_cc1 -std=c99 -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-C99 %s
+// RUN: not %clang_cc1 -std=invalid -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID %s
+// CHECK-C99: error: invalid argument '-std=c99' not allowed with 'OpenCL'
+// CHECK-INVALID: error: invalid value 'invalid' in '-std=invalid'
+
+kernel void func(void);

Modified: cfe/trunk/test/Frontend/stdlang.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/stdlang.c?rev=273015&r1=273014&r2=273015&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/stdlang.c (original)
+++ cfe/trunk/test/Frontend/stdlang.c Fri Jun 17 12:19:28 2016
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -x cuda -std=c++11 -DCUDA %s
 // RUN: %clang_cc1 -x cl -DOPENCL %s
+// RUN: %clang_cc1 -x cl -cl-std=cl -DOPENCL %s
+// RUN: %clang_cc1 -x cl -cl-std=cl1.1 -DOPENCL %s
+// RUN: %clang_cc1 -x cl -cl-std=cl1.2 -DOPENCL %s
+// RUN: %clang_cc1 -x cl -cl-std=cl2.0 -DOPENCL %s
 // RUN: %clang_cc1 -x cl -cl-std=CL -DOPENCL %s
 // RUN: %clang_cc1 -x cl -cl-std=CL1.1 -DOPENCL %s
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 -DOPENCL %s




More information about the cfe-commits mailing list