Great! Thanks!

Anastasia

-----Original Message-----
From: Liu, Yaxun (Sam) [mailto:yaxun....@amd.com] 
Sent: 25 May 2016 15:46
To: Anastasia Stulova; cfe-commits@lists.llvm.org
Cc: nd
Subject: RE: r267590 - [OpenCL] Add predefined macros.

I will take a look. Thanks.

Sam

-----Original Message-----
From: Anastasia Stulova [mailto:anastasia.stul...@arm.com]
Sent: Wednesday, May 25, 2016 10:29 AM
To: Liu, Yaxun (Sam) <yaxun....@amd.com>; cfe-commits@lists.llvm.org
Cc: nd <n...@arm.com>
Subject: RE: r267590 - [OpenCL] Add predefined macros.

This is because OpenCL sets C99 flag as being superset of it. If you check in 
clang/Frontend/LangStandards.def

LANGSTANDARD(opencl, "cl",
             "OpenCL 1.0",
             LineComment | C99 | Digraphs | HexFloat)

We should undo this change as it leaves no possibility to specify an OpenCL 
version during compilation apart from using the frontend option (which isn't 
conventional approach).

Anastasia

-----Original Message-----
From: Liu, Yaxun (Sam) [mailto:yaxun....@amd.com]
Sent: 24 May 2016 19:58
To: Anastasia Stulova; cfe-commits@lists.llvm.org
Cc: nd
Subject: RE: r267590 - [OpenCL] Add predefined macros.

Did clang accept -std=CL2.0 before this change?

According to this diff, the only accepted option for -std= is c99 when 
compiling OpenCL programs.

Sam

-----Original Message-----
From: Anastasia Stulova [mailto:anastasia.stul...@arm.com]
Sent: Tuesday, May 24, 2016 2:48 PM
To: Liu, Yaxun (Sam) <yaxun....@amd.com>; cfe-commits@lists.llvm.org
Cc: nd <n...@arm.com>
Subject: RE: r267590 - [OpenCL] Add predefined macros.

Hi Sam,

I think this commit broke Clang.

It seems we are no longer able to pass the -std=CL2.0, which is important for 
the standalone Clang OpenCL users as -cl-std is frontend only option.
 
clang  -std=CL2.0 test.cl
error: invalid argument '-std=CL2.0' not allowed with 'OpenCL'

We might have to revert or rework this bit:

