[llvm-commits] [llvm] r148553 - in /llvm/trunk: docs/LangRef.html include/llvm-c/Core.h include/llvm/Attributes.h lib/AsmParser/LLLexer.cpp lib/AsmParser/LLParser.cpp lib/AsmParser/LLParser.h lib/AsmParser/LLToken.h lib/Bitcode/Reader/BitcodeRead

David Blaikie dblaikie at gmail.com
Fri Jan 20 10:31:08 PST 2012


On Fri, Jan 20, 2012 at 9:56 AM, Kostya Serebryany <kcc at google.com> wrote:
> Author: kcc
> Date: Fri Jan 20 11:56:17 2012
> New Revision: 148553
>
> URL: http://llvm.org/viewvc/llvm-project?rev=148553&view=rev
> Log:
> Extend Attributes to 64 bits
>
> Problem: LLVM needs more function attributes than currently available (32 bits).
> One such proposed attribute is "address_safety", which shows that a function is being checked for address safety (by AddressSanitizer, SAFECode, etc).
>
> Solution:
> - extend the Attributes from 32 bits to 64-bits
> - wrap the object into a class so that unsigned is never erroneously used instead
> - change "unsigned" to "Attributes" throughout the code, including one place in clang.
> - the class has no "operator uint64 ()", but it has "uint64_t Raw() " to support packing/unpacking.
> - the class has "safe operator bool()" to support the common idiom:  if (Attributes attr = getAttrs()) useAttrs(attr);

Oh, I didn't notice you'd done anything like this in the CR version.
Just for the record - your implementation isn't terribly safe. It's
safer than 'bool', that's for sure, but still has some limitations.

In case it's of interest, I had included in a previous CR (that was
never signed off) a full implementation of the Safe Bool style
documented here ( http://www.artima.com/cppsource/safebool.html ) to
be used by StringRef (or Twine) or something... if that'd be of
interest I can pry it out as a separate patch.

(to find my original patch you can probably look for something from
this email address with twine and stringref in the title and a file
attachment - it was sent out probably 6-9 months ago. I've been
meaning to update it recently to get it back up to mainline
compatibility)

- David

> - The CTOR from uint64_t is marked explicit, so I had to add a few explicit CTOR calls
> - Add the new attribute "address_safety". Doing it in the same commit to check that attributes beyond first 32 bits actually work.
> - Some of the functions from the Attribute namespace are worth moving inside the class, but I'd prefer to have it as a separate commit.
>
> Tested:
> "make check" on Linux (32-bit and 64-bit) and Mac (10.6)
> built/run spec CPU 2006 on Linux with clang -O2.
>
>
> This change will break clang build in lib/CodeGen/CGCall.cpp.
> The following patch will fix it.
>
> Modified:
>    llvm/trunk/docs/LangRef.html
>    llvm/trunk/include/llvm-c/Core.h
>    llvm/trunk/include/llvm/Attributes.h
>    llvm/trunk/lib/AsmParser/LLLexer.cpp
>    llvm/trunk/lib/AsmParser/LLParser.cpp
>    llvm/trunk/lib/AsmParser/LLParser.h
>    llvm/trunk/lib/AsmParser/LLToken.h
>    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
>    llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
>    llvm/trunk/lib/CodeGen/Analysis.cpp
>    llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
>    llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
>    llvm/trunk/lib/VMCore/Attributes.cpp
>    llvm/trunk/lib/VMCore/Core.cpp
>    llvm/trunk/lib/VMCore/Verifier.cpp
>    llvm/trunk/utils/llvm.grm
>
> Modified: llvm/trunk/docs/LangRef.html
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LangRef.html?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/docs/LangRef.html (original)
> +++ llvm/trunk/docs/LangRef.html Fri Jan 20 11:56:17 2012
> @@ -1143,6 +1143,10 @@
>  </pre>
>
>  <dl>
> +  <dt><tt><b>address_safety</b></tt></dt>
> +  <dd>This attribute indicates that the address safety analysis
> +  is enabled for this function.  </dd>
> +
>   <dt><tt><b>alignstack(<<em>n</em>>)</b></tt></dt>
>   <dd>This attribute indicates that, when emitting the prologue and epilogue,
>       the backend should forcibly align the stack pointer. Specify the
>
> Modified: llvm/trunk/include/llvm-c/Core.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm-c/Core.h (original)
> +++ llvm/trunk/include/llvm-c/Core.h Fri Jan 20 11:56:17 2012
> @@ -118,7 +118,8 @@
>     LLVMStackAlignment = 7<<26,
>     LLVMReturnsTwice = 1 << 29,
>     LLVMUWTable = 1 << 30,
> -    LLVMNonLazyBind = 1 << 31
> +    LLVMNonLazyBind = 1U << 31,
> +    LLVMAddressSafety = 1ULL << 32,
>  } LLVMAttribute;
>
>  typedef enum {
>
> Modified: llvm/trunk/include/llvm/Attributes.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Attributes.h?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Attributes.h (original)
> +++ llvm/trunk/include/llvm/Attributes.h Fri Jan 20 11:56:17 2012
> @@ -23,7 +23,47 @@
>  class Type;
>
>  /// Attributes - A bitset of attributes.
> -typedef unsigned Attributes;
> +class Attributes {
> + public:
> +  Attributes() : Bits(0) { }
> +  explicit Attributes(uint64_t Val) : Bits(Val) { }
> +  Attributes(const Attributes &Attrs) : Bits(Attrs.Bits) { }
> +  // This is a "safe bool() operator".
> +  operator const void *() const { return Bits ? this : 0; }
> +  bool isEmptyOrSingleton() const { return (Bits & (Bits - 1)) == 0; }
> +  Attributes &operator = (const Attributes &Attrs) {
> +    Bits = Attrs.Bits;
> +    return *this;
> +  }
> +  bool operator == (const Attributes &Attrs) const {
> +    return Bits == Attrs.Bits;
> +  }
> +  bool operator != (const Attributes &Attrs) const {
> +    return Bits != Attrs.Bits;
> +  }
> +  Attributes operator | (const Attributes &Attrs) const {
> +    return Attributes(Bits | Attrs.Bits);
> +  }
> +  Attributes operator & (const Attributes &Attrs) const {
> +    return Attributes(Bits & Attrs.Bits);
> +  }
> +  Attributes operator ^ (const Attributes &Attrs) const {
> +    return Attributes(Bits ^ Attrs.Bits);
> +  }
> +  Attributes &operator |= (const Attributes &Attrs) {
> +    Bits |= Attrs.Bits;
> +    return *this;
> +  }
> +  Attributes &operator &= (const Attributes &Attrs) {
> +    Bits &= Attrs.Bits;
> +    return *this;
> +  }
> +  Attributes operator ~ () const { return Attributes(~Bits); }
> +  uint64_t Raw() const { return Bits; }
> + private:
> +  // Currently, we need less than 64 bits.
> +  uint64_t Bits;
> +};
>
>  namespace Attribute {
>
> @@ -33,44 +73,45 @@
>  /// results or the function itself.
>  /// @brief Function attributes.
>
> -const Attributes None      = 0;     ///< No attributes have been set
> -const Attributes ZExt      = 1<<0;  ///< Zero extended before/after call
> -const Attributes SExt      = 1<<1;  ///< Sign extended before/after call
> -const Attributes NoReturn  = 1<<2;  ///< Mark the function as not returning
> -const Attributes InReg     = 1<<3;  ///< Force argument to be passed in register
> -const Attributes StructRet = 1<<4;  ///< Hidden pointer to structure to return
> -const Attributes NoUnwind  = 1<<5;  ///< Function doesn't unwind stack
> -const Attributes NoAlias   = 1<<6;  ///< Considered to not alias after call
> -const Attributes ByVal     = 1<<7;  ///< Pass structure by value
> -const Attributes Nest      = 1<<8;  ///< Nested function static chain
> -const Attributes ReadNone  = 1<<9;  ///< Function does not access memory
> -const Attributes ReadOnly  = 1<<10; ///< Function only reads from memory
> -const Attributes NoInline        = 1<<11; ///< inline=never
> -const Attributes AlwaysInline    = 1<<12; ///< inline=always
> -const Attributes OptimizeForSize = 1<<13; ///< opt_size
> -const Attributes StackProtect    = 1<<14; ///< Stack protection.
> -const Attributes StackProtectReq = 1<<15; ///< Stack protection required.
> -const Attributes Alignment = 31<<16; ///< Alignment of parameter (5 bits)
> +const Attributes None      (0);     ///< No attributes have been set
> +const Attributes ZExt      (1<<0);  ///< Zero extended before/after call
> +const Attributes SExt      (1<<1);  ///< Sign extended before/after call
> +const Attributes NoReturn  (1<<2);  ///< Mark the function as not returning
> +const Attributes InReg     (1<<3);  ///< Force argument to be passed in register
> +const Attributes StructRet (1<<4);  ///< Hidden pointer to structure to return
> +const Attributes NoUnwind  (1<<5);  ///< Function doesn't unwind stack
> +const Attributes NoAlias   (1<<6);  ///< Considered to not alias after call
> +const Attributes ByVal     (1<<7);  ///< Pass structure by value
> +const Attributes Nest      (1<<8);  ///< Nested function static chain
> +const Attributes ReadNone  (1<<9);  ///< Function does not access memory
> +const Attributes ReadOnly  (1<<10); ///< Function only reads from memory
> +const Attributes NoInline        (1<<11); ///< inline=never
> +const Attributes AlwaysInline    (1<<12); ///< inline=always
> +const Attributes OptimizeForSize (1<<13); ///< opt_size
> +const Attributes StackProtect    (1<<14); ///< Stack protection.
> +const Attributes StackProtectReq (1<<15); ///< Stack protection required.
> +const Attributes Alignment (31<<16); ///< Alignment of parameter (5 bits)
>                                      // stored as log2 of alignment with +1 bias
>                                      // 0 means unaligned different from align 1
> -const Attributes NoCapture = 1<<21; ///< Function creates no aliases of pointer
> -const Attributes NoRedZone = 1<<22; /// disable redzone
> -const Attributes NoImplicitFloat = 1<<23; /// disable implicit floating point
> +const Attributes NoCapture (1<<21); ///< Function creates no aliases of pointer
> +const Attributes NoRedZone (1<<22); /// disable redzone
> +const Attributes NoImplicitFloat (1<<23); /// disable implicit floating point
>                                           /// instructions.
> -const Attributes Naked           = 1<<24; ///< Naked function
> -const Attributes InlineHint      = 1<<25; ///< source said inlining was
> +const Attributes Naked           (1<<24); ///< Naked function
> +const Attributes InlineHint      (1<<25); ///< source said inlining was
>                                           ///desirable
> -const Attributes StackAlignment  = 7<<26; ///< Alignment of stack for
> +const Attributes StackAlignment  (7<<26); ///< Alignment of stack for
>                                           ///function (3 bits) stored as log2
>                                           ///of alignment with +1 bias
>                                           ///0 means unaligned (different from
>                                           ///alignstack(1))
> -const Attributes ReturnsTwice    = 1<<29; ///< Function can return twice
> -const Attributes UWTable     = 1<<30;     ///< Function must be in a unwind
> +const Attributes ReturnsTwice    (1<<29); ///< Function can return twice
> +const Attributes UWTable     (1<<30);     ///< Function must be in a unwind
>                                           ///table
> -const Attributes NonLazyBind = 1U<<31;    ///< Function is called early and/or
> +const Attributes NonLazyBind (1U<<31);    ///< Function is called early and/or
>                                           ///  often, so lazy binding isn't
>                                           ///  worthwhile.
> +const Attributes AddressSafety(1ULL<<32); ///< Address safety checking is on.
>
>  /// Note that uwtable is about the ABI or the user mandating an entry in the
>  /// unwind table. The nounwind attribute is about an exception passing by the
> @@ -92,7 +133,7 @@
>  const Attributes FunctionOnly = NoReturn | NoUnwind | ReadNone | ReadOnly |
>   NoInline | AlwaysInline | OptimizeForSize | StackProtect | StackProtectReq |
>   NoRedZone | NoImplicitFloat | Naked | InlineHint | StackAlignment |
> -  UWTable | NonLazyBind | ReturnsTwice;
> +  UWTable | NonLazyBind | ReturnsTwice | AddressSafety;
>
>  /// @brief Parameter attributes that do not apply to vararg call arguments.
>  const Attributes VarArgsIncompatible = StructRet;
> @@ -113,20 +154,20 @@
>  inline Attributes constructAlignmentFromInt(unsigned i) {
>   // Default alignment, allow the target to define how to align it.
>   if (i == 0)
> -    return 0;
> +    return None;
>
>   assert(isPowerOf2_32(i) && "Alignment must be a power of two.");
>   assert(i <= 0x40000000 && "Alignment too large.");
> -  return (Log2_32(i)+1) << 16;
> +  return Attributes((Log2_32(i)+1) << 16);
>  }
>
>  /// This returns the alignment field of an attribute as a byte alignment value.
>  inline unsigned getAlignmentFromAttrs(Attributes A) {
>   Attributes Align = A & Attribute::Alignment;
> -  if (Align == 0)
> +  if (!Align)
>     return 0;
>
> -  return 1U << ((Align >> 16) - 1);
> +  return 1U << ((Align.Raw() >> 16) - 1);
>  }
>
>  /// This turns an int stack alignment (which must be a power of 2) into
> @@ -134,21 +175,21 @@
>  inline Attributes constructStackAlignmentFromInt(unsigned i) {
>   // Default alignment, allow the target to define how to align it.
>   if (i == 0)
> -    return 0;
> +    return None;
>
>   assert(isPowerOf2_32(i) && "Alignment must be a power of two.");
>   assert(i <= 0x100 && "Alignment too large.");
> -  return (Log2_32(i)+1) << 26;
> +  return Attributes((Log2_32(i)+1) << 26);
>  }
>
>  /// This returns the stack alignment field of an attribute as a byte alignment
>  /// value.
>  inline unsigned getStackAlignmentFromAttrs(Attributes A) {
>   Attributes StackAlign = A & Attribute::StackAlignment;
> -  if (StackAlign == 0)
> +  if (!StackAlign)
>     return 0;
>
> -  return 1U << ((StackAlign >> 26) - 1);
> +  return 1U << ((StackAlign.Raw() >> 26) - 1);
>  }
>
>
> @@ -242,7 +283,7 @@
>   /// paramHasAttr - Return true if the specified parameter index has the
>   /// specified attribute set.
>   bool paramHasAttr(unsigned Idx, Attributes Attr) const {
> -    return (getAttributes(Idx) & Attr) != 0;
> +    return getAttributes(Idx) & Attr;
>   }
>
>   /// getParamAlignment - Return the alignment for the specified function
>
> Modified: llvm/trunk/lib/AsmParser/LLLexer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.cpp?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/lib/AsmParser/LLLexer.cpp (original)
> +++ llvm/trunk/lib/AsmParser/LLLexer.cpp Fri Jan 20 11:56:17 2012
> @@ -548,6 +548,7 @@
>   KEYWORD(noimplicitfloat);
>   KEYWORD(naked);
>   KEYWORD(nonlazybind);
> +  KEYWORD(address_safety);
>
>   KEYWORD(type);
>   KEYWORD(opaque);
>
> Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
> +++ llvm/trunk/lib/AsmParser/LLParser.cpp Fri Jan 20 11:56:17 2012
> @@ -874,7 +874,7 @@
>  /// ParseOptionalAttrs - Parse a potentially empty attribute list.  AttrKind
>  /// indicates what kind of attribute list this is: 0: function arg, 1: result,
>  /// 2: function attr.
> -bool LLParser::ParseOptionalAttrs(unsigned &Attrs, unsigned AttrKind) {
> +bool LLParser::ParseOptionalAttrs(Attributes &Attrs, unsigned AttrKind) {
>   Attrs = Attribute::None;
>   LocTy AttrLoc = Lex.getLoc();
>
> @@ -919,6 +919,7 @@
>     case lltok::kw_noimplicitfloat: Attrs |= Attribute::NoImplicitFloat; break;
>     case lltok::kw_naked:           Attrs |= Attribute::Naked; break;
>     case lltok::kw_nonlazybind:     Attrs |= Attribute::NonLazyBind; break;
> +    case lltok::kw_address_safety:  Attrs |= Attribute::AddressSafety; break;
>
>     case lltok::kw_alignstack: {
>       unsigned Alignment;
> @@ -1353,8 +1354,8 @@
>     // Parse the argument.
>     LocTy ArgLoc;
>     Type *ArgTy = 0;
> -    unsigned ArgAttrs1 = Attribute::None;
> -    unsigned ArgAttrs2 = Attribute::None;
> +    Attributes ArgAttrs1;
> +    Attributes ArgAttrs2;
>     Value *V;
>     if (ParseType(ArgTy, ArgLoc))
>       return true;
> @@ -1394,7 +1395,7 @@
>   } else {
>     LocTy TypeLoc = Lex.getLoc();
>     Type *ArgTy = 0;
> -    unsigned Attrs;
> +    Attributes Attrs;
>     std::string Name;
>
>     if (ParseType(ArgTy) ||
> @@ -1461,7 +1462,7 @@
>   for (unsigned i = 0, e = ArgList.size(); i != e; ++i) {
>     if (!ArgList[i].Name.empty())
>       return Error(ArgList[i].Loc, "argument name invalid in function type");
> -    if (ArgList[i].Attrs != 0)
> +    if (ArgList[i].Attrs)
>       return Error(ArgList[i].Loc,
>                    "argument attributes invalid in function type");
>   }
> @@ -2586,7 +2587,8 @@
>   LocTy LinkageLoc = Lex.getLoc();
>   unsigned Linkage;
>
> -  unsigned Visibility, RetAttrs;
> +  unsigned Visibility;
> +  Attributes RetAttrs;
>   CallingConv::ID CC;
>   Type *RetType = 0;
>   LocTy RetTypeLoc = Lex.getLoc();
> @@ -2650,7 +2652,7 @@
>
>   SmallVector<ArgInfo, 8> ArgList;
>   bool isVarArg;
> -  unsigned FuncAttrs;
> +  Attributes FuncAttrs;
>   std::string Section;
>   unsigned Alignment;
>   std::string GC;
> @@ -3162,7 +3164,7 @@
>  ///       OptionalAttrs 'to' TypeAndValue 'unwind' TypeAndValue
>  bool LLParser::ParseInvoke(Instruction *&Inst, PerFunctionState &PFS) {
>   LocTy CallLoc = Lex.getLoc();
> -  unsigned RetAttrs, FnAttrs;
> +  Attributes RetAttrs, FnAttrs;
>   CallingConv::ID CC;
>   Type *RetType = 0;
>   LocTy RetTypeLoc;
> @@ -3561,7 +3563,7 @@
>  ///       ParameterList OptionalAttrs
>  bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS,
>                          bool isTail) {
> -  unsigned RetAttrs, FnAttrs;
> +  Attributes RetAttrs, FnAttrs;
>   CallingConv::ID CC;
>   Type *RetType = 0;
>   LocTy RetTypeLoc;
>
> Modified: llvm/trunk/lib/AsmParser/LLParser.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.h?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/lib/AsmParser/LLParser.h (original)
> +++ llvm/trunk/lib/AsmParser/LLParser.h Fri Jan 20 11:56:17 2012
> @@ -15,6 +15,7 @@
>  #define LLVM_ASMPARSER_LLPARSER_H
>
>  #include "LLLexer.h"
> +#include "llvm/Attributes.h"
>  #include "llvm/Instructions.h"
>  #include "llvm/Module.h"
>  #include "llvm/Type.h"
> @@ -171,7 +172,7 @@
>       return ParseUInt32(Val);
>     }
>     bool ParseOptionalAddrSpace(unsigned &AddrSpace);
> -    bool ParseOptionalAttrs(unsigned &Attrs, unsigned AttrKind);
> +    bool ParseOptionalAttrs(Attributes &Attrs, unsigned AttrKind);
>     bool ParseOptionalLinkage(unsigned &Linkage, bool &HasLinkage);
>     bool ParseOptionalLinkage(unsigned &Linkage) {
>       bool HasLinkage; return ParseOptionalLinkage(Linkage, HasLinkage);
> @@ -304,8 +305,8 @@
>     struct ParamInfo {
>       LocTy Loc;
>       Value *V;
> -      unsigned Attrs;
> -      ParamInfo(LocTy loc, Value *v, unsigned attrs)
> +      Attributes Attrs;
> +      ParamInfo(LocTy loc, Value *v, Attributes attrs)
>         : Loc(loc), V(v), Attrs(attrs) {}
>     };
>     bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
> @@ -325,9 +326,9 @@
>     struct ArgInfo {
>       LocTy Loc;
>       Type *Ty;
> -      unsigned Attrs;
> +      Attributes Attrs;
>       std::string Name;
> -      ArgInfo(LocTy L, Type *ty, unsigned Attr, const std::string &N)
> +      ArgInfo(LocTy L, Type *ty, Attributes Attr, const std::string &N)
>         : Loc(L), Ty(ty), Attrs(Attr), Name(N) {}
>     };
>     bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList, bool &isVarArg);
>
> Modified: llvm/trunk/lib/AsmParser/LLToken.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLToken.h?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/lib/AsmParser/LLToken.h (original)
> +++ llvm/trunk/lib/AsmParser/LLToken.h Fri Jan 20 11:56:17 2012
> @@ -102,6 +102,7 @@
>     kw_noimplicitfloat,
>     kw_naked,
>     kw_nonlazybind,
> +    kw_address_safety,
>
>     kw_type,
>     kw_opaque,
>
> Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
> +++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Fri Jan 20 11:56:17 2012
> @@ -461,8 +461,8 @@
>       // If Function attributes are using index 0 then transfer them
>       // to index ~0. Index 0 is used for return value attributes but used to be
>       // used for function attributes.
> -      Attributes RetAttribute = Attribute::None;
> -      Attributes FnAttribute = Attribute::None;
> +      Attributes RetAttribute;
> +      Attributes FnAttribute;
>       for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
>         // FIXME: remove in LLVM 3.0
>         // The alignment is stored as a 16-bit raw value from bits 31--16.
> @@ -472,23 +472,24 @@
>         if (Alignment && !isPowerOf2_32(Alignment))
>           return Error("Alignment is not a power of two.");
>
> -        Attributes ReconstitutedAttr = Record[i+1] & 0xffff;
> +        Attributes ReconstitutedAttr(Record[i+1] & 0xffff);
>         if (Alignment)
>           ReconstitutedAttr |= Attribute::constructAlignmentFromInt(Alignment);
> -        ReconstitutedAttr |= (Record[i+1] & (0xffffull << 32)) >> 11;
> -        Record[i+1] = ReconstitutedAttr;
> +        ReconstitutedAttr |=
> +            Attributes((Record[i+1] & (0xffffull << 32)) >> 11);
>
> +        Record[i+1] = ReconstitutedAttr.Raw();
>         if (Record[i] == 0)
> -          RetAttribute = Record[i+1];
> +          RetAttribute = ReconstitutedAttr;
>         else if (Record[i] == ~0U)
> -          FnAttribute = Record[i+1];
> +          FnAttribute = ReconstitutedAttr;
>       }
>
> -      unsigned OldRetAttrs = (Attribute::NoUnwind|Attribute::NoReturn|
> +      Attributes OldRetAttrs = (Attribute::NoUnwind|Attribute::NoReturn|
>                               Attribute::ReadOnly|Attribute::ReadNone);
>
>       if (FnAttribute == Attribute::None && RetAttribute != Attribute::None &&
> -          (RetAttribute & OldRetAttrs) != 0) {
> +          (RetAttribute & OldRetAttrs)) {
>         if (FnAttribute == Attribute::None) { // add a slot so they get added.
>           Record.push_back(~0U);
>           Record.push_back(0);
> @@ -505,8 +506,9 @@
>         } else if (Record[i] == ~0U) {
>           if (FnAttribute != Attribute::None)
>             Attrs.push_back(AttributeWithIndex::get(~0U, FnAttribute));
> -        } else if (Record[i+1] != Attribute::None)
> -          Attrs.push_back(AttributeWithIndex::get(Record[i], Record[i+1]));
> +        } else if (Attributes(Record[i+1]) != Attribute::None)
> +          Attrs.push_back(AttributeWithIndex::get(Record[i],
> +                                                  Attributes(Record[i+1])));
>       }
>
>       MAttributes.push_back(AttrListPtr::get(Attrs.begin(), Attrs.end()));
>
> Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
> +++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Fri Jan 20 11:56:17 2012
> @@ -179,10 +179,11 @@
>       // Store the alignment in the bitcode as a 16-bit raw value instead of a
>       // 5-bit log2 encoded value. Shift the bits above the alignment up by
>       // 11 bits.
> -      uint64_t FauxAttr = PAWI.Attrs & 0xffff;
> +      uint64_t FauxAttr = PAWI.Attrs.Raw() & 0xffff;
>       if (PAWI.Attrs & Attribute::Alignment)
> -        FauxAttr |= (1ull<<16)<<(((PAWI.Attrs & Attribute::Alignment)-1) >> 16);
> -      FauxAttr |= (PAWI.Attrs & (0x3FFull << 21)) << 11;
> +        FauxAttr |= (1ull<<16)<<
> +            (((PAWI.Attrs & Attribute::Alignment).Raw()-1) >> 16);
> +      FauxAttr |= (PAWI.Attrs.Raw() & (0x3FFull << 21)) << 11;
>
>       Record.push_back(FauxAttr);
>     }
>
> Modified: llvm/trunk/lib/CodeGen/Analysis.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Analysis.cpp?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/Analysis.cpp (original)
> +++ llvm/trunk/lib/CodeGen/Analysis.cpp Fri Jan 20 11:56:17 2012
> @@ -259,7 +259,7 @@
>   // Conservatively require the attributes of the call to match those of
>   // the return. Ignore noalias because it doesn't affect the call sequence.
>   const Function *F = ExitBB->getParent();
> -  unsigned CallerRetAttr = F->getAttributes().getRetAttributes();
> +  Attributes CallerRetAttr = F->getAttributes().getRetAttributes();
>   if ((CalleeRetAttr ^ CallerRetAttr) & ~Attribute::NoAlias)
>     return false;
>
> @@ -299,7 +299,7 @@
>
>   // Conservatively require the attributes of the call to match those of
>   // the return. Ignore noalias because it doesn't affect the call sequence.
> -  unsigned CallerRetAttr = F->getAttributes().getRetAttributes();
> +  Attributes CallerRetAttr = F->getAttributes().getRetAttributes();
>   if (CallerRetAttr & ~Attribute::NoAlias)
>     return false;
>
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Fri Jan 20 11:56:17 2012
> @@ -1063,7 +1063,7 @@
>     if (!CastInst::isCastable(ActTy, ParamTy))
>       return false;   // Cannot transform this parameter value.
>
> -    unsigned Attrs = CallerPAL.getParamAttributes(i + 1);
> +    Attributes Attrs = CallerPAL.getParamAttributes(i + 1);
>     if (Attrs & Attribute::typeIncompatible(ParamTy))
>       return false;   // Attribute not compatible with transformed value.
>
> @@ -1392,4 +1392,3 @@
>   CS.setCalledFunction(NewCallee);
>   return CS.getInstruction();
>  }
> -
>
> Modified: llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp Fri Jan 20 11:56:17 2012
> @@ -619,7 +619,7 @@
>   // It's not safe to eliminate the sign / zero extension of the return value.
>   // See llvm::isInTailCallPosition().
>   const Function *F = BB->getParent();
> -  unsigned CallerRetAttr = F->getAttributes().getRetAttributes();
> +  Attributes CallerRetAttr = F->getAttributes().getRetAttributes();
>   if ((CallerRetAttr & Attribute::ZExt) || (CallerRetAttr & Attribute::SExt))
>     return false;
>
> @@ -674,7 +674,7 @@
>
>     // Conservatively require the attributes of the call to match those of the
>     // return. Ignore noalias because it doesn't affect the call sequence.
> -    unsigned CalleeRetAttr = CS.getAttributes().getRetAttributes();
> +    Attributes CalleeRetAttr = CS.getAttributes().getRetAttributes();
>     if ((CalleeRetAttr ^ CallerRetAttr) & ~Attribute::NoAlias)
>       continue;
>
>
> Modified: llvm/trunk/lib/VMCore/Attributes.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Attributes.cpp?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/lib/VMCore/Attributes.cpp (original)
> +++ llvm/trunk/lib/VMCore/Attributes.cpp Fri Jan 20 11:56:17 2012
> @@ -76,6 +76,8 @@
>     Result += "naked ";
>   if (Attrs & Attribute::NonLazyBind)
>     Result += "nonlazybind ";
> +  if (Attrs & Attribute::AddressSafety)
> +    Result += "address_safety ";
>   if (Attrs & Attribute::StackAlignment) {
>     Result += "alignstack(";
>     Result += utostr(Attribute::getStackAlignmentFromAttrs(Attrs));
> @@ -152,8 +154,10 @@
>   }
>   static void Profile(FoldingSetNodeID &ID, const AttributeWithIndex *Attr,
>                       unsigned NumAttrs) {
> -    for (unsigned i = 0; i != NumAttrs; ++i)
> -      ID.AddInteger(uint64_t(Attr[i].Attrs) << 32 | unsigned(Attr[i].Index));
> +    for (unsigned i = 0; i != NumAttrs; ++i) {
> +      ID.AddInteger(Attr[i].Attrs.Raw());
> +      ID.AddInteger(Attr[i].Index);
> +    }
>   }
>  };
>  }
>
> Modified: llvm/trunk/lib/VMCore/Core.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/lib/VMCore/Core.cpp (original)
> +++ llvm/trunk/lib/VMCore/Core.cpp Fri Jan 20 11:56:17 2012
> @@ -13,6 +13,7 @@
>  //===----------------------------------------------------------------------===//
>
>  #include "llvm-c/Core.h"
> +#include "llvm/Attributes.h"
>  #include "llvm/Bitcode/ReaderWriter.h"
>  #include "llvm/Constants.h"
>  #include "llvm/DerivedTypes.h"
> @@ -1350,14 +1351,14 @@
>  void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
>   Function *Func = unwrap<Function>(Fn);
>   const AttrListPtr PAL = Func->getAttributes();
> -  const AttrListPtr PALnew = PAL.addAttr(~0U, PA);
> +  const AttrListPtr PALnew = PAL.addAttr(~0U, Attributes(PA));
>   Func->setAttributes(PALnew);
>  }
>
>  void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
>   Function *Func = unwrap<Function>(Fn);
>   const AttrListPtr PAL = Func->getAttributes();
> -  const AttrListPtr PALnew = PAL.removeAttr(~0U, PA);
> +  const AttrListPtr PALnew = PAL.removeAttr(~0U, Attributes(PA));
>   Func->setAttributes(PALnew);
>  }
>
> @@ -1365,7 +1366,7 @@
>   Function *Func = unwrap<Function>(Fn);
>   const AttrListPtr PAL = Func->getAttributes();
>   Attributes attr = PAL.getFnAttributes();
> -  return (LLVMAttribute)attr;
> +  return (LLVMAttribute)attr.Raw();
>  }
>
>  /*--.. Operations on parameters ............................................--*/
> @@ -1427,18 +1428,18 @@
>  }
>
>  void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
> -  unwrap<Argument>(Arg)->addAttr(PA);
> +  unwrap<Argument>(Arg)->addAttr(Attributes(PA));
>  }
>
>  void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
> -  unwrap<Argument>(Arg)->removeAttr(PA);
> +  unwrap<Argument>(Arg)->removeAttr(Attributes(PA));
>  }
>
>  LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg) {
>   Argument *A = unwrap<Argument>(Arg);
>   Attributes attr = A->getParent()->getAttributes().getParamAttributes(
>     A->getArgNo()+1);
> -  return (LLVMAttribute)attr;
> +  return (LLVMAttribute)attr.Raw();
>  }
>
>
> @@ -1635,14 +1636,14 @@
>                            LLVMAttribute PA) {
>   CallSite Call = CallSite(unwrap<Instruction>(Instr));
>   Call.setAttributes(
> -    Call.getAttributes().addAttr(index, PA));
> +    Call.getAttributes().addAttr(index, Attributes(PA)));
>  }
>
>  void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
>                               LLVMAttribute PA) {
>   CallSite Call = CallSite(unwrap<Instruction>(Instr));
>   Call.setAttributes(
> -    Call.getAttributes().removeAttr(index, PA));
> +    Call.getAttributes().removeAttr(index, Attributes(PA)));
>  }
>
>  void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
>
> Modified: llvm/trunk/lib/VMCore/Verifier.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Verifier.cpp?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/lib/VMCore/Verifier.cpp (original)
> +++ llvm/trunk/lib/VMCore/Verifier.cpp Fri Jan 20 11:56:17 2012
> @@ -547,7 +547,7 @@
>   for (unsigned i = 0;
>        i < array_lengthof(Attribute::MutuallyIncompatible); ++i) {
>     Attributes MutI = Attrs & Attribute::MutuallyIncompatible[i];
> -    Assert1(!(MutI & (MutI - 1)), "Attributes " +
> +    Assert1(MutI.isEmptyOrSingleton(), "Attributes " +
>             Attribute::getAsString(MutI) + " are incompatible!", V);
>   }
>
> @@ -607,7 +607,7 @@
>   for (unsigned i = 0;
>        i < array_lengthof(Attribute::MutuallyIncompatible); ++i) {
>     Attributes MutI = FAttrs & Attribute::MutuallyIncompatible[i];
> -    Assert1(!(MutI & (MutI - 1)), "Attributes " +
> +    Assert1(MutI.isEmptyOrSingleton(), "Attributes " +
>             Attribute::getAsString(MutI) + " are incompatible!", V);
>   }
>  }
>
> Modified: llvm/trunk/utils/llvm.grm
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/llvm.grm?rev=148553&r1=148552&r2=148553&view=diff
> ==============================================================================
> --- llvm/trunk/utils/llvm.grm (original)
> +++ llvm/trunk/utils/llvm.grm Fri Jan 20 11:56:17 2012
> @@ -174,6 +174,7 @@
>  | sspreq
>  | returns_twice
>  | nonlazybind
> + | address_safety
>  ;
>
>  OptFuncAttrs  ::= + _ | OptFuncAttrs FuncAttr ;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list