[llvm] [CHERI][RISCV] Do not attempt to pass in an alignment granule for globals with explicit sections. (PR #218189)
Owen Anderson via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 22 21:01:02 PDT 2026
https://github.com/resistor created https://github.com/llvm/llvm-project/pull/218189
This was already implied to be the case in the comments of emitGlobalVariable(GV, AlignmentGranule),
but it is the caller's responsibility to ensure that this is handled properly. As such the
emitGlobalVariable(GV) caller needs to enforce this requirement.
>From d17c0ac5e88a65b11a24469ad939cfbbb54452df Mon Sep 17 00:00:00 2001
From: Owen Anderson <resistor at mac.com>
Date: Sat, 22 Aug 2026 22:58:24 -0500
Subject: [PATCH] [CHERI][RISCV] Do not attempt to pass in an alignment granule
for globals with explicit sections.
This was already implied to be the case in the comments of emitGlobalVariable(GV, AlignmentGranule),
but it is the caller's responsibility to ensure that this is handled properly. As such the
emitGlobalVariable(GV) caller needs to enforce this requirement.
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 4 +++-
llvm/test/CodeGen/RISCV/cheri-global-bounds.ll | 13 ++++++++++---
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index cbd8f1932a285..99981f420b8e3 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -788,7 +788,9 @@ MCSymbol *AsmPrinter::getSymbolPreferLocal(const GlobalValue &GV) const {
/// EmitGlobalVariable - Emit the specified global variable to the .s file.
void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
- MaybeAlign AlignmentGranule = getRequiredGlobalAlignmentGranule(*GV);
+ MaybeAlign AlignmentGranule = std::nullopt;
+ if (!GV->hasSection())
+ AlignmentGranule = getRequiredGlobalAlignmentGranule(*GV);
emitGlobalVariable(GV, AlignmentGranule);
if (AlignmentGranule)
OutStreamer->emitValueToAlignment(*AlignmentGranule);
diff --git a/llvm/test/CodeGen/RISCV/cheri-global-bounds.ll b/llvm/test/CodeGen/RISCV/cheri-global-bounds.ll
index 0443338855e62..5681877341301 100644
--- a/llvm/test/CodeGen/RISCV/cheri-global-bounds.ll
+++ b/llvm/test/CodeGen/RISCV/cheri-global-bounds.ll
@@ -1,6 +1,6 @@
-; RUN: llc -mtriple riscv32 -mattr=+experimental-y -target-abi il32pc64 %s -o - | FileCheck -check-prefix=RVY32 %s
-; RUN: llc -mtriple riscv64 -mattr=+experimental-y -target-abi l64pc128 %s -o - | FileCheck -check-prefix=RVY64 %s
-; RUN: llc -mtriple riscv64 -mattr=+xcheriot -target-abi cheriot %s -o - | FileCheck -check-prefix=CHERIOT %s
+; RUN: llc -mtriple riscv32 -mattr=+experimental-y -target-abi il32pc64 %s -o - | FileCheck -check-prefix=RVY32,COMMON %s
+; RUN: llc -mtriple riscv64 -mattr=+experimental-y -target-abi l64pc128 %s -o - | FileCheck -check-prefix=RVY64,COMMON %s
+; RUN: llc -mtriple riscv64 -mattr=+xcheriot -target-abi cheriot %s -o - | FileCheck -check-prefix=CHERIOT,COMMON %s
@global1 = global [6995 x i8] zeroinitializer, align 1
@@ -24,3 +24,10 @@
; CHERIOT-NEXT: .zero 6995
; CHERIOT-NEXT: .size global1, 7008
; CHERIOT: .p2align 4, 0x0
+
+ at global_in_section = global [6995 x i8] zeroinitializer, section "foo", align 1
+
+; COMMON-LABEL: .globl global_in_section
+; COMMON-NEXT: global_in_section:
+; COMMON-NEXT: .zero 6995
+; COMMON-NEXT: .size global_in_section, 6995
More information about the llvm-commits
mailing list