--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Apr 26 14:25:46
+++ 2016
@@ -1495,9 +1495,8 @@ static void ParseLangArgs(LangOptions &O
             << A->getAsString(Args) << "C++/ObjC++";
         break;
       case IK_OpenCL:
-        if (!Std.isC99())
-          Diags.Report(diag::err_drv_argument_not_allowed_with)
-            << A->getAsString(Args) << "OpenCL";
+        Diags.Report(diag::err_drv_argument_not_allowed_with)
+          << A->getAsString(Args) << "OpenCL";
         break;
       case IK_CUDA:
       case IK_PreprocessedCuda:

Do you think you could look into this?

Thanks,
Anastasia

-----Original Message-----
From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf Of 
Yaxun Liu via cfe-commits
Sent: 26 April 2016 20:26
To: cfe-commits@lists.llvm.org
Subject: r267590 - [OpenCL] Add predefined macros.

Author: yaxunl
Date: Tue Apr 26 14:25:46 2016
New Revision: 267590

URL: http://llvm.org/viewvc/llvm-project?rev=267590&view=rev
Log:
[OpenCL] Add predefined macros.

OpenCL spec requires __OPENCL_C_VERSION__ to be defined based on -cl-std 
option. This patch implements that.

The patch also defines __FAST_RELAXED_MATH__ based on -cl-fast-relaxed-math 
option.

Also fixed a test using -std=c99 for OpenCL program. Limit allowed language 
standard of OpenCL to be OpenCL standards.

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

Removed:
    cfe/trunk/test/Frontend/std.cl
Modified:
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/lib/Frontend/InitPreprocessor.cpp
    cfe/trunk/test/Frontend/stdlang.c
    cfe/trunk/test/Preprocessor/predefined-macros.c

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=267590&r1=267589&r2=267590&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Apr 26 14:25:46
+++ 2016
@@ -1495,9 +1495,8 @@ static void ParseLangArgs(LangOptions &O
             << A->getAsString(Args) << "C++/ObjC++";
         break;
       case IK_OpenCL:
-        if (!Std.isC99())
-          Diags.Report(diag::err_drv_argument_not_allowed_with)
-            << A->getAsString(Args) << "OpenCL";
+        Diags.Report(diag::err_drv_argument_not_allowed_with)
+          << A->getAsString(Args) << "OpenCL";
         break;
       case IK_CUDA:
       case IK_PreprocessedCuda:

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=267590&r1=267589&r2=267590&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Tue Apr 26 14:25:46 2016
@@ -408,6 +408,39 @@ static void InitializeStandardPredefined
   if (LangOpts.ObjC1)
     Builder.defineMacro("__OBJC__");
 
+  // OpenCL v1.0/1.1 s6.9, v1.2/2.0 s6.10: Preprocessor Directives and Macros.
+  if (LangOpts.OpenCL) {
+    // OpenCL v1.0 and v1.1 do not have a predefined macro to indicate the
+    // language standard with which the program is compiled. __OPENCL_VERSION__
+    // is for the OpenCL version supported by the OpenCL device, which is not
+    // necessarily the language standard with which the program is compiled.
+    // A shared OpenCL header file requires a macro to indicate the language
+    // standard. As a workaround, __OPENCL_C_VERSION__ is defined for
+    // OpenCL v1.0 and v1.1.
+    switch (LangOpts.OpenCLVersion) {
+    case 100:
+      Builder.defineMacro("__OPENCL_C_VERSION__", "100");
+      break;
+    case 110:
+      Builder.defineMacro("__OPENCL_C_VERSION__", "110");
+      break;
+    case 120:
+      Builder.defineMacro("__OPENCL_C_VERSION__", "120");
+      break;
+    case 200:
+      Builder.defineMacro("__OPENCL_C_VERSION__", "200");
+      break;
+    default:
+      llvm_unreachable("Unsupported OpenCL version");
+    }
+    Builder.defineMacro("CL_VERSION_1_0", "100");
+    Builder.defineMacro("CL_VERSION_1_1", "110");
+    Builder.defineMacro("CL_VERSION_1_2", "120");
+    Builder.defineMacro("CL_VERSION_2_0", "200");
+
+    if (LangOpts.FastRelaxedMath)
+      Builder.defineMacro("__FAST_RELAXED_MATH__");
+  }
   // Not "standard" per se, but available even with the -undef flag.
   if (LangOpts.AsmPreprocessor)
     Builder.defineMacro("__ASSEMBLER__");

Removed: cfe/trunk/test/Frontend/std.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/std.cl?rev=267589&view=auto
==============================================================================
--- cfe/trunk/test/Frontend/std.cl (original)
+++ cfe/trunk/test/Frontend/std.cl (removed)
@@ -1,9 +0,0 @@
-// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL -// RUN: %clang_cc1 %s 
-fsyntax-only -cl-std=CL1.1 -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL1.2 
-// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL2.0 -// RUN: not %clang_cc1 %s 
-fsyntax-only -cl-std=invalid -DINVALID 2>&1 | FileCheck %s
-
-#ifdef INVALID
-// CHECK: invalid value 'invalid' in '-cl-std=invalid'
-#endif

Modified: cfe/trunk/test/Frontend/stdlang.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/stdlang.c?rev=267590&r1=267589&r2=267590&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/stdlang.c (original)
+++ cfe/trunk/test/Frontend/stdlang.c Tue Apr 26 14:25:46 2016
@@ -1,6 +1,13 @@
 // RUN: %clang_cc1 -x cuda -std=c++11 -DCUDA %s -// RUN: %clang_cc1 -x cl 
-std=c99 -DOPENCL %s -// expected-no-diagnostics
+// 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:
+not %clang_cc1 -x cl -std=c99 -DOPENCL %s 2>&1 | FileCheck
+--check-prefix=CHECK-C99 %s // RUN: not %clang_cc1 -x cl 
+-cl-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 '-cl-std=invalid'
 
 #if defined(CUDA)
   __attribute__((device)) void f_device();

Modified: cfe/trunk/test/Preprocessor/predefined-macros.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/predefined-macros.c?rev=267590&r1=267589&r2=267590&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/predefined-macros.c (original)
+++ cfe/trunk/test/Preprocessor/predefined-macros.c Tue Apr 26 14:25:46
+++ 2016
@@ -146,3 +146,40 @@
 // CHECK-SYNC_CAS_MIPS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1  // 
CHECK-SYNC_CAS_MIPS32-NOT: __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
 // CHECK-SYNC_CAS_MIPS64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
+
+// RUN: %clang_cc1 %s -E -dM -o - -x cl \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-CL10
+// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL1.1 \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-CL11
+// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL1.2 \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-CL12
+// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL2.0 \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-CL20
+// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-fast-relaxed-math \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-FRM
+// CHECK-CL10: #define CL_VERSION_1_0 100 // CHECK-CL10: #define
+CL_VERSION_1_1 110 // CHECK-CL10: #define CL_VERSION_1_2 120 //
+CHECK-CL10: #define CL_VERSION_2_0 200 // CHECK-CL10: #define 
+__OPENCL_C_VERSION__ 100 // CHECK-CL10-NOT: #define 
+__FAST_RELAXED_MATH__ 1 // CHECK-CL11: #define CL_VERSION_1_0 100 //
+CHECK-CL11: #define CL_VERSION_1_1 110 // CHECK-CL11: #define
+CL_VERSION_1_2 120 // CHECK-CL11: #define CL_VERSION_2_0 200 //
+CHECK-CL11: #define __OPENCL_C_VERSION__ 110 // CHECK-CL11-NOT: #define 
+__FAST_RELAXED_MATH__ 1 // CHECK-CL12: #define CL_VERSION_1_0 100 //
+CHECK-CL12: #define CL_VERSION_1_1 110 // CHECK-CL12: #define
+CL_VERSION_1_2 120 // CHECK-CL12: #define CL_VERSION_2_0 200 //
+CHECK-CL12: #define __OPENCL_C_VERSION__ 120 // CHECK-CL12-NOT: #define 
+__FAST_RELAXED_MATH__ 1 // CHECK-CL20: #define CL_VERSION_1_0 100 //
+CHECK-CL20: #define CL_VERSION_1_1 110 // CHECK-CL20: #define
+CL_VERSION_1_2 120 // CHECK-CL20: #define CL_VERSION_2_0 200 //
+CHECK-CL20: #define __OPENCL_C_VERSION__ 200 // CHECK-CL20-NOT: #define 
+__FAST_RELAXED_MATH__ 1 // CHECK-FRM: #define __FAST_RELAXED_MATH__ 1
+


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to