]> granicus.if.org Git - clang/commitdiff
[WebAssembly] Modernize include path handling
authorSam Clegg <sbc@chromium.org>
Thu, 13 Jun 2019 09:42:43 +0000 (09:42 +0000)
committerSam Clegg <sbc@chromium.org>
Thu, 13 Jun 2019 09:42:43 +0000 (09:42 +0000)
Move include path construction from
InitHeaderSearch::AddDefaultIncludePaths in the Driver which appears
to be the more modern/correct way of doing things.

Differential Revision: https://reviews.llvm.org/D63030

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363241 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains/WebAssembly.cpp
lib/Frontend/InitHeaderSearch.cpp
test/Driver/wasm-toolchain.cpp

index 9f63d2e374b2750b734fb12677146160ad7db10c..a6a881873e20d7731cb8e2ad3a278bc27b5b9650 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "WebAssembly.h"
 #include "CommonArgs.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
@@ -170,14 +171,39 @@ WebAssembly::GetCXXStdlibType(const ArgList &Args) const {
 
 void WebAssembly::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
                                             ArgStringList &CC1Args) const {
-  if (!DriverArgs.hasArg(options::OPT_nostdinc)) {
-    if (getTriple().getOS() != llvm::Triple::UnknownOS) {
-      const std::string MultiarchTriple =
-          getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot);
-      addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include/" + MultiarchTriple);
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+    return;
+
+  const Driver &D = getDriver();
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+    SmallString<128> P(D.ResourceDir);
+    llvm::sys::path::append(P, "include");
+    addSystemInclude(DriverArgs, CC1Args, P);
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+    return;
+
+  // Check for configure-time C include directories.
+  StringRef CIncludeDirs(C_INCLUDE_DIRS);
+  if (CIncludeDirs != "") {
+    SmallVector<StringRef, 5> dirs;
+    CIncludeDirs.split(dirs, ":");
+    for (StringRef dir : dirs) {
+      StringRef Prefix =
+          llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
+      addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
     }
-    addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include");
+    return;
+  }
+
+  if (getTriple().getOS() != llvm::Triple::UnknownOS) {
+    const std::string MultiarchTriple =
+        getMultiarchTriple(D, getTriple(), D.SysRoot);
+    addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include/" + MultiarchTriple);
   }
+  addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
 }
 
 void WebAssembly::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
@@ -188,7 +214,8 @@ void WebAssembly::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
       const std::string MultiarchTriple =
           getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot);
       addSystemInclude(DriverArgs, CC1Args,
-                       getDriver().SysRoot + "/include/" + MultiarchTriple + "/c++/v1");
+                       getDriver().SysRoot + "/include/" + MultiarchTriple +
+                           "/c++/v1");
     }
     addSystemInclude(DriverArgs, CC1Args,
                      getDriver().SysRoot + "/include/c++/v1");
index e6cd8235b019162c7fe02fec8009ef084941186c..d65d13489dc42fdb503eb4e2a33aea633109bc08 100644 (file)
@@ -414,9 +414,11 @@ void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
   default:
     break; // Everything else continues to use this routine's logic.
 
+  case llvm::Triple::Emscripten:
   case llvm::Triple::Linux:
   case llvm::Triple::Hurd:
   case llvm::Triple::Solaris:
+  case llvm::Triple::WASI:
     return;
 
   case llvm::Triple::Win32:
@@ -424,6 +426,12 @@ void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
         triple.isOSBinFormatMachO())
       return;
     break;
+
+  case llvm::Triple::UnknownOS:
+    if (triple.getArch() == llvm::Triple::wasm32 ||
+        triple.getArch() == llvm::Triple::wasm64)
+      return;
+    break;
   }
 
   // All header search logic is handled in the Driver for Darwin.
index fb845d677e29ebf64912c87ed3858dec82ed9f6c..18ebddc2093bf563838428e1ac012f186f5e8a81 100644 (file)
 // RUN: %clangxx -### -no-canonical-prefixes -target wasm32-wasi --sysroot=/foo --stdlib=c++ %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=COMPILE %s
 // COMPILE: clang{{.*}}" "-cc1"
+// COMPILE: "-resource-dir" "[[RESOURCE_DIR:[^"]*]]"
 // COMPILE: "-isysroot" "/foo"
 // COMPILE: "-internal-isystem" "/foo/include/wasm32-wasi/c++/v1"
 // COMPILE: "-internal-isystem" "/foo/include/c++/v1"
+// COMPILE: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
 // COMPILE: "-internal-isystem" "/foo/include/wasm32-wasi"
 // COMPILE: "-internal-isystem" "/foo/include"