24378340 clang -fopenmp must include the path to the omp.h header file
authorStefan Teleman <stefan.teleman@oracle.com>
Thu, 18 Aug 2016 12:56:39 -0700
changeset 6637 22d5f6c97e6f
parent 6636 1c4ef2cb001a
child 6638 c7defa3ae9cc
24378340 clang -fopenmp must include the path to the omp.h header file 24378393 clang -fopenmp must define _OPENMP to 201307
components/llvm/Makefile
components/llvm/clang.p5m
components/llvm/patches/010-solaris-clang-libclangBasic.patch
components/llvm/patches/012-solaris-clang-libclangDriver.patch
components/llvm/patches/013-solaris-clang-libclangFrontend.patch
components/llvm/patches/031-solaris-build-system.patch
--- a/components/llvm/Makefile	Thu Aug 18 12:54:40 2016 -0700
+++ b/components/llvm/Makefile	Thu Aug 18 12:56:39 2016 -0700
@@ -512,6 +512,7 @@
 REQUIRED_PACKAGES += developer/gnu-binutils
 REQUIRED_PACKAGES += library/libedit
 REQUIRED_PACKAGES += library/libffi
+REQUIRED_PACKAGES += library/libiomp5
 REQUIRED_PACKAGES += library/libxml2
 REQUIRED_PACKAGES += library/zlib
 REQUIRED_PACKAGES += runtime/perl-522
--- a/components/llvm/clang.p5m	Thu Aug 18 12:54:40 2016 -0700
+++ b/components/llvm/clang.p5m	Thu Aug 18 12:56:39 2016 -0700
@@ -146,5 +146,9 @@
 file path=usr/share/scan-view/GetRadarVersion.scpt
 file path=usr/share/scan-view/bugcatcher.ico
 license llvm.license license="University of Illinois/NCSA"
+# pkgdepend doesn't find the dependency on libiomp5 although
+# it is listed in REQUIRED_PACKAGES. So, we set it as an
+# explicit dependency here.
+depend type=require fmri=pkg:/library/libiomp5
 depend type=require fmri=pkg:/system/header
 
--- a/components/llvm/patches/010-solaris-clang-libclangBasic.patch	Thu Aug 18 12:54:40 2016 -0700
+++ b/components/llvm/patches/010-solaris-clang-libclangBasic.patch	Thu Aug 18 12:56:39 2016 -0700
@@ -1,4 +1,6 @@
 # 23701635 clang produces amd64 opcodes, but calls 32-bit assembler by default
+# 24378340 clang -fopenmp must include the path to the omp.h header file
+# 24378393 clang -fopenmp must define _OPENMP to 201307
 # 3.9.X for upstream.
 --- tools/clang/include/clang/Basic/LangOptions.def	2016-01-06 08:42:12.000000000 -0500
 +++ tools/clang/include/clang/Basic/LangOptions.def	2016-05-08 23:19:20.551431215 -0400
@@ -54,8 +56,8 @@
  
  unsigned Selector::getNumArgs() const {
 ###
---- tools/clang/lib/Basic/Targets.cpp	2016-02-19 08:40:14.000000000 -0900
-+++ tools/clang/lib/Basic/Targets.cpp	2016-07-06 07:39:20.069419785 -0800
+--- tools/clang/lib/Basic/Targets.cpp	2016-05-24 12:36:54.000000000 -0700
++++ tools/clang/lib/Basic/Targets.cpp	2016-08-08 08:06:27.116982930 -0700
 @@ -29,10 +29,11 @@
  #include "llvm/MC/MCSectionMachO.h"
  #include "llvm/Support/ErrorHandling.h"
@@ -97,7 +99,7 @@
 +
 +    Builder.defineMacro("__EXTENSIONS__", "1");
 +
-+    if (Opts.POSIXThreads) {
++    if (Opts.POSIXThreads || Opts.OpenMP) {
 +      Builder.defineMacro("_REENTRANT");
 +      Builder.defineMacro("__GTHREADS", "1");
 +    }
@@ -291,7 +293,7 @@
    }
  };
  
[email protected]@ -5893,6 +6066,10 @@
[email protected]@ -5899,6 +6072,10 @@
      case 'N': // Same as 'K' but zext (required for SIMode)
      case 'O': // The constant 4096
        return true;
--- a/components/llvm/patches/012-solaris-clang-libclangDriver.patch	Thu Aug 18 12:54:40 2016 -0700
+++ b/components/llvm/patches/012-solaris-clang-libclangDriver.patch	Thu Aug 18 12:56:39 2016 -0700
@@ -2,9 +2,11 @@
 # 23854357 clang should check for GNU ld
 # 22778650 clang should support OpenMP because it can
 # 24314745 clang should support PIE executables in Solaris
+# 24378340 clang -fopenmp must include the path to the omp.h header file
+# 24378393 clang -fopenmp must define _OPENMP to 201307
 # 3.9.X for upstream.
---- tools/clang/include/clang/Driver/Options.td	2016-01-06 16:27:42.000000000 -0500
-+++ tools/clang/include/clang/Driver/Options.td	2016-05-08 23:19:20.553431263 -0400
+--- tools/clang/include/clang/Driver/Options.td	2016-01-06 13:27:42.000000000 -0800
++++ tools/clang/include/clang/Driver/Options.td	2016-07-30 10:18:25.039779680 -0700
 @@ -669,6 +669,9 @@
    Flags<[CC1Option]>, HelpText<"Form fused FP ops (e.g. FMAs): fast (everywhere)"
    " | on (according to FP_CONTRACT pragma, default) | off (never fuse)">;
@@ -15,7 +17,30 @@
  def ffor_scope : Flag<["-"], "ffor-scope">, Group<f_Group>;
  def fno_for_scope : Flag<["-"], "fno-for-scope">, Group<f_Group>;
  
[email protected]@ -1312,6 +1315,12 @@
[email protected]@ -959,11 +962,17 @@
+ 
+ def fobjc_sender_dependent_dispatch : Flag<["-"], "fobjc-sender-dependent-dispatch">, Group<f_Group>;
+ def fomit_frame_pointer : Flag<["-"], "fomit-frame-pointer">, Group<f_Group>;
+-def fopenmp : Flag<["-"], "fopenmp">, Group<f_Group>, Flags<[CC1Option, NoArgumentUnused]>;
+-def fno_openmp : Flag<["-"], "fno-openmp">, Group<f_Group>, Flags<[NoArgumentUnused]>;
+-def fopenmp_EQ : Joined<["-"], "fopenmp=">, Group<f_Group>;
+-def fopenmp_use_tls : Flag<["-"], "fopenmp-use-tls">, Group<f_Group>, Flags<[NoArgumentUnused]>;
+-def fnoopenmp_use_tls : Flag<["-"], "fnoopenmp-use-tls">, Group<f_Group>, Flags<[CC1Option, NoArgumentUnused]>;
++def fopenmp : Flag<["-"], "fopenmp">, Group<f_Group>,
++              Flags<[CC1Option]>, HelpText<"Enable OpenMP">;
++def fno_openmp : Flag<["-"], "fno-openmp">, Group<f_Group>,
++                 Flags<[CC1Option]>, HelpText<"Disable OpenMP">;
++def fopenmp_EQ : Joined<["-"], "fopenmp=">, Group<f_Group>,
++                 Flags<[CC1Option]>,
++                 HelpText<"Use specified OpenMP Implementation">;
++def fopenmp_use_tls : Flag<["-"], "fopenmp-use-tls">, Group<f_Group>,
++                      Flags<[CC1Option]>, HelpText<"Use OpenMP TLS">;
++def fnoopenmp_use_tls : Flag<["-"], "fnoopenmp-use-tls">, Group<f_Group>,
++                        Flags<[CC1Option]>, HelpText<"Do not use OpenMP TLS">;
+ 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">;
[email protected]@ -1312,6 +1321,12 @@
  def meabi : Separate<["-"], "meabi">, Group<m_Group>, Flags<[CC1Option]>,
    HelpText<"Set EABI type, e.g. 4, 5 or gnu (default depends on triple)">;
  
@@ -28,7 +53,7 @@
  def mmmx : Flag<["-"], "mmmx">, Group<m_x86_Features_Group>;
  def mno_3dnowa : Flag<["-"], "mno-3dnowa">, Group<m_x86_Features_Group>;
  def mno_3dnow : Flag<["-"], "mno-3dnow">, Group<m_x86_Features_Group>;
[email protected]@ -1954,6 +1963,7 @@
[email protected]@ -1954,6 +1969,7 @@
  
  def fprofile_dir : Joined<["-"], "fprofile-dir=">, Group<clang_ignored_gcc_optimization_f_Group>;
  
@@ -55,8 +80,8 @@
                            New.includeSuffix());
  
 ###
---- tools/clang/lib/Driver/ToolChains.cpp	2016-02-16 10:56:48.000000000 -0900
-+++ tools/clang/lib/Driver/ToolChains.cpp	2016-06-30 09:27:01.031173505 -0800
+--- tools/clang/lib/Driver/ToolChains.cpp	2016-02-16 11:56:48.000000000 -0800
++++ tools/clang/lib/Driver/ToolChains.cpp	2016-08-04 06:09:44.734198665 -0700
 @@ -28,12 +28,15 @@
  #include "llvm/ProfileData/InstrProf.h"
  #include "llvm/Support/ErrorHandling.h"
@@ -174,7 +199,7 @@
    switch (TargetTriple.getArch()) {
    case llvm::Triple::aarch64:
      LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs));
[email protected]@ -3302,69 +3321,783 @@
[email protected]@ -3302,69 +3321,828 @@
  }
  
  /// Solaris - Solaris tool chain which can call as(1) and ld(1) directly.
@@ -225,8 +250,7 @@
 +      findGCCIncludeDirs(Triple, Args);
 +      findGCCInternalLibDir(Triple, Args);
 +    }
- 
--  GCCInstallation.init(Triple, Args);
++
 +    if (Arg *A = Args.getLastArg(options::OPT_fuse_ld_EQ)) {
 +      Linker = A->getValue();
 +      if (Linker == "bfd")
@@ -248,9 +272,7 @@
 +      }
 +    }
  
--  path_list &Paths = getFilePaths();
--  if (GCCInstallation.isValid())
--    addPathIfExists(D, GCCInstallation.getInstallPath(), Paths);
+-  GCCInstallation.init(Triple, Args);
 +    if (Arg *A = Args.getLastArg(options::OPT_fuse_as_EQ)) {
 +      Assembler = A->getValue();
 +      if (Assembler == "llvm")
@@ -265,7 +287,10 @@
 +                 (Assembler == "solaris"))
 +        D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
 +    }
-+
+ 
+-  path_list &Paths = getFilePaths();
+-  if (GCCInstallation.isValid())
+-    addPathIfExists(D, GCCInstallation.getInstallPath(), Paths);
 +    getProgramPaths().push_back(GCCInstallDir);
  
 -  addPathIfExists(D, getDriver().getInstalledDir(), Paths);
@@ -339,12 +364,12 @@
 +                                  llvm::opt::ArgStringList &CC1Args) const {
 +  if (!llvm::sys::fs::exists(Base + Suffix))
 +    return false;
++
++  addSystemInclude(DriverArgs, CC1Args, Base);
++  addSystemInclude(DriverArgs, CC1Args, Base + Suffix);
  
 -void Solaris::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
 -                                           ArgStringList &CC1Args) const {
-+  addSystemInclude(DriverArgs, CC1Args, Base);
-+  addSystemInclude(DriverArgs, CC1Args, Base + Suffix);
-+
 +  if ((GCCMultiarchTriple.empty() && TargetMultiarchTriple.empty()) ||
 +      llvm::sys::fs::exists(Base + Suffix + "/" + GCCTriple + IncludeSuffix)) {
 +    addSystemInclude(DriverArgs,
@@ -356,6 +381,11 @@
 +                     Base + "/" + TargetMultiarchTriple + Suffix);
 +  }
 +
++  if (DriverArgs.hasArg(options::OPT_fopenmp) ||
++      DriverArgs.hasArg(options::OPT_fopenmp_EQ)) {
++    addSystemInclude(DriverArgs, CC1Args, "/usr/include/iomp5");
++  }
++
 +  addSystemInclude(DriverArgs, CC1Args, Base + "/backward");
 +  addSystemInclude(DriverArgs, CC1Args, Base + Suffix + "/backward");
 +  return true;
@@ -441,6 +471,10 @@
 +    }
 +  }
 +
++  if (DriverArgs.hasArg(options::OPT_fopenmp) ||
++      DriverArgs.hasArg(options::OPT_fopenmp_EQ))
++    addSystemInclude(DriverArgs, CC1Args, "/usr/include/iomp5");
++
 +  addExternCSystemInclude(DriverArgs, CC1Args, "/usr/include");
 +}
 +
@@ -473,11 +507,47 @@
 +
 +  DriverArgs.ClaimAllArgs(options::OPT_fabi_version_EQ);
 +
++  if (Arg *A = DriverArgs.getLastArg(options::OPT_fopenmp))
++    CC1Args.push_back(DriverArgs.MakeArgString("-fopenmp"));
++
++  if (Arg *A = DriverArgs.getLastArg(options::OPT_fno_openmp))
++    CC1Args.push_back(DriverArgs.MakeArgString("-fno-openmp"));
++
++  if (Arg *A = DriverArgs.getLastArg(options::OPT_fopenmp_EQ)) {
++    std::string V = A->getValue();
++    if (V != "libiomp5") {
++      const Driver &D = getDriver();
++      D.Diag(diag::err_drv_unsupported_opt) << V.c_str();
++    }
++
++    std::string fompeq="-fopenmp=";
++    fompeq += V;
++    CC1Args.push_back(DriverArgs.MakeArgString(fompeq.c_str()));
++  }
++
++  if (Arg *A = DriverArgs.getLastArg(options::OPT_fopenmp_use_tls))
++    CC1Args.push_back(DriverArgs.MakeArgString("-fopenmp-use-tls"));
++
++  if (Arg *A = DriverArgs.getLastArg(options::OPT_fnoopenmp_use_tls))
++    CC1Args.push_back(DriverArgs.MakeArgString("-fnoopenmp-use-tls"));
++
++  if (Arg *A = DriverArgs.getLastArg(options::OPT_fopenmp_is_device)) {
++    CC1Args.push_back(DriverArgs.MakeArgString("-fopenmp-is-device"));
++  }
++
 +  if (Arch == llvm::Triple::sparc || Arch == llvm::Triple::sparcv9) {
 +    CC1Args.push_back(DriverArgs.MakeArgString("-target-feature"));
 +    CC1Args.push_back(DriverArgs.MakeArgString("+hwcap"));
 +  }
 +
++  if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
++    if (Arg *A = DriverArgs.getLastArg(options::OPT_fomit_frame_pointer))
++      CC1Args.push_back(DriverArgs.MakeArgString("-fomit-frame-pointer"));
++
++    if (Arg *A = DriverArgs.getLastArg(options::OPT_fno_omit_frame_pointer))
++      CC1Args.push_back(DriverArgs.MakeArgString("-fno-omit-frame-pointer"));
++  }
++
 +  bool SeenVIS = false;
 +  bool SeenVIS2 = false;
 +  bool SeenVIS3 = false;
@@ -993,7 +1063,7 @@
    }
  }
  
[email protected]@ -3404,6 +4137,27 @@
[email protected]@ -3404,6 +4182,27 @@
    UbuntuVivid,
    UbuntuWily,
    UbuntuXenial,
@@ -1021,7 +1091,7 @@
    UnknownDistro
  };
  
[email protected]@ -3421,6 +4175,10 @@
[email protected]@ -3421,6 +4220,10 @@
    return Distro >= UbuntuHardy && Distro <= UbuntuXenial;
  }
  
@@ -1032,7 +1102,7 @@
  static Distro DetectDistro(const Driver &D, llvm::Triple::ArchType Arch) {
    llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File =
        llvm::MemoryBuffer::getFile("/etc/lsb-release");
[email protected]@ -3488,6 +4246,59 @@
[email protected]@ -3488,6 +4291,59 @@
      return UnknownDistro;
    }
  
@@ -1215,7 +1285,7 @@
    MinGW(const Driver &D, const llvm::Triple &Triple,
 ###
 --- tools/clang/lib/Driver/Tools.cpp	2016-02-12 14:51:41.000000000 -0800
-+++ tools/clang/lib/Driver/Tools.cpp	2016-07-18 19:13:48.364415520 -0700
++++ tools/clang/lib/Driver/Tools.cpp	2016-08-04 06:17:07.826616905 -0700
 @@ -43,15 +43,22 @@
  #include "llvm/Support/raw_ostream.h"
  #include "llvm/Support/TargetParser.h"
@@ -2053,7 +2123,7 @@
      }
    }
  
[email protected]@ -7431,48 +7965,264 @@
[email protected]@ -7431,48 +7965,268 @@
      assert(Output.isNothing() && "Invalid output.");
    }
  
@@ -2291,7 +2361,11 @@
 +
 +  if (!Args.hasArg(options::OPT_nostdlib) &&
 +      !Args.hasArg(options::OPT_nodefaultlibs)) {
-+    addOpenMPRuntime(CmdArgs, TC, Args);
++    if (Args.hasArg(options::OPT_fopenmp) ||
++        Args.hasArg(options::OPT_fopenmp_EQ)) {
++      addOpenMPRuntime(CmdArgs, TC, Args);
++      CmdArgs.push_back("-latomic");
++    }
 +
 +    if (D.CCCIsCXX())
 +      TC.AddCXXStdlibLibArgs(Args, CmdArgs);
@@ -2343,7 +2417,7 @@
  void openbsd::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
                                        const InputInfo &Output,
                                        const InputInfoList &Inputs,
[email protected]@ -8623,6 +9373,41 @@
[email protected]@ -8623,6 +9377,41 @@
      CmdArgs.push_back("-ldl");
  }
  
--- a/components/llvm/patches/013-solaris-clang-libclangFrontend.patch	Thu Aug 18 12:54:40 2016 -0700
+++ b/components/llvm/patches/013-solaris-clang-libclangFrontend.patch	Thu Aug 18 12:56:39 2016 -0700
@@ -1,7 +1,18 @@
+# 24378340 clang -fopenmp must include the path to the omp.h header file
+# 24378393 clang -fopenmp must define _OPENMP to 201307
 # Solaris GCC Toolchain.
 # 3.9.X upstream.
---- tools/clang/lib/Frontend/CompilerInvocation.cpp	2016-01-12 16:01:56.000000000 -0500
-+++ tools/clang/lib/Frontend/CompilerInvocation.cpp	2016-05-08 23:19:20.574431774 -0400
+--- tools/clang/lib/Frontend/CompilerInvocation.cpp	2016-01-12 13:01:56.000000000 -0800
++++ tools/clang/lib/Frontend/CompilerInvocation.cpp	2016-08-08 08:15:38.179011582 -0700
[email protected]@ -1424,7 +1424,7 @@
+   return DefaultVisibility;
+ }
+ 
+-static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
++static void ParseLangArgs(LangOptions &Opts, InputArgList &Args, InputKind IK,
+                           DiagnosticsEngine &Diags) {
+   // FIXME: Cleanup per-file based stuff.
+   LangStandard::Kind LangStd = LangStandard::lang_unspecified;
 @@ -1718,6 +1718,7 @@
    Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls);
    Opts.PackStruct = getLastArgIntValue(Args, OPT_fpack_struct_EQ, 0, Diags);
@@ -10,6 +21,30 @@
    Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags);
    Opts.PIELevel = getLastArgIntValue(Args, OPT_pie_level, 0, Diags);
    Opts.Static = Args.hasArg(OPT_static_define);
[email protected]@ -1811,7 +1812,13 @@
+   }
+ 
+   // Check if -fopenmp is specified.
+-  Opts.OpenMP = Args.hasArg(options::OPT_fopenmp);
++  Opts.OpenMP = Args.getLastArgNoClaim(options::OPT_fopenmp) ||
++    Args.getLastArgNoClaim(options::OPT_fopenmp_EQ);
++
++  // OpenMP implies threads.
++  if (Opts.OpenMP)
++    Opts.POSIXThreads = Opts.OpenMP;
++
+   Opts.OpenMPUseTLS =
+       Opts.OpenMP && !Args.hasArg(options::OPT_fnoopenmp_use_tls);
+   Opts.OpenMPIsDevice =
[email protected]@ -1819,7 +1826,6 @@
+ 
+   // Get the OpenMP target triples if any.
+   if (Arg *A = Args.getLastArg(options::OPT_omptargets_EQ)) {
+-
+     for (unsigned i = 0; i < A->getNumValues(); ++i) {
+       llvm::Triple TT(A->getValue(i));
+ 
+###
 --- tools/clang/lib/Frontend/InitHeaderSearch.cpp	2015-12-29 22:40:23.000000000 -0500
 +++ tools/clang/lib/Frontend/InitHeaderSearch.cpp	2016-05-08 23:19:20.575431798 -0400
 @@ -118,7 +118,7 @@
--- a/components/llvm/patches/031-solaris-build-system.patch	Thu Aug 18 12:54:40 2016 -0700
+++ b/components/llvm/patches/031-solaris-build-system.patch	Thu Aug 18 12:56:39 2016 -0700
@@ -1,4 +1,5 @@
 # 24314621 LLVM should build using the new CMake based build system
+# 24378393 clang -fopenmp must define _OPENMP to 201307
 # CMake parts for upstream, Solaris-specific parts no.
 --- Makefile.config.in	2015-08-07 12:44:47.000000000 -0400
 +++ Makefile.config.in	2016-05-08 23:19:20.538430899 -0400
@@ -786,7 +787,7 @@
    "Default <path> to all compiler invocations for --sysroot=<path>." )
  
 +if(CMAKE_HOST_SOLARIS)
-+  set(CLANG_DEFAULT_OPENMP_RUNTIME "libgomp" CACHE STRING
++  set(CLANG_DEFAULT_OPENMP_RUNTIME "libiomp5" CACHE STRING
 +      "Default OpenMP runtime used by -fopenmp.")
 +else()
  set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING