]> granicus.if.org Git - clang/commitdiff
Add -fopenmp -cc1 option and wire it up to define _OPENMP, from Alexey Bataev!
authorDouglas Gregor <dgregor@apple.com>
Tue, 15 Jan 2013 06:45:29 +0000 (06:45 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 15 Jan 2013 06:45:29 +0000 (06:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172509 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/LangOptions.def
include/clang/Driver/Options.td
lib/Frontend/CompilerInvocation.cpp
lib/Frontend/InitPreprocessor.cpp
test/OpenMP/predefined_macro.c [new file with mode: 0644]

index 8ef766ff63ed5217d3e4a2538fcffbdf1d26c899..b78c26118cefa60ac9433ec4d2e86079831d1838 100644 (file)
@@ -117,6 +117,7 @@ LANGOPT(ShortEnums        , 1, 0, "short enum types")
 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")
index 685911fbcaf3154836ebcbdc0d0ce0dffc2d918f..1b8084927f4b0a57af43b909a79d4b9f3523b2ec 100644 (file)
@@ -610,7 +610,7 @@ def fno_objc_nonfragile_abi : Flag<["-"], "fno-objc-nonfragile-abi">, Group<f_Gr
 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">;
index 0f00c07ca933fe5aa737c002636b77f445c3f463..20def5e480c95240167a0143e52e84ff541e2bad 100644 (file)
@@ -1241,6 +1241,9 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
   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,
index 886b212bc2bcb37da23a8da910a10f61b4f69f0d..3646e27a49180559f1713c2795304c6c4c60e159 100644 (file)
@@ -641,6 +641,16 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
                         "__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);
 }
diff --git a/test/OpenMP/predefined_macro.c b/test/OpenMP/predefined_macro.c
new file mode 100644 (file)
index 0000000..e18c3d2
--- /dev/null
@@ -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
+