llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: Simi Pallipurath (simpal01)

<details>
<summary>Changes</summary>

The current baremetal driver implementation does not have a way to derive the 
target-triple-level include path within the sysroot.

This feature is especially useful in setups where header paths deviate from the 
default bare-metal assumptions. For example, when headers are shared across 
target triples, it becomes necessary to organise them under 
target-triple-specific directories to ensure correct resolution..

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


1 Files Affected:

- (modified) clang/lib/Driver/ToolChains/BareMetal.cpp (+14-1) 


``````````diff
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 9b7f58c392885..d048f228f4572 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -408,6 +408,8 @@ void BareMetal::AddClangSystemIncludeArgs(const ArgList 
&DriverArgs,
   if (DriverArgs.hasArg(options::OPT_nostdlibinc))
     return;
 
+  const Driver &D = getDriver();
+
   if (std::optional<std::string> Path = getStdlibIncludePath())
     addSystemInclude(DriverArgs, CC1Args, *Path);
 
@@ -418,6 +420,13 @@ void BareMetal::AddClangSystemIncludeArgs(const ArgList 
&DriverArgs,
       llvm::sys::path::append(Dir, M.includeSuffix());
       llvm::sys::path::append(Dir, "include");
       addSystemInclude(DriverArgs, CC1Args, Dir.str());
+
+      Dir = SysRootDir;
+      llvm::sys::path::append(Dir, getTripleString());
+      if (D.getVFS().exists(Dir)) {
+        llvm::sys::path::append(Dir, "include");
+        addSystemInclude(DriverArgs, CC1Args, Dir.str());
+      }
     }
   }
 }
@@ -498,9 +507,13 @@ void BareMetal::AddClangCXXStdlibIncludeArgs(const ArgList 
&DriverArgs,
         addSystemInclude(DriverArgs, CC1Args, TargetDir.str());
         break;
       }
-      // Add generic path if nothing else succeeded so far.
+      // Add generic paths if nothing else succeeded so far.
       llvm::sys::path::append(Dir, "include", "c++", "v1");
       addSystemInclude(DriverArgs, CC1Args, Dir.str());
+      Dir = SysRootDir;
+      llvm::sys::path::append(Dir, Target, "include", "c++", "v1");
+      if (D.getVFS().exists(Dir))
+        addSystemInclude(DriverArgs, CC1Args, Dir.str());
       break;
     }
     case ToolChain::CST_Libstdcxx: {

``````````

</details>


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

Reply via email to