[llvm] Filter out unemitted metadata before assertion in AIXAsmPrinter. (PR #165620)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 29 13:16:16 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-powerpc

Author: Sean Fertile (mandlebug)

<details>
<summary>Changes</summary>

Global annotations metadata would trigger an assertion during code emission on AIX. Filter out globals that are in the "llvm.metadata" section before reaching the assert. Adds a test to verify the metadata is not emitted on either ELF or XCOFF targets.

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


2 Files Affected:

- (modified) llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp (+4) 
- (added) llvm/test/CodeGen/PowerPC/annotate-metadata.ll (+15) 


``````````diff
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index bcb3f507e98d6..dde6cbf74f79a 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -2750,6 +2750,10 @@ void PPCAIXAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
   if (isSpecialLLVMGlobalArrayToSkip(GV) || isSpecialLLVMGlobalArrayForStaticInit(GV))
     return;
 
+  // Ignore non-emitted data.
+  if (GV->getSection() == "llvm.metadata")
+    return;
+
   // If the Global Variable has the toc-data attribute, it needs to be emitted
   // when we emit the .toc section.
   if (GV->hasAttribute("toc-data")) {
diff --git a/llvm/test/CodeGen/PowerPC/annotate-metadata.ll b/llvm/test/CodeGen/PowerPC/annotate-metadata.ll
new file mode 100644
index 0000000000000..4149b56e0ea95
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/annotate-metadata.ll
@@ -0,0 +1,15 @@
+; RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple powerpc-ibm-aix-xcoff < \
+; RUN: %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple powerpc64le-unknown-linux < \
+; RUN: %s | FileCheck %s
+
+ at .str = private unnamed_addr constant [12 x i8] c"MY_METADATA\00", section "llvm.metadata"
+ at .str.1 = private unnamed_addr constant [10 x i8] c"my_file.c\00", section "llvm.metadata"
+ at global.annotations = appending global [3 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr @a, ptr @.str, ptr @.str.1, i32 100, ptr null }, { ptr, ptr, ptr, i32, ptr } { ptr @b, ptr @.str, ptr @.str.1, i32 200, ptr null }, { ptr, ptr, ptr, i32, ptr } { ptr @c, ptr @.str, ptr @.str.1, i32 300, ptr null }], section "llvm.metadata"
+
+ at a = global i32 1
+ at b = global i32 2
+ at c = global i32 3
+
+; CHECK-NOT: metadata
+; CHECK-NOT: annotations

``````````

</details>


https://github.com/llvm/llvm-project/pull/165620


More information about the llvm-commits mailing list