Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3147,9 +3147,17 @@ void AsmPrinter::emitAlignment(Align Alignment, const GlobalObject *GV,

if (getCurrentSection()->getKind().isText()) {
const MCSubtargetInfo *STI = nullptr;
if (this->MF)
STI = &getSubtargetInfo();
else
if (this->MF) {
// Don't allow the possibly smaller alignment of the GV
// (e.g. 2 for a C++ method) to reduce a function's alignment
// below the target's minimum function alignment. (#90358)
const TargetSubtargetInfo *TSI = &MF->getSubtarget();
const Align MinAlign =
TSI->getTargetLowering()->getMinFunctionAlignment();
if (Alignment < MinAlign)
Alignment = MinAlign;
STI = TSI;
} else
STI = TM.getMCSubtargetInfo();
OutStreamer->emitCodeAlignment(Alignment, STI, MaxBytesToEmit);
} else
Expand Down
19 changes: 19 additions & 0 deletions llvm/test/CodeGen/AArch64/func-alignment.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; RUN: llc -mtriple=aarch64 -O0 -fast-isel < %s | FileCheck %s

; Verify that Clang's C++ ABI alignment for functions of 2 does not
; result in underaligned functions when they are in special sections.
; (#90415)

define void @noSection() align 2 {
; CHECK: .p2align 2
entry:
ret void
}

define void @withSection() section "__TEXT,__foo,regular,pure_instructions" align 2 {
; CHECK: .p2align 2
entry:
ret void
}