]> granicus.if.org Git - clang/commitdiff
[CodeGen][x86_64] Enable 'force_align_arg_pointer' attribute at x86_64
authorErich Keane <erich.keane@intel.com>
Wed, 30 Aug 2017 21:17:40 +0000 (21:17 +0000)
committerErich Keane <erich.keane@intel.com>
Wed, 30 Aug 2017 21:17:40 +0000 (21:17 +0000)
This attribute is useful in OS development when we jump from 32 to 64 bit
code and expect that 64bit function forces correct stack alignment.

Related discussion: http://lists.llvm.org/pipermail/cfe-dev/2017-June/054358.html

Patch By: anatol.pomozov (anatol.pomozov@gmail.com)

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312173 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Attr.td
lib/CodeGen/TargetInfo.cpp
test/CodeGen/function-attributes.c

index 22eaa1d494713eef4f3681b4bdd833cf5d517bf1..7cf307efc96ace9303410d5300c45e5f2a98fe13 100644 (file)
@@ -2042,7 +2042,7 @@ def AnyX86NoCallerSavedRegisters : InheritableAttr,
   let Documentation = [AnyX86NoCallerSavedRegistersDocs];
 }
 
-def X86ForceAlignArgPointer : InheritableAttr, TargetSpecificAttr<TargetX86> {
+def X86ForceAlignArgPointer : InheritableAttr, TargetSpecificAttr<TargetAnyX86> {
   let Spellings = [GNU<"force_align_arg_pointer">];
   // Technically, this appertains to a FunctionDecl, but the target-specific
   // code silently allows anything function-like (such as typedefs or function
index 77b9b4caab5d653c98ea44712ca7136aaf6bd187..10fa2ea322c907bd8cbc9d8d83416ccf9f964f09 100644 (file)
@@ -2297,6 +2297,15 @@ public:
     if (!IsForDefinition)
       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);
+      }
       if (FD->hasAttr<AnyX86InterruptAttr>()) {
         llvm::Function *Fn = cast<llvm::Function>(GV);
         Fn->setCallingConv(llvm::CallingConv::X86_INTR);
@@ -2425,6 +2434,15 @@ void WinX86_64TargetCodeGenInfo::setTargetAttributes(
   if (!IsForDefinition)
     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);
+    }
     if (FD->hasAttr<AnyX86InterruptAttr>()) {
       llvm::Function *Fn = cast<llvm::Function>(GV);
       Fn->setCallingConv(llvm::CallingConv::X86_INTR);
index 2139f6fe65460a45723bae901e657c89c22788d9..e14397440100a8db8c07b61a1f23fb3280d6b9b3 100644 (file)
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -disable-llvm-passes -Os -o - %s | FileCheck %s
 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -disable-llvm-passes -Os -std=c99 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-llvm-passes -Os -std=c99 -o - %s | FileCheck %s
 // CHECK: define signext i8 @f0(i32 %x) [[NUW:#[0-9]+]]
 // CHECK: define zeroext i8 @f1(i32 %x) [[NUW]]
 // CHECK: define void @f2(i8 signext %x) [[NUW]]