This is an archive of the discontinued LLVM Phabricator instance.

[clang] Don't look into <sysroot> for C++ headers if they are found alongside the toolchain
AbandonedPublic

Authored by ldionne on Jan 20 2021, 9:18 AM.

Details

Summary

Currently, Clang looks for libc++ headers alongside the installation
directory of Clang, and it also adds a search path for headers in the
-isysroot. This is problematic if headers are found in both the toolchain
and in the sysroot, since #include_next will end up finding the libc++
headers in the sysroot instead of the intended system headers.

This patch changes the logic such that if the toolchain contains libc++
headers, no C++ header paths are added in the sysroot. However, if the
toolchain does *not* contain libc++ headers, the sysroot is searched as
usual.

This should not be a breaking change, since any code that previously
relied on some libc++ headers being found in the sysroot suffered from
the #include_next issue described above, which renders any libc++ header
basically useless.

This is a cherry-pick of commit a3a24316087d0e1b4db0b8fee19cdee8b7968032.

Diff Detail

Event Timeline

ldionne created this revision.Jan 20 2021, 9:18 AM
ldionne requested review of this revision.Jan 20 2021, 9:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 20 2021, 9:18 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I would like to cherry-pick this change onto LLVM 11.1.0, if there is still time to do so. It is breaking Clang when the sysroot contains headers for libc++. Is it too late?

dexonsmith accepted this revision.Feb 8 2021, 11:57 AM

LGTM. Sorry for missing this earlier!

This revision is now accepted and ready to land.Feb 8 2021, 11:57 AM

Sorry, it's too late for 11.1.0.

ldionne abandoned this revision.Feb 8 2021, 2:09 PM