Skip to content

Global string alignment #142346

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion llvm/lib/IR/IRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ GlobalVariable *IRBuilderBase::CreateGlobalString(StringRef Str,
*M, StrConstant->getType(), true, GlobalValue::PrivateLinkage,
StrConstant, Name, nullptr, GlobalVariable::NotThreadLocal, AddressSpace);
GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
GV->setAlignment(Align(1));
GV->setAlignment(M->getDataLayout().getPrefTypeAlign(getInt8Ty()));
return GV;
}

Expand Down
15 changes: 15 additions & 0 deletions llvm/test/Transforms/InstCombine/SystemZ/printf-opt-alignment.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; RUN: opt < %s --passes=instcombine -S -mtriple=systemz-unknown | FileCheck %s
;
; Check that string replacements inserted by the instcombiner are properly aligned.
; The specific case checked replaces `printf("foo\n")` with `puts("foo")`

@msg1 = constant [17 x i8] c"Alignment Check\0A\00", align 2
; CHECK: c"Alignment Check\00", align 2

; Function Attrs: noinline nounwind
define dso_local void @foo() #0 {
%call = call signext i32 (ptr, ...) @printf(ptr noundef @msg1)
ret void
}

declare signext i32 @printf(ptr noundef, ...) #1