[cfe-commits] r95820 - in /cfe/trunk: include/clang/AST/Attr.h lib/AST/AttrImpl.cpp lib/Sema/TargetAttributesSema.cpp test/Sema/x86-attr-force-align-arg-pointer.c

Daniel Dunbar daniel at zuster.org
Thu Feb 11 08:25:01 PST 2010


On Wed, Feb 10, 2010 at 3:06 PM, Charles Davis <cdavis at mines.edu> wrote:
> Author: cdavis
> Date: Wed Feb 10 17:06:52 2010
> New Revision: 95820
>
> URL: http://llvm.org/viewvc/llvm-project?rev=95820&view=rev
> Log:
> Add support for the force_align_arg_pointer attribute. This is an x86-specific
> attribute, so it uses Anton's new target-specific attribute support. It's
> supposed to ensure that the stack is 16-byte aligned, but since necessary
> support is lacking from LLVM, this is a no-op for now.
>
> Added:
>    cfe/trunk/test/Sema/x86-attr-force-align-arg-pointer.c
> Modified:
>    cfe/trunk/include/clang/AST/Attr.h
>    cfe/trunk/lib/AST/AttrImpl.cpp
>    cfe/trunk/lib/Sema/TargetAttributesSema.cpp
>
> Modified: cfe/trunk/include/clang/AST/Attr.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=95820&r1=95819&r2=95820&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Attr.h (original)
> +++ cfe/trunk/include/clang/AST/Attr.h Wed Feb 10 17:06:52 2010
> @@ -96,7 +96,8 @@
>     FIRST_TARGET_ATTRIBUTE,
>     DLLExport,
>     DLLImport,
> -    MSP430Interrupt
> +    MSP430Interrupt,
> +    X86ForceAlignArgPointer
>   };
>
>  private:
> @@ -570,6 +571,8 @@
>   static bool classof(const MSP430InterruptAttr *A) { return true; }
>  };
>
> +DEF_SIMPLE_ATTR(X86ForceAlignArgPointer);
> +
>  #undef DEF_SIMPLE_ATTR
>
>  }  // end namespace clang
>
> Modified: cfe/trunk/lib/AST/AttrImpl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/AttrImpl.cpp?rev=95820&r1=95819&r2=95820&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/AttrImpl.cpp (original)
> +++ cfe/trunk/lib/AST/AttrImpl.cpp Wed Feb 10 17:06:52 2010
> @@ -55,6 +55,7 @@
>  DEF_SIMPLE_ATTR_CLONE(Override)
>  DEF_SIMPLE_ATTR_CLONE(DLLImport)
>  DEF_SIMPLE_ATTR_CLONE(DLLExport)
> +DEF_SIMPLE_ATTR_CLONE(X86ForceAlignArgPointer)
>
>  Attr* PragmaPackAttr::clone(ASTContext &C) const {
>   return ::new (C) PragmaPackAttr(Alignment);
>
> Modified: cfe/trunk/lib/Sema/TargetAttributesSema.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TargetAttributesSema.cpp?rev=95820&r1=95819&r2=95820&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/TargetAttributesSema.cpp (original)
> +++ cfe/trunk/lib/Sema/TargetAttributesSema.cpp Wed Feb 10 17:06:52 2010
> @@ -70,6 +70,46 @@
>   };
>  }
>
> +static void HandleX86ForceAlignArgPointerAttr(Decl *D,
> +                                              const AttributeList& Attr,
> +                                              Sema &S) {
> +  // Check the attribute arguments.
> +  if (Attr.getNumArgs() != 0) {
> +    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
> +    return;
> +  }
> +
> +  // If we try to apply it to a function pointer, don't warn, but don't
> +  // do anything, either. It doesn't matter anyway, because there's nothing
> +  // special about calling a force_align_arg_pointer function.

It might be a good idea to warn anyway. If a user is trying to do
something which does nothing, they are probably confused and it may be
worth pointing out.

 - Daniel

> +  ValueDecl* VD = dyn_cast<ValueDecl>(D);
> +  if(VD->getType()->isFunctionPointerType())
> +    return;
> +  // Attribute can only be applied to function types.
> +  if(!isa<FunctionDecl>(D)) {
> +    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
> +      << Attr.getName() << /* function */0;
> +    return;
> +  }
> +
> +  D->addAttr(::new (S.Context) X86ForceAlignArgPointerAttr());
> +}
> +
> +namespace {
> +  class X86AttributesSema : public TargetAttributesSema {
> +  public:
> +    X86AttributesSema() { }
> +    bool ProcessDeclAttribute(Scope *scope, Decl *D,
> +                              const AttributeList &Attr, Sema &S) const {
> +      if (Attr.getName()->getName() == "force_align_arg_pointer") {
> +        HandleX86ForceAlignArgPointerAttr(D, Attr, S);
> +        return true;
> +      }
> +      return false;
> +    }
> +  };
> +}
> +
>  const TargetAttributesSema &Sema::getTargetAttributesSema() const {
>   if (TheTargetAttributesSema)
>     return *TheTargetAttributesSema;
> @@ -81,6 +121,8 @@
>
>   case llvm::Triple::msp430:
>     return *(TheTargetAttributesSema = new MSP430AttributesSema);
> +  case llvm::Triple::x86:
> +    return *(TheTargetAttributesSema = new X86AttributesSema);
>   }
>  }
>
>
> Added: cfe/trunk/test/Sema/x86-attr-force-align-arg-pointer.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/x86-attr-force-align-arg-pointer.c?rev=95820&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/Sema/x86-attr-force-align-arg-pointer.c (added)
> +++ cfe/trunk/test/Sema/x86-attr-force-align-arg-pointer.c Wed Feb 10 17:06:52 2010
> @@ -0,0 +1,18 @@
> +// RUN: %clang_cc1 -triple i386-apple-darwin10 -fsyntax-only -verify %s
> +
> +int a __attribute__((force_align_arg_pointer)); // expected-warning{{attribute only applies to function types}}
> +
> +// It doesn't matter where the attribute is located.
> +void b(void) __attribute__((force_align_arg_pointer));
> +void __attribute__((force_align_arg_pointer)) c(void);
> +
> +// Functions only have to be declared force_align_arg_pointer once.
> +void b(void) {}
> +
> +// It doesn't matter which declaration has the attribute.
> +void d(void);
> +void __attribute__((force_align_arg_pointer)) d(void) {}
> +
> +// Attribute is ignored on function pointer types.
> +void (__attribute__((force_align_arg_pointer)) *p)();
> +
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list