Skip to content

[CodeGen] Don't allow function alignment less than the target's minimum #90415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
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
}


Loading