[PATCH][Solaris] Use the GCC Installation detector to add the C++ include paths

Xan López via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 03:16:36 PDT 2015


Hi Yaron, Rafael,

thanks, I updated the patch with a test. Please note I'm using the
testing ifrastructure already created in a previous patch Rafael
reviewed once (that's why the sysroot is not created, among other
things).

Patch attached.

On Wed, Aug 05, 2015 at 04:54:28PM +0300, Yaron Keren wrote:
> I made similar test for mingw toolchain in clang/test/Driver/mingw.cpp :
> create a directory structure under Inputs, direct clang to it using
> --sysroot and test that the expected directories are found.
> 
> 
> 
> 2015-08-05 16:15 GMT+03:00 Rafael Espíndola <rafael.espindola at gmail.com>:
> 
> > This looks ok, but can you add a testcase?
> >
> > On 28 July 2015 at 06:20, Xan López <xan at igalia.com> wrote:
> > > A follow up to the previous patch, this gets rid of the last hardcoded
> > > path (and moves it to its proper place).
> > >
> > > _______________________________________________
> > > llvm-commits mailing list
> > > llvm-commits at cs.uiuc.edu
> > > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> > >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> >
-------------- next part --------------
>From f69999e256acdac7645537764de79e45aeb5876a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Xan=20L=C3=B3pez?= <xan at igalia.com>
Date: Thu, 23 Jul 2015 16:39:08 +0200
Subject: [PATCH] [Solaris] Move the C++ includes management to the Driver

We can also use the detected GCC installation now, instead of
hardcoding the C++ includes path.
---
 lib/Driver/ToolChains.cpp             | 25 +++++++++++++++++++++++++
 lib/Driver/ToolChains.h               |  4 ++++
 lib/Frontend/InitHeaderSearch.cpp     |  9 ---------
 test/Driver/solaris-header-search.cpp | 11 +++++++++++
 4 files changed, 40 insertions(+), 9 deletions(-)
 create mode 100644 test/Driver/solaris-header-search.cpp

diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 5c04115..4f486c5 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -2953,6 +2953,31 @@ Tool *Solaris::buildAssembler() const {
 
 Tool *Solaris::buildLinker() const { return new tools::solaris::Linker(*this); }
 
+void Solaris::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
+                                           ArgStringList &CC1Args) const {
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
+      DriverArgs.hasArg(options::OPT_nostdincxx))
+    return;
+
+  // Include the support directory for things like xlocale and fudged system
+  // headers.
+  addSystemInclude(DriverArgs, CC1Args, "/usr/include/c++/v1/support/solaris");
+
+  if (GCCInstallation.isValid()) {
+    GCCVersion Version = GCCInstallation.getVersion();
+    addSystemInclude(DriverArgs, CC1Args,
+                     getDriver().SysRoot + "/usr/gcc/" +
+                     Version.MajorStr + "." +
+                     Version.MinorStr +
+                     "/include/c++/" + Version.Text);
+    addSystemInclude(DriverArgs, CC1Args,
+                     getDriver().SysRoot + "/usr/gcc/" + Version.MajorStr +
+                     "." + Version.MinorStr + "/include/c++/" +
+                     Version.Text + "/" +
+                     GCCInstallation.getTriple().str());
+  }
+}
+
 /// Distribution (very bare-bones at the moment).
 
 enum Distro {
diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h
index c6883d8..253c918 100644
--- a/lib/Driver/ToolChains.h
+++ b/lib/Driver/ToolChains.h
@@ -527,6 +527,10 @@ public:
 
   bool IsIntegratedAssemblerDefault() const override { return true; }
 
+  void AddClangCXXStdlibIncludeArgs(
+      const llvm::opt::ArgList &DriverArgs,
+      llvm::opt::ArgStringList &CC1Args) const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
diff --git a/lib/Frontend/InitHeaderSearch.cpp b/lib/Frontend/InitHeaderSearch.cpp
index e3a17c9..f68cf0f 100644
--- a/lib/Frontend/InitHeaderSearch.cpp
+++ b/lib/Frontend/InitHeaderSearch.cpp
@@ -404,10 +404,6 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOp
     AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
                                 "", "", "", triple);
     break;
-  case llvm::Triple::Solaris:
-    AddGnuCPlusPlusIncludePaths("/usr/gcc/4.5/include/c++/4.5.2/",
-                                "i386-pc-solaris2.11", "", "", triple);
-    break;
   default:
     break;
   }
@@ -453,11 +449,6 @@ void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
           AddUnmappedPath(P, CXXSystem, false);
         }
       }
-      // On Solaris, include the support directory for things like xlocale and
-      // fudged system headers.
-      if (triple.getOS() == llvm::Triple::Solaris) 
-        AddPath("/usr/include/c++/v1/support/solaris", CXXSystem, false);
-      
       AddPath("/usr/include/c++/v1", CXXSystem, false);
     } else {
       AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
diff --git a/test/Driver/solaris-header-search.cpp b/test/Driver/solaris-header-search.cpp
new file mode 100644
index 0000000..667b2c0
--- /dev/null
+++ b/test/Driver/solaris-header-search.cpp
@@ -0,0 +1,11 @@
+// Test that the C++ headers are found.
+//
+// RUN: %clang -no-canonical-prefixes %s -### 2>&1 \
+// RUN:     --target=sparc-sun-solaris2.11 \
+// RUN:     --gcc-toolchain="" \
+// RUN:     --sysroot=%S/Inputs/sparc-sun-solaris2.11 \
+// RUN:   | FileCheck %s
+// CHECK: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
+// CHECK: "-internal-isystem" "{{.*}}/usr/include/c++/v1/support/solaris"
+// CHECK: "-internal-isystem" "{{.*}}/usr/gcc/4.8/include/c++/4.8.2"
+// CHECK: "-internal-isystem" "{{.*}}/usr/gcc/4.8/include/c++/4.8.2/sparc-sun-solaris2.11"
-- 
2.4.3



More information about the llvm-commits mailing list