llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: Joseph Huber (jhuber6)

<details>
<summary>Changes</summary>

Summary:
The LLVM-libc stores its headers in the target-specific include
directory. This PR makes the Linux toolchain include this directory when
the environment is LLVM. This should allow the following to work
correctly when building the LLVM libc

```shell
$&gt; clang --target=x86_64-unknown-linux-llvm -static foo.c
```

In the future we might want to consider making a separate toolchain, but
considering that the LLVM-libc intentionally shares a lot of
compatibility with GCC I thnk it's easier to just to do conditional
operations like this.


---
Full diff: https://github.com/llvm/llvm-project/pull/175593.diff


8 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Linux.cpp (+7) 
- (added) clang/test/Driver/Inputs/basic_llvm_linux_tree/bin/.keep () 
- (added) clang/test/Driver/Inputs/basic_llvm_linux_tree/include/c++/v1/.keep 
() 
- (added) 
clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/.keep
 () 
- (added) 
clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/c++/v1/.keep
 () 
- (added) 
clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/.keep
 () 
- (added) 
clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/crt0.o
 () 
- (added) clang/test/Driver/linux-llvm-toolchain.c (+3) 


``````````diff
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index cdbf21fb90263..da4aaa907dafb 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -747,6 +747,13 @@ void Linux::AddClangSystemIncludeArgs(const ArgList 
&DriverArgs,
   if (DriverArgs.hasArg(options::OPT_nostdlibinc))
     return;
 
+  // The LLVM-libc environment stores its C headers in the Clang include
+  // directory.
+  if (getTriple().getEnvironment() == llvm::Triple::LLVM) {
+    if (std::optional<std::string> Path = getStdlibIncludePath())
+      addSystemInclude(DriverArgs, CC1Args, *Path);
+  }
+
   // LOCAL_INCLUDE_DIR
   addSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/local/include"));
   // TOOL_INCLUDE_DIR
diff --git a/clang/test/Driver/Inputs/basic_llvm_linux_tree/bin/.keep 
b/clang/test/Driver/Inputs/basic_llvm_linux_tree/bin/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git 
a/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/c++/v1/.keep 
b/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/c++/v1/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git 
a/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/.keep
 
b/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git 
a/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/c++/v1/.keep
 
b/clang/test/Driver/Inputs/basic_llvm_linux_tree/include/x86_64-unknown-linux-llvm/c++/v1/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git 
a/clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/.keep
 
b/clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git 
a/clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/crt0.o
 
b/clang/test/Driver/Inputs/basic_llvm_linux_tree/lib/x86_64-unknown-linux-llvm/crt0.o
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/linux-llvm-toolchain.c 
b/clang/test/Driver/linux-llvm-toolchain.c
new file mode 100644
index 0000000000000..46632de779f25
--- /dev/null
+++ b/clang/test/Driver/linux-llvm-toolchain.c
@@ -0,0 +1,3 @@
+// RUN:   %clang -### --target=x86_64-unknown-linux-llvm 
--sysroot=%S/Inputs/basic_llvm_linux_tree \
+// RUN:     -ccc-install-dir %S/Inputs/basic_llvm_linux_tree/bin %s 2>&1 | 
FileCheck %s --check-prefix=CHECK-HEADERS
+// CHECK-HEADERS: "-cc1"{{.*}}"-isysroot"{{.*}}"-internal-isystem" 
"{{.*}}include/x86_64-unknown-linux-llvm"

``````````

</details>


https://github.com/llvm/llvm-project/pull/175593
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to