llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Ian Anderson (ian-twilightcoder)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/177748.diff


4 Files Affected:

- (modified) clang/include/clang/Basic/DarwinSDKInfo.h (+9-3) 
- (modified) clang/lib/Basic/DarwinSDKInfo.cpp (+5-3) 
- (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+11-1) 
- (added) clang/test/Driver/darwin-depfile-sdksettings-maccatalyst.m (+4) 


``````````diff
diff --git a/clang/include/clang/Basic/DarwinSDKInfo.h 
b/clang/include/clang/Basic/DarwinSDKInfo.h
index 54e4df5988526..4bfdacd92405c 100644
--- a/clang/include/clang/Basic/DarwinSDKInfo.h
+++ b/clang/include/clang/Basic/DarwinSDKInfo.h
@@ -181,17 +181,21 @@ class DarwinSDKInfo {
   using PlatformInfoStorageType = SmallVector<SDKPlatformInfo, 2>;
 
   DarwinSDKInfo(
-      VersionTuple Version, VersionTuple MaximumDeploymentTarget,
+      std::string FilePath, VersionTuple Version,
+      VersionTuple MaximumDeploymentTarget,
       PlatformInfoStorageType PlatformInfos,
       llvm::DenseMap<OSEnvPair::StorageType,
                      std::optional<RelatedTargetVersionMapping>>
           VersionMappings =
               llvm::DenseMap<OSEnvPair::StorageType,
                              std::optional<RelatedTargetVersionMapping>>())
-      : Version(Version), MaximumDeploymentTarget(MaximumDeploymentTarget),
+      : FilePath(FilePath), Version(Version),
+        MaximumDeploymentTarget(MaximumDeploymentTarget),
         PlatformInfos(std::move(PlatformInfos)),
         VersionMappings(std::move(VersionMappings)) {}
 
+  StringRef getFilePath() const { return FilePath; }
+    
   const llvm::VersionTuple &getVersion() const { return Version; }
 
   const SDKPlatformInfo &getCanonicalPlatformInfo() const {
@@ -224,9 +228,11 @@ class DarwinSDKInfo {
   }
 
   static std::optional<DarwinSDKInfo>
-  parseDarwinSDKSettingsJSON(const llvm::json::Object *Obj);
+  parseDarwinSDKSettingsJSON(std::string FilePath,
+                             const llvm::json::Object *Obj);
 
 private:
+  std::string FilePath;
   VersionTuple Version;
   VersionTuple MaximumDeploymentTarget;
   PlatformInfoStorageType PlatformInfos;
diff --git a/clang/lib/Basic/DarwinSDKInfo.cpp 
b/clang/lib/Basic/DarwinSDKInfo.cpp
index b55ffd1c39a86..4fa2febe0f650 100644
--- a/clang/lib/Basic/DarwinSDKInfo.cpp
+++ b/clang/lib/Basic/DarwinSDKInfo.cpp
@@ -176,7 +176,8 @@ static std::optional<VersionTuple> getVersionKey(const 
llvm::json::Object &Obj,
 }
 
 std::optional<DarwinSDKInfo>
-DarwinSDKInfo::parseDarwinSDKSettingsJSON(const llvm::json::Object *Obj) {
+DarwinSDKInfo::parseDarwinSDKSettingsJSON(std::string FilePath,
+                                          const llvm::json::Object *Obj) {
   auto Version = getVersionKey(*Obj, "Version");
   if (!Version)
     return std::nullopt;
@@ -226,7 +227,7 @@ DarwinSDKInfo::parseDarwinSDKSettingsJSON(const 
llvm::json::Object *Obj) {
     }
   }
 
-  return DarwinSDKInfo(std::move(*Version),
+  return DarwinSDKInfo(std::move(FilePath), std::move(*Version),
                        std::move(*MaximumDeploymentVersion),
                        std::move(PlatformInfos), std::move(VersionMappings));
 }
@@ -247,7 +248,8 @@ clang::parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, 
StringRef SDKRootPath) {
     return Result.takeError();
 
   if (const auto *Obj = Result->getAsObject()) {
-    if (auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON(Obj))
+    if (auto SDKInfo = DarwinSDKInfo::parseDarwinSDKSettingsJSON(
+            Filepath.str().str(), Obj))
       return std::move(SDKInfo);
   }
   return llvm::make_error<llvm::StringError>("invalid SDKSettings.json",
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index fb75739360328..5c975bcb57248 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1917,7 +1917,7 @@ struct DarwinPlatform {
     StringRef PlatformPrefix =
         (Platform == DarwinPlatformKind::DriverKit) ? "/System/DriverKit" : "";
     return DarwinSDKInfo(
-        getOSVersion(), /*MaximumDeploymentTarget=*/
+        "", getOSVersion(), /*MaximumDeploymentTarget=*/
         VersionTuple(getOSVersion().getMajor(), 0, 99),
         {DarwinSDKInfo::SDKPlatformInfo(llvm::Triple::Apple, OS,
                                         llvm::Triple::UnknownEnvironment,
@@ -3398,6 +3398,16 @@ void Darwin::addClangCC1ASTargetOptions(
           OS << "-darwin-target-variant-sdk-version=" << *SDKVersion;
           CC1ASArgs.push_back(Args.MakeArgString(Arg));
         }
+
+        // Make the SDKSettings.json an explicit dependency for the compiler
+        // invocation, in case the compiler needs to read it to remap
+        // macCatalyst versions.
+        if ((isTargetMacCatalyst() || TargetVariantTriple) &&
+            !SDKInfo->getFilePath().empty()) {
+          SmallString<64> ExtraDepOpt("-fdepfile-entry=");
+          ExtraDepOpt += SDKInfo->getFilePath();
+          CC1ASArgs.push_back(Args.MakeArgString(ExtraDepOpt));
+        }
       }
     }
   }
diff --git a/clang/test/Driver/darwin-depfile-sdksettings-maccatalyst.m 
b/clang/test/Driver/darwin-depfile-sdksettings-maccatalyst.m
new file mode 100644
index 0000000000000..176aeb58ed294
--- /dev/null
+++ b/clang/test/Driver/darwin-depfile-sdksettings-maccatalyst.m
@@ -0,0 +1,4 @@
+// RUN: %clang -target x86_64-apple-ios13.1-macabi -isysroot 
%S/Inputs/MacOSX10.15.sdk -c %s -### 2>&1 \
+// RUN:   | FileCheck %s
+
+// CHECK: -fdepfile-entry={{.*}}MacOSX10.15.sdk{{/|\\}}SDKSettings.json

``````````

</details>


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

Reply via email to