Author: Ian Anderson
Date: 2026-02-18T09:04:24-08:00
New Revision: 879630aa0850a58452aa241f19c3f96e569545b6

URL: 
https://github.com/llvm/llvm-project/commit/879630aa0850a58452aa241f19c3f96e569545b6
DIFF: 
https://github.com/llvm/llvm-project/commit/879630aa0850a58452aa241f19c3f96e569545b6.diff

LOG: [clang][driver] Don't emit an error on an unrecognized SDK name (#181897)

-isysroot can be an unrecognized value in unusual circumstances. Don't
emit an error when checking the triple against such an isysroot, let the
user try to do what they're trying to do.

Added: 
    clang/test/Driver/Inputs/XRSimulator1.0.sdk/usr/include/libxml/.keep

Modified: 
    clang/lib/Driver/ToolChains/Darwin.cpp
    clang/test/Driver/incompatible_sysroot.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 1c95a79a52a9c..74fcb10c0be22 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1145,11 +1145,11 @@ void Darwin::VerifyTripleForSDK(const 
llvm::opt::ArgList &Args,
       getDriver().Diag(diag::warn_incompatible_sysroot)
           << SDKInfo->getDisplayName() << Triple.getTriple();
   } else if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
+    // If there is no SDK info, assume this is building against an SDK that
+    // predates SDKSettings.json. Try to match the triple to the SDK path.
     const char *isysroot = A->getValue();
-    StringRef SDK = getSDKName(isysroot);
-    if (!SDK.empty()) {
-      size_t StartVer = SDK.find_first_of("0123456789");
-      StringRef SDKName = SDK.slice(0, StartVer);
+    StringRef SDKName = getSDKName(isysroot);
+    if (!SDKName.empty()) {
       bool supported = true;
       if (Triple.isWatchOS())
         supported = SDKName.starts_with("Watch");
@@ -1161,9 +1161,8 @@ void Darwin::VerifyTripleForSDK(const llvm::opt::ArgList 
&Args,
         supported = SDKName.starts_with("iPhone");
       else if (Triple.isMacOSX())
         supported = SDKName.starts_with("MacOSX");
-      else
-        llvm::reportFatalUsageError(Twine("SDK at '") + isysroot +
-                                    "' missing SDKSettings.json.");
+      // If it's not an older SDK, then it might be a damaged SDK or a
+      // non-standard -isysroot path. Don't try to diagnose that here.
 
       if (!supported)
         getDriver().Diag(diag::warn_incompatible_sysroot)
@@ -2484,6 +2483,8 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) 
const {
   // Read the SDKSettings.json file for more information, like the SDK version
   // that we can pass down to the compiler.
   SDKInfo = parseSDKSettings(getVFS(), Args, getDriver());
+  // FIXME: If SDKInfo is std::nullopt, diagnose a bad isysroot value (e.g.
+  // doesn't end in .sdk).
 
   // The OS and the version can be specified using the -target argument.
   std::optional<DarwinPlatform> PlatformAndVersion =

diff  --git 
a/clang/test/Driver/Inputs/XRSimulator1.0.sdk/usr/include/libxml/.keep 
b/clang/test/Driver/Inputs/XRSimulator1.0.sdk/usr/include/libxml/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d

diff  --git a/clang/test/Driver/incompatible_sysroot.c 
b/clang/test/Driver/incompatible_sysroot.c
index a5f7d03da7254..6bc8cd07d1f12 100644
--- a/clang/test/Driver/incompatible_sysroot.c
+++ b/clang/test/Driver/incompatible_sysroot.c
@@ -12,13 +12,14 @@
 // RUN: %clang -target arm64-apple-visionos1.0-simulator 
-Wincompatible-sysroot -isysroot %S/Inputs/XRSimulator1.0.sdk -S -o - %s 2>&1 | 
FileCheck -check-prefix CHECK-VISIONOSSIM %s
 // RUN: %clang -target arm64-apple-xros1.0 -Wincompatible-sysroot -isysroot 
%S/Inputs/XRSimulator1.0.sdk -S -o - %s 2>&1 | FileCheck -check-prefix 
CHECK-VISIONOSSIM-VISIONOS %s
 // RUN: %clang -target arm64-apple-ios17.1 -Wincompatible-sysroot -isysroot 
%S/Inputs/XRSimulator1.0.sdk -S -o - %s 2>&1 | FileCheck -check-prefix 
CHECK-VISIONOSSIM-IOS %s
+// RUN: %clang -target arm64-apple-visionos1.0-simulator 
-Wincompatible-sysroot -isysroot 
%S/Inputs/XRSimulator1.0.sdk/usr/include/libxml -S -o - %s 2>&1 | FileCheck 
-check-prefix CHECK-VISIONOSSIM %s
 
 int main() { return 0; }
-// CHECK-OSX-IOS: warning: using sysroot for 'MacOSX' but targeting 
'x86_64-apple-ios9.0.0-simulator'
-// CHECK-IOS-WATCHOS: warning: using sysroot for 'iPhoneOS' but targeting 
'arm64-apple-watchos2.0.0'
-// CHECK-IOS-TVOS: warning: using sysroot for 'iPhoneOS' but targeting 
'arm64-apple-tvos9.0.0'
-// CHECK-OSX-DRIVERKIT: warning: using sysroot for 'MacOSX' but targeting 
'x86_64-apple-driverkit19.0.0'
-// CHECK-IOS-DRIVERKIT: warning: using sysroot for 'iPhoneOS' but targeting 
'x86_64-apple-driverkit19.0.0'
+// CHECK-OSX-IOS: warning: using sysroot for 'MacOSX10.9' but targeting 
'x86_64-apple-ios9.0.0-simulator'
+// CHECK-IOS-WATCHOS: warning: using sysroot for 'iPhoneOS9.2' but targeting 
'arm64-apple-watchos2.0.0'
+// CHECK-IOS-TVOS: warning: using sysroot for 'iPhoneOS9.2' but targeting 
'arm64-apple-tvos9.0.0'
+// CHECK-OSX-DRIVERKIT: warning: using sysroot for 'MacOSX10.9' but targeting 
'x86_64-apple-driverkit19.0.0'
+// CHECK-IOS-DRIVERKIT: warning: using sysroot for 'iPhoneOS9.2' but targeting 
'x86_64-apple-driverkit19.0.0'
 // CHECK-IOS-IOSSIM-NOT: warning: using sysroot for '{{.*}}' but targeting 
'{{.*}}'
 // CHECK-OSX-IOS-DISABLED-NOT: warning: using sysroot for '{{.*}}' but 
targeting '{{.*}}'
 


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to