[clang] [clang][ExtractAPI] Emit environment component of target triple in SGF (PR #103273)

Daniel Grumberg via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 13 08:12:39 PDT 2024


https://github.com/daniel-grumberg created https://github.com/llvm/llvm-project/pull/103273

rdar://133533830

>From 6c9fdf64b14c14db00fbf4ba8ec4103b14ddb72d Mon Sep 17 00:00:00 2001
From: Daniel Grumberg <dgrumberg at apple.com>
Date: Tue, 13 Aug 2024 16:09:58 +0100
Subject: [PATCH] [clang][ExtractAPI] Emit environment component of target
 triple in SGF

rdar://133533830
---
 .../Serialization/SymbolGraphSerializer.cpp   |  4 ++++
 .../test/ExtractAPI/platform-serialization.c  | 20 +++++++++++++++++++
 2 files changed, 24 insertions(+)
 create mode 100644 clang/test/ExtractAPI/platform-serialization.c

diff --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 6e56ee5b573f66..647c8659639f35 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -104,6 +104,10 @@ Object serializePlatform(const Triple &T) {
   Object Platform;
   Platform["architecture"] = T.getArchName();
   Platform["vendor"] = T.getVendorName();
+
+  if (!T.getEnvironmentName().empty())
+    Platform["environment"] = T.getEnvironmentName();
+
   Platform["operatingSystem"] = serializeOperatingSystem(T);
   return Platform;
 }
diff --git a/clang/test/ExtractAPI/platform-serialization.c b/clang/test/ExtractAPI/platform-serialization.c
new file mode 100644
index 00000000000000..6d6a13f085cd9d
--- /dev/null
+++ b/clang/test/ExtractAPI/platform-serialization.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -extract-api --pretty-sgf -triple arm64-apple-ios17.1-macabi \
+// RUN:   -x c-header %s -verify -o - | FileCheck %s
+
+int a;
+
+// CHECK:      "platform": {
+// CHECK-NEXT:   "architecture": "arm64",
+// CHECK-NEXT:   "environment": "macabi",
+// CHECK-NEXT:   "operatingSystem": {
+// CHECK-NEXT:     "minimumVersion": {
+// CHECK-NEXT:       "major": 14,
+// CHECK-NEXT:       "minor": 0,
+// CHECK-NEXT:       "patch": 0
+// CHECK-NEXT:     },
+// CHECK-NEXT:     "name": "ios"
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "vendor": "apple"
+// CHECK-NEXT: }
+
+// expected-no-diagnostics



More information about the cfe-commits mailing list