This is an archive of the discontinued LLVM Phabricator instance.

[clang] Re-apply change to avoid passing -stdlib=libc++ spuriously to CC1 on Darwin
ClosedPublic

Authored by ldionne on Dec 13 2022, 7:38 AM.

Details

Summary

Previously, we would be passing down -stdlib=libc++ from the Driver
to CC1 whenever the default standard library on the platform was libc++,
even if -stdlib= had not been passed to the Driver. This meant that we
would pass -stdlib=libc++ in nonsensical circumstances, such as when
compiling C code.

This logic had been added in b534ce46bd40 to make sure that header
search paths were set up properly. However, since libc++ is now the
default Standard Library on Darwin, passing this explicitly is not
required anymore. Indeed, if no -stdlib= is specified, CC1 will end
up using libc++ if it queries which standard library to use, without
having to be told.

Not passing -stdlib= at all to CC1 on Darwin should become possible
once CC1 stops relying on it to set up framework search paths.

Furthermore, this commit also removes a diagnostic checking whether the
deployment target is too old to support libc++. Nowadays, all supported
deployment targets use libc++ and compiling with libstdc++ is not
supported anymore. The Driver was the wrong place to issue this
diagnostic since it doesn't know whether libc++ will actually be linked
against (e.g. C vs C++), which would lead to spurious diagnostics.
Given that these targets are not supported anymore, we simply drop
the diagnostic instead of trying to refactor it into CC1.

This is a re-application of 6540f32db09c which had been reverted in
49dd02bd0819 because it broke a compiler-rt test. The test had broken
because we were compiling C code and passing -stdlib=libc++, which Clang
will now warn about.

rdar://103198514

Diff Detail

Event Timeline

ldionne created this revision.Dec 13 2022, 7:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2022, 7:38 AM
ldionne requested review of this revision.Dec 13 2022, 7:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2022, 7:38 AM
arphaman accepted this revision.Dec 13 2022, 10:24 AM

Great, thank you!

This revision is now accepted and ready to land.Dec 13 2022, 10:24 AM
hans added a subscriber: hans.Dec 20 2022, 8:45 AM

This seems to have broken the instrprof-darwin-exports.c test, see e.g. https://green.lab.llvm.org/green/job/clang-stage1-RA/32351/

I'll revert for now.

This seems to have broken the instrprof-darwin-exports.c test, see e.g. https://green.lab.llvm.org/green/job/clang-stage1-RA/32351/

I'll revert for now.

It seems you still need to claim OPT_stdlib_EQ so it doesn't complain about unused argument when you pass stdlib when compiling C code.

ldionne reopened this revision.Dec 20 2022, 3:20 PM

This seems to have broken the instrprof-darwin-exports.c test, see e.g. https://green.lab.llvm.org/green/job/clang-stage1-RA/32351/

I'll revert for now.

It seems you still need to claim OPT_stdlib_EQ so it doesn't complain about unused argument when you pass stdlib when compiling C code.

Thanks for taking a look. I actually think that the current behavior is correct -- we don't use -stdlib=libc++ in C mode, and I don't think we should be silencing the warning. If someone compiles C code with -stdlib=libc++, I think it's OK to tell them that we're ignoring the flag.

Instead, I think the "fix" needs to be done within compiler-rt.

This revision is now accepted and ready to land.Dec 20 2022, 3:20 PM
ldionne updated this revision to Diff 484403.Dec 20 2022, 3:24 PM
ldionne retitled this revision from [clang] Don't spuriously pass -stdlib=libc++ to CC1 on Darwin to [clang] Re-apply change to avoid passing -stdlib=libc++ spuriously to CC1 on Darwin.
ldionne edited the summary of this revision. (Show Details)

Fix compiler-rt test.

Herald added a project: Restricted Project. · View Herald TranscriptDec 20 2022, 3:24 PM
Herald added subscribers: Restricted Project, Enna1. · View Herald Transcript
ldionne added inline comments.Dec 20 2022, 3:28 PM
compiler-rt/test/profile/lit.cfg.py
45–51

This is not great, but I think this is OK as a stopgap. I don't want to remove -stdlib=libc++ from target_cflags in this patch since it may cause other issues in the test suite.

I'll ship this now since CI seems happy and I reproduced the issue and saw it was fixed by my new change.