[llvm-branch-commits] [cfe-branch] r333511 - Merging r330331:

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue May 29 23:02:32 PDT 2018


Author: tstellar
Date: Tue May 29 23:02:32 2018
New Revision: 333511

URL: http://llvm.org/viewvc/llvm-project?rev=333511&view=rev
Log:
Merging r330331:

------------------------------------------------------------------------
r330331 | erichkeane | 2018-04-19 07:27:05 -0700 (Thu, 19 Apr 2018) | 14 lines

Fix __attribute__((force_align_arg_pointer)) misalignment bug

The force_align_arg_pointer attribute was using a hardcoded 16-byte
alignment value which in combination with -mstack-alignment=32 (or
larger) would produce a misaligned stack which could result in crashes
when accessing stack buffers using aligned AVX load/store instructions.

Fix the issue by using the "stackrealign" function attribute instead
of using a hardcoded 16-byte alignment.

Patch By: Gramner

Differential Revision: https://reviews.llvm.org/D45812

------------------------------------------------------------------------

Modified:
    cfe/branches/release_60/lib/CodeGen/TargetInfo.cpp
    cfe/branches/release_60/test/CodeGen/function-attributes.c

Modified: cfe/branches/release_60/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/lib/CodeGen/TargetInfo.cpp?rev=333511&r1=333510&r2=333511&view=diff
==============================================================================
--- cfe/branches/release_60/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/branches/release_60/lib/CodeGen/TargetInfo.cpp Tue May 29 23:02:32 2018
@@ -1931,13 +1931,8 @@ void X86_32TargetCodeGenInfo::setTargetA
     return;
   if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
     if (FD->hasAttr<X86ForceAlignArgPointerAttr>()) {
-      // Get the LLVM function.
       llvm::Function *Fn = cast<llvm::Function>(GV);
-
-      // Now add the 'alignstack' attribute with a value of 16.
-      llvm::AttrBuilder B;
-      B.addStackAlignmentAttr(16);
-      Fn->addAttributes(llvm::AttributeList::FunctionIndex, B);
+      Fn->addFnAttr("stackrealign");
     }
     if (FD->hasAttr<AnyX86InterruptAttr>()) {
       llvm::Function *Fn = cast<llvm::Function>(GV);
@@ -2292,13 +2287,8 @@ public:
       return;
     if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
       if (FD->hasAttr<X86ForceAlignArgPointerAttr>()) {
-        // Get the LLVM function.
-        auto *Fn = cast<llvm::Function>(GV);
-
-        // Now add the 'alignstack' attribute with a value of 16.
-        llvm::AttrBuilder B;
-        B.addStackAlignmentAttr(16);
-        Fn->addAttributes(llvm::AttributeList::FunctionIndex, B);
+        llvm::Function *Fn = cast<llvm::Function>(GV);
+        Fn->addFnAttr("stackrealign");
       }
       if (FD->hasAttr<AnyX86InterruptAttr>()) {
         llvm::Function *Fn = cast<llvm::Function>(GV);
@@ -2429,13 +2419,8 @@ void WinX86_64TargetCodeGenInfo::setTarg
     return;
   if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
     if (FD->hasAttr<X86ForceAlignArgPointerAttr>()) {
-      // Get the LLVM function.
-      auto *Fn = cast<llvm::Function>(GV);
-
-      // Now add the 'alignstack' attribute with a value of 16.
-      llvm::AttrBuilder B;
-      B.addStackAlignmentAttr(16);
-      Fn->addAttributes(llvm::AttributeList::FunctionIndex, B);
+      llvm::Function *Fn = cast<llvm::Function>(GV);
+      Fn->addFnAttr("stackrealign");
     }
     if (FD->hasAttr<AnyX86InterruptAttr>()) {
       llvm::Function *Fn = cast<llvm::Function>(GV);

Modified: cfe/branches/release_60/test/CodeGen/function-attributes.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/test/CodeGen/function-attributes.c?rev=333511&r1=333510&r2=333511&view=diff
==============================================================================
--- cfe/branches/release_60/test/CodeGen/function-attributes.c (original)
+++ cfe/branches/release_60/test/CodeGen/function-attributes.c Tue May 29 23:02:32 2018
@@ -71,7 +71,7 @@ void f15(void) {
 
 // PR5254
 // CHECK-LABEL: define void @f16
-// CHECK: [[ALIGN:#[0-9]+]]
+// CHECK: [[SR:#[0-9]+]]
 // CHECK: {
 void __attribute__((force_align_arg_pointer)) f16(void) {
 }
@@ -112,7 +112,7 @@ void f20(void) {
 // CHECK: attributes [[NUW]] = { nounwind optsize{{.*}} }
 // CHECK: attributes [[AI]] = { alwaysinline nounwind optsize{{.*}} }
 // CHECK: attributes [[NUW_OS_RN]] = { nounwind optsize readnone{{.*}} }
-// CHECK: attributes [[ALIGN]] = { nounwind optsize alignstack=16{{.*}} }
+// CHECK: attributes [[SR]] = { nounwind optsize{{.*}} "stackrealign"{{.*}} }
 // CHECK: attributes [[RT]] = { nounwind optsize returns_twice{{.*}} }
 // CHECK: attributes [[NR]] = { noreturn optsize }
 // CHECK: attributes [[NUW_RN]] = { nounwind optsize readnone }




More information about the llvm-branch-commits mailing list