[PATCH] D51026: [CodeGen] Implicitly set stackrealign on the main function, if custom stack alignment is used
Martin Storsjö via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 21 13:42:14 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL340334: [CodeGen] Implicitly set stackrealign on the main function, if custom stack… (authored by mstorsjo, committed by ).
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D51026?vs=161653&id=161809#toc
Repository:
rL LLVM
https://reviews.llvm.org/D51026
Files:
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/test/CodeGen/stackrealign-main.c
Index: cfe/trunk/test/CodeGen/stackrealign-main.c
===================================================================
--- cfe/trunk/test/CodeGen/stackrealign-main.c
+++ cfe/trunk/test/CodeGen/stackrealign-main.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o - -mstack-alignment=64 %s | FileCheck %s
+
+// CHECK-LABEL: define void @other()
+// CHECK: [[OTHER:#[0-9]+]]
+// CHECK: {
+void other(void) {}
+
+// CHECK-LABEL: define i32 @main(
+// CHECK: [[MAIN:#[0-9]+]]
+// CHECK: {
+int main(int argc, char **argv) {
+ other();
+ return 0;
+}
+
+// CHECK: attributes [[OTHER]] = { noinline nounwind optnone
+// CHECK-NOT: "stackrealign"
+// CHECK: }
+// CHECK: attributes [[MAIN]] = { noinline nounwind optnone {{.*}}"stackrealign"{{.*}} }
Index: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
@@ -979,6 +979,13 @@
if (FD->isMain())
Fn->addFnAttr(llvm::Attribute::NoRecurse);
+ // If a custom alignment is used, force realigning to this alignment on
+ // any main function which certainly will need it.
+ if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
+ if ((FD->isMain() || FD->isMSVCRTEntryPoint()) &&
+ CGM.getCodeGenOpts().StackAlignment)
+ Fn->addFnAttr("stackrealign");
+
llvm::BasicBlock *EntryBB = createBasicBlock("entry", CurFn);
// Create a marker to make it easy to insert allocas into the entryblock
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51026.161809.patch
Type: text/x-patch
Size: 1563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180821/2a1ed3c4/attachment-0001.bin>
More information about the cfe-commits
mailing list