This is an archive of the discontinued LLVM Phabricator instance.

Add a new warning to notify users of mismatched SDK and deployment target
ClosedPublic

Authored by beanz on Mar 11 2016, 8:48 AM.

Details

Summary

This patch adds a new driver warning -Wincompatible-sdk which notifies the user when they are mismatching the version min options and the sysroot.

The patch works by checking the sysroot (if present) for an SDK name, then matching that against the target platform. In the case of a mismatch it logs a warning.

Diff Detail

Repository
rL LLVM

Event Timeline

beanz updated this revision to Diff 50437.Mar 11 2016, 8:48 AM
beanz retitled this revision from to Add a new warning to notify users of mismatched SDK and deployment target.
beanz updated this object.
beanz added a reviewer: bob.wilson.
beanz added a subscriber: cfe-commits.
bob.wilson edited edge metadata.Mar 15 2016, 4:16 PM

This is a good idea overall. See comments.

include/clang/Basic/DiagnosticDriverKinds.td
198 ↗(On Diff #50437)

Instead of the driver option, you should add this to the diagnostic: InGroup<DiagGroup<"incompatible-sdk">>

include/clang/Driver/Options.td
1090 ↗(On Diff #50437)

You should not need to add this option. See above.

lib/Driver/ToolChains.cpp
333 ↗(On Diff #50437)

Please add a space before the open paren.

742 ↗(On Diff #50437)

Please add a space before the open paren.

750 ↗(On Diff #50437)

Please add a space before the open paren. You should run the patch through clang-format since you have several formatting issues.

Excuse me for intruding, but from what I see, this warning applies only to Apple SDK. Since SDK could mean everything, what about naming the warning accordingly, like '-Wincompatible-apple-sdk' or '-Wapple-incompatible-sdk' and adjust the description accordingly?

Yes, in its current usage this warning is only used for Apple's SDKs, but how does it help to put "apple" in the name of the diagnostic? Are you concerned about a name conflict with a similar diagnostic for non-Apple SDKs?

I'm more concerned about some users who might think that option would work also with their favourite sdk (visual studio comes into mind as a common sdk).

beanz added a comment.Mar 28 2016, 9:20 AM

Perhaps naming this warning 'incompatible-sdk' isn't the best name. I can see how it would cause some confusion for Visual Studio users. On Darwin the SDK is the collection of headers and libraries you link against, not the toolkit you have installed.

Perhaps calling the warning 'incompatible-sysroot' is a better name. Even though this patch only implements it for Darwin I imagine that similar functionality could be added for Windows and Linux too. The idea being to have the compiler perform some basic check to ensure that the headers and libraries you are building against actually support your target.

Updated patches coming shortly.

beanz updated this revision to Diff 51813.Mar 28 2016, 11:31 AM
beanz edited edge metadata.

Updates based on review feedback.

rsmith added a subscriber: rsmith.Apr 27 2016, 6:00 PM
rsmith added inline comments.
lib/Driver/ToolChains.cpp
718–720 ↗(On Diff #51813)

This seems to get a couple of corner cases wrong (/ between the platform name and .sdk, .sdk not at the end of the path component, ...). Have you considered using llvm::sys::path's path iterators here? Not a big deal either way, though.

722 ↗(On Diff #51813)

According to slice's documentation, if EndSDK < BeginSDK + 5, this slice call will return a slice from BeginSDK + 5 to the end of the string, and you won't be checking for a .sdk prefix as you intended to.

rsmith added inline comments.Apr 27 2016, 6:03 PM
lib/Driver/ToolChains.cpp
722 ↗(On Diff #51813)

Huh. That's a bug in slice's documentation (fixed in r267831).

beanz updated this revision to Diff 55472.Apr 28 2016, 1:07 PM

Use llvm::sys::path::const_iterator instead of hand slicing the paths, based on feedback from @rsmith.

Thanks,
-Chris

rsmith added inline comments.Apr 28 2016, 2:45 PM
lib/Driver/ToolChains.cpp
722–733 ↗(On Diff #55472)

Can you share some of the code between the parsing the SDK version out of -isysroot here and above?

beanz updated this revision to Diff 55652.Apr 29 2016, 1:03 PM

Cleanup and refactoring based on feedback from @rsmith.

rsmith accepted this revision.Apr 29 2016, 3:29 PM
rsmith added a reviewer: rsmith.
rsmith added inline comments.
lib/Driver/ToolChains.cpp
733 ↗(On Diff #55652)

I assume it's intentional that you allow targeting FooOS with a sysroot for FooSimulator and vice versa?

This revision is now accepted and ready to land.Apr 29 2016, 3:29 PM
beanz added a comment.Apr 29 2016, 3:33 PM

Thanks!

Will commit soon.

lib/Driver/ToolChains.cpp
733 ↗(On Diff #55652)

Yes. It turns out that setting the iOS version min flag when using the simulator SDK is *way* too common of a case to warn about, and since it all turns into the same load command anyways it doesn't matter too much.

This revision was automatically updated to reflect the committed changes.