beanz created this revision. beanz added a reviewer: bob.wilson. beanz added a subscriber: cfe-commits.
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. http://reviews.llvm.org/D18088 Files: include/clang/Basic/DiagnosticDriverKinds.td include/clang/Driver/Options.td lib/Driver/ToolChains.cpp lib/Driver/ToolChains.h test/Driver/incompatible_sdk.c
Index: test/Driver/incompatible_sdk.c =================================================================== --- /dev/null +++ test/Driver/incompatible_sdk.c @@ -0,0 +1,10 @@ +// RUN: %clang -Wincompatible-sdk -isysroot SDKs/MacOSX10.9.sdk -mios-version-min=9.0 -S -o - %s 2>&1 | FileCheck -check-prefix CHECK-OSX-IOS %s +// RUN: %clang -Wincompatible-sdk -isysroot SDKs/iPhoneOS9.2.sdk -mwatchos-version-min=2.0 -S -o - %s 2>&1 | FileCheck -check-prefix CHECK-IOS-WATCHOS %s +// RUN: %clang -Wincompatible-sdk -isysroot SDKs/iPhoneOS9.2.sdk -mtvos-version-min=9.0 -S -o - %s 2>&1 | FileCheck -check-prefix CHECK-IOS-TVOS %s +// RUN: %clang -Wincompatible-sdk -isysroot SDKs/iPhoneSimulator9.2.sdk -mios-version-min=9.0 -S -o - %s 2>&1 | FileCheck -check-prefix CHECK-IOS-IOSSIM %s + +int main() { return 0; } +// CHECK-OSX-IOS: warning: using SDK for 'MacOSX10.9' but deploying to 'iPhone' +// CHECK-IOS-WATCHOS: warning: using SDK for 'iPhoneOS9.2' but deploying to 'Watch' +// CHECK-IOS-TVOS: warning: using SDK for 'iPhoneOS9.2' but deploying to 'AppleTV' +// CHECK-IOS-IOSSIM-NOT: warning: using SDK for '{{.*}}' but deploying to '{{.*}}' Index: lib/Driver/ToolChains.h =================================================================== --- lib/Driver/ToolChains.h +++ lib/Driver/ToolChains.h @@ -496,6 +496,7 @@ return TargetVersion < VersionTuple(V0, V1, V2); } + StringRef getPlatformFamily() const; StringRef getOSLibraryNameSuffix() const; public: Index: lib/Driver/ToolChains.cpp =================================================================== --- lib/Driver/ToolChains.cpp +++ lib/Driver/ToolChains.cpp @@ -329,6 +329,23 @@ } } +StringRef Darwin::getPlatformFamily() const { + switch(TargetPlatform) { + case DarwinPlatformKind::MacOS: + return "MacOSX"; + case DarwinPlatformKind::IPhoneOS: + case DarwinPlatformKind::IPhoneOSSimulator: + return "iPhone"; + case DarwinPlatformKind::TvOS: + case DarwinPlatformKind::TvOSSimulator: + return "AppleTV"; + case DarwinPlatformKind::WatchOS: + case DarwinPlatformKind::WatchOSSimulator: + return "Watch"; + } + llvm_unreachable("Unsupported platform"); +} + StringRef Darwin::getOSLibraryNameSuffix() const { switch(TargetPlatform) { case DarwinPlatformKind::MacOS: @@ -721,6 +738,21 @@ Platform = WatchOSSimulator; setTarget(Platform, Major, Minor, Micro); + + if(Args.hasArg(options::OPT_Wincompatible_sdk)) { + if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { + StringRef isysroot = A->getValue(); + // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk + size_t BeginSDK = isysroot.rfind("SDKs/"); + size_t EndSDK = isysroot.rfind(".sdk"); + if (BeginSDK != StringRef::npos && EndSDK != StringRef::npos) { + StringRef SDK = isysroot.slice(BeginSDK + 5, EndSDK); + if(!SDK.startswith(getPlatformFamily())) + getDriver().Diag(diag::warn_incompatible_sdk) << SDK + << getPlatformFamily(); + } + } + } } void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1087,6 +1087,8 @@ def Wlarger_than_EQ : Joined<["-"], "Wlarger-than=">, Group<clang_ignored_f_Group>; def Wlarger_than_ : Joined<["-"], "Wlarger-than-">, Alias<Wlarger_than_EQ>; def Wframe_larger_than_EQ : Joined<["-"], "Wframe-larger-than=">, Group<f_Group>, Flags<[DriverOption]>; +def Wincompatible_sdk : Flag<["-"], "Wincompatible-sdk">, Group<f_Group>, + Flags<[DriverOption]>; def : Flag<["-"], "fterminated-vtables">, Alias<fapple_kext>; def fthreadsafe_statics : Flag<["-"], "fthreadsafe-statics">, Group<f_Group>; Index: include/clang/Basic/DiagnosticDriverKinds.td =================================================================== --- include/clang/Basic/DiagnosticDriverKinds.td +++ include/clang/Basic/DiagnosticDriverKinds.td @@ -195,6 +195,7 @@ "precompiled header '%0' was ignored because '%1' is not first '-include'">; def warn_missing_sysroot : Warning<"no such sysroot directory: '%0'">, InGroup<DiagGroup<"missing-sysroot">>; +def warn_incompatible_sdk : Warning<"using SDK for '%0' but deploying to '%1'">; def warn_debug_compression_unavailable : Warning<"cannot compress debug sections (zlib not installed)">, InGroup<DiagGroup<"debug-compression-unavailable">>; def warn_drv_enabling_rtti_with_exceptions : Warning<
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits