llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Prajwal Nadig (snprajwal)

<details>
<summary>Changes</summary>

Macros are processed by iterating over the preprocessor's stored `DenseMap`, 
which is pointer-keyed with `IdentifierInfo`. This map is not ordered, leading 
to the contents of the symbol graph changing across runs with identical inputs. 
Sort macros lexicographically by name to ensure consistent output.

rdar://184545768

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


2 Files Affected:

- (modified) clang/lib/ExtractAPI/ExtractAPIConsumer.cpp (+9-2) 
- (modified) clang/test/ExtractAPI/macros.c (+8) 


``````````diff
diff --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp 
b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index 85da480fb67a6..4b3d6993acce5 100644
--- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -287,8 +287,15 @@ class MacroCallback : public PPCallbacks {
       : Ctx(Ctx), SM(SM), API(API), PP(PP) {}
 
   void EndOfMainFile() override {
-    for (const auto &M : PP.macros()) {
-      auto *II = M.getFirst();
+    SmallVector<const IdentifierInfo *> Macros;
+    for (const auto &M : PP.macros())
+      Macros.push_back(M.getFirst());
+    llvm::sort(Macros,
+               [](const IdentifierInfo *LHS, const IdentifierInfo *RHS) {
+                 return LHS->getName() < RHS->getName();
+               });
+
+    for (const auto *II : Macros) {
       auto MD = PP.getMacroDefinition(II);
       auto *MI = MD.getMacroInfo();
 
diff --git a/clang/test/ExtractAPI/macros.c b/clang/test/ExtractAPI/macros.c
index 15eb5f6a7f66f..cb0b018fd5390 100644
--- a/clang/test/ExtractAPI/macros.c
+++ b/clang/test/ExtractAPI/macros.c
@@ -354,5 +354,13 @@
 // FUNGNU-NEXT:   "FUNGNU"
 // FUNGNU-NEXT: ]
 
+// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix ORDER
+// ORDER: "!testLabel": "c:@macro@FUN"
+// ORDER: "!testLabel": "c:@macro@FUNC99"
+// ORDER: "!testLabel": "c:@macro@FUNGNU"
+// ORDER: "!testLabel": "c:@macro@HELLO"
+// ORDER: "!testLabel": "c:@macro@MACRO_FUN"
+// ORDER: "!testLabel": "c:@macro@WORLD"
+
 // expected-no-diagnostics
 

``````````

</details>


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

Reply via email to