[cfe-commits] r172509 - in /cfe/trunk: include/clang/Basic/LangOptions.def include/clang/Driver/Options.td lib/Frontend/CompilerInvocation.cpp lib/Frontend/InitPreprocessor.cpp test/OpenMP/ test/OpenMP/predefined_macro.c

Douglas Gregor dgregor at apple.com
Mon Jan 14 22:45:29 PST 2013


Author: dgregor
Date: Tue Jan 15 00:45:29 2013
New Revision: 172509

URL: http://llvm.org/viewvc/llvm-project?rev=172509&view=rev
Log:
Add -fopenmp -cc1 option and wire it up to define _OPENMP, from Alexey Bataev!

Added:
    cfe/trunk/test/OpenMP/
    cfe/trunk/test/OpenMP/predefined_macro.c   (with props)
Modified:
    cfe/trunk/include/clang/Basic/LangOptions.def
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/lib/Frontend/InitPreprocessor.cpp

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=172509&r1=172508&r2=172509&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Tue Jan 15 00:45:29 2013
@@ -117,6 +117,7 @@
 LANGOPT(OpenCL            , 1, 0, "OpenCL")
 LANGOPT(OpenCLVersion     , 32, 0, "OpenCL version")
 LANGOPT(CUDA              , 1, 0, "CUDA")
+LANGOPT(OpenMP            , 1, 0, "OpenMP support")
 
 LANGOPT(AssumeSaneOperatorNew , 1, 1, "implicit __attribute__((malloc)) for C++'s new operators")
 BENIGN_LANGOPT(ElideConstructors , 1, 1, "C++ copy constructor elision")

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=172509&r1=172508&r2=172509&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Jan 15 00:45:29 2013
@@ -610,7 +610,7 @@
 def fobjc_sender_dependent_dispatch : Flag<["-"], "fobjc-sender-dependent-dispatch">, Group<f_Group>;
 def fobjc : Flag<["-"], "fobjc">, Group<f_Group>;
 def fomit_frame_pointer : Flag<["-"], "fomit-frame-pointer">, Group<f_Group>;
-def fopenmp : Flag<["-"], "fopenmp">, Group<f_Group>;
+def fopenmp : Flag<["-"], "fopenmp">, Group<f_Group>, Flags<[CC1Option]>;
 def fno_optimize_sibling_calls : Flag<["-"], "fno-optimize-sibling-calls">, Group<f_Group>;
 def foptimize_sibling_calls : Flag<["-"], "foptimize-sibling-calls">, Group<f_Group>;
 def force__cpusubtype__ALL : Flag<["-"], "force_cpusubtype_ALL">;

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=172509&r1=172508&r2=172509&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Jan 15 00:45:29 2013
@@ -1241,6 +1241,9 @@
   Opts.ApplePragmaPack = Args.hasArg(OPT_fapple_pragma_pack);
   Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name);
 
+  // Check if -fopenmp is specified.
+  Opts.OpenMP = Args.hasArg(OPT_fopenmp);
+
   // Record whether the __DEPRECATED define was requested.
   Opts.Deprecated = Args.hasFlag(OPT_fdeprecated_macro,
                                  OPT_fno_deprecated_macro,

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=172509&r1=172508&r2=172509&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Tue Jan 15 00:45:29 2013
@@ -641,6 +641,16 @@
                         "__attribute__((objc_ownership(none)))");
   }
 
+  // OpenMP definition
+  if (LangOpts.OpenMP) {
+    // OpenMP 2.2: 
+    //   In implementations that support a preprocessor, the _OPENMP
+    //   macro name is defined to have the decimal value yyyymm where
+    //   yyyy and mm are the year and the month designations of the
+    //   version of the OpenMP API that the implementation support.
+    Builder.defineMacro("_OPENMP", "201107");
+  }
+
   // Get other target #defines.
   TI.getTargetDefines(LangOpts, Builder);
 }

Added: cfe/trunk/test/OpenMP/predefined_macro.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/predefined_macro.c?rev=172509&view=auto
==============================================================================
--- cfe/trunk/test/OpenMP/predefined_macro.c (added)
+++ cfe/trunk/test/OpenMP/predefined_macro.c Tue Jan 15 00:45:29 2013
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fopenmp -verify -DFOPENMP -o - %s
+// RUN: %clang_cc1 -verify -o - %s
+// expected-no-diagnostics
+#ifdef FOPENMP
+// -fopenmp option is specified
+#ifndef _OPENMP
+#error "No _OPENMP macro is defined with -fopenmp option"
+#elsif _OPENMP != 201107
+#error "_OPENMP has incorrect value"
+#endif //_OPENMP
+#else
+// No -fopenmp option is specified
+#ifdef _OPENMP
+#error "_OPENMP macro is defined without -fopenmp option"
+#endif // _OPENMP
+#endif // FOPENMP
+

Propchange: cfe/trunk/test/OpenMP/predefined_macro.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/OpenMP/predefined_macro.c
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/OpenMP/predefined_macro.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain





More information about the cfe-commits mailing list