Anton Korobeynikov wrote:
> Hello, Charles
> 
>> This is a very simple patch, but I want feedback on it before I put it in.
> You're emitting a target-specific attribute inside generic codegen code.
Whoops. Good catch.

How's this patch?

Chip

Index: test/CodeGen/function-attributes.c
===================================================================
--- test/CodeGen/function-attributes.c  (revision 96013)
+++ test/CodeGen/function-attributes.c  (working copy)
@@ -81,3 +81,11 @@
 // CHECK: {
 void f15(void) {
 }
+
+// PR5254
+// CHECK: define void @f16
+// CHECK: alignstack(16)
+// CHECK: {
+void __attribute__((force_align_arg_pointer)) f16(void) {
+}
+
Index: lib/CodeGen/TargetInfo.cpp
===================================================================
--- lib/CodeGen/TargetInfo.cpp  (revision 96013)
+++ lib/CodeGen/TargetInfo.cpp  (working copy)
@@ -325,6 +325,9 @@
 public:
   X86_32TargetCodeGenInfo(ASTContext &Context, bool d, bool p)
     :TargetCodeGenInfo(new X86_32ABIInfo(Context, d, p)) {}
+
+  void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+                           CodeGen::CodeGenModule &CGM) const;
 };
 
 }
@@ -551,6 +554,20 @@
   return AddrTyped;
 }
 
+void X86_32TargetCodeGenInfo::SetTargetAttributes(const Decl *D,
+                                                  llvm::GlobalValue *GV,
+                                            CodeGen::CodeGenModule &CGM) const 
{
+  if (const FunctionDecl *FD = dyn_cast<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.
+      Fn->addAttribute(~0U, 
llvm::Attribute::constructStackAlignmentFromInt(16));
+    }
+  }
+}
+
 namespace {
 /// X86_64ABIInfo - The X86_64 ABI information.
 class X86_64ABIInfo : public ABIInfo {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to