Page MenuHomePhabricator

[CMake] Add option to switch default C++ stdlib
ClosedPublic

Authored by Hahnfeld on Jan 6 2016, 3:47 AM.

Details

Summary

With this option one can set the default library to use if no -stdlib= is provided on compiler invocation (currently hard coded libstdc++ which remains default)
Also add explicit option -stdlib=libstdc++ to tests that require it and would fail when you choose libc++.

Diff Detail

Repository
rL LLVM

Event Timeline

Hahnfeld updated this revision to Diff 44105.Jan 6 2016, 3:47 AM
Hahnfeld retitled this revision from to [CMake] Add option to switch default C++ stdlib.
Hahnfeld updated this object.
Hahnfeld added reviewers: chandlerc, mclow.lists, beanz.
Hahnfeld added a subscriber: cfe-commits.

Any comments on this change?

mcrosier resigned from this revision.Feb 1 2016, 9:53 AM
mcrosier removed a reviewer: mcrosier.
beanz edited edge metadata.Feb 9 2016, 8:53 AM

Is it correct to assume that all the test case changes are needed just to make the tests pass if you set CLANG_DEFAULT_CXX_STDLIB=libc++?

I'm not really comfortable approving this patch because I've made all of one or two changes ever to the driver, but I can try to pester someone else to take a gander. It doesn't look particularly invasive to me.

One comment inline.

lib/Driver/ToolChain.cpp
552 ↗(On Diff #44105)

There are two cases where this line would get hit:

(1) If the stdlib arg is an invalid library, it falls through here after printing the diagnostic
(2) if CLANG_DEFAULT_CXX_STDLIB is itself an invalid library value

Can you add a configure-time or compile time check to catch case 2?

rsmith added a subscriber: rsmith.Feb 9 2016, 7:46 PM

The direction here generally seems fine to me.

lib/Driver/ToolChain.cpp
538 ↗(On Diff #44105)

On Darwin, this default will be clobbered by the code in Darwin::TranslateArgs in ToolChains.cpp. On MIPS, this override will take no effect because GetCXXStdlibType is overridden.

Perhaps we could instead default CLANG_DEFAULT_CXX_STDLIB to "", and let the tool chain pick the default if it's neither specified at configure time nor on the command line.

Hahnfeld updated this revision to Diff 47441.Feb 10 2016, 4:07 AM
Hahnfeld edited edge metadata.

Address reviewers' comments:

  • check for valid CLANG_DEFAULT_CXX_STDLIB
  • generalize for Darwin and Bitrig by introducing GetDefaultCXXStdlibType
  • fallback to CLANG_DEFAULT_CXX_STDLIB if user choice is incorrect
Hahnfeld marked an inline comment as done.Feb 10 2016, 4:15 AM

Is it correct to assume that all the test case changes are needed just to make the tests pass if you set CLANG_DEFAULT_CXX_STDLIB=libc++?

[...]

Yes, most of the tests check for the correct libstdc++ include paths which are not met with libc++.

lib/Driver/ToolChain.cpp
549–550 ↗(On Diff #47441)

I have moved the behaviour from Darwin::TranslateArgs to Darwin::GetDefaultCXXStdlibType and added this method for Bitrig as well (which was straightforward). MIPS only allows libc++ so there is nothing the user can choose from...

I would have also liked to implement this for FreeBSD and NetBSD but their default library is dependent on the system version. While this wouldn't be a problem and could be implemented in GetDefaultCXXStdlibType, this would still be overriden by CLANG_DEFAULT_CXX_STDLIB which unfortunately fails the tests in test/Driver/{freebsd.c,netbsd.c}. Is it ok to leave this for now?

Everything about this looks reasonable to me.

Can you commit the test changes in a separate commit before committing the other changes? That way if something goes wrong the diff for the meat of the patch is a small diff.

rsmith accepted this revision.Feb 11 2016, 12:08 PM
rsmith added a reviewer: rsmith.
This revision is now accepted and ready to land.Feb 11 2016, 12:08 PM
This revision was automatically updated to reflect the committed changes.

Can you commit the test changes in a separate commit before committing the other changes? That way if something goes wrong the diff for the meat of the patch is a small diff.

Committed seperately in rL260661, thanks.