Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion clang/lib/Driver/ToolChains/BareMetal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -419,6 +421,12 @@ void BareMetal::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
llvm::sys::path::append(Dir, "include");
addSystemInclude(DriverArgs, CC1Args, Dir.str());
}
SmallString<128> Dir = SysRootDir;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd use copy constructor over assignment operator for consistency with the existing code.

Suggested change
SmallString<128> Dir = SysRootDir;
SmallString<128> Dir(SysRootDir);

llvm::sys::path::append(Dir, getTripleString());
if (D.getVFS().exists(Dir)) {
llvm::sys::path::append(Dir, "include");
addSystemInclude(DriverArgs, CC1Args, Dir.str());
}
}
}

Expand Down Expand Up @@ -498,9 +506,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());
Comment on lines +512 to +515
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this logic is unrelated to multilibs, this should be done inside AddCXXIncludePath.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AddCXXIncludePath(Path) is currently passed a path derived from a top-level include directory that isn’t rooted in the active --sysroot. What this PR is actually aiming for is to derive the target-triple-level include path within the sysroot itself. But here the sysroot computation happens after the AddCXXIncludePath(Path) call.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I still think we need to move this logic outside of the multilib loop to avoid adding the include directory multiple times. I think this entire loop might need to be restructured since I don't think it's actually correct, so it might be probably easiest for now to just move the new logic outside.

break;
}
case ToolChain::CST_Libstdcxx: {
Expand Down
Loading