[PATCH] Fix alignment issues in LLVM.

Duncan P. N. Exon Smith dexonsmith at apple.com
Tue Jun 16 11:04:42 PDT 2015


> On 2015-Jun-16, at 09:32, Reid Kleckner <rnk at google.com> wrote:
> 
> BTW, Duncan recently rewrote this so I'll add him.
> 

LGTM once you've addressed Reid's comments, although I have some nitpicks
below.

Isn't there some logic like this in `User` too?  Pete was changing it
around recently.

> Index: include/llvm/IR/DerivedTypes.h
> ===================================================================
> --- include/llvm/IR/DerivedTypes.h
> +++ include/llvm/IR/DerivedTypes.h
> @@ -140,7 +140,9 @@
>      return T->getTypeID() == FunctionTyID;
>    }
>  };
> -
> +// Assert objects tacked on the end of FunctionType won't be misaligned
> +static_assert(AlignOf<FunctionType>::Alignment >= AlignOf<Type *>::Alignment,
> +              "");

Please put the comment inside the assertion, so we get a decent compiler error.

    static_assert(..., "Expected FunctionType not to change alignment");

>  
>  /// CompositeType - Common super class of ArrayType, StructType, PointerType
>  /// and VectorType.
> Index: lib/IR/AttributeImpl.h
> ===================================================================
> --- lib/IR/AttributeImpl.h
> +++ lib/IR/AttributeImpl.h
> @@ -181,17 +181,23 @@
>        AttrList[I].Profile(ID);
>    }
>  };
> +// Assert objects tacked on the end of AttributeSetNode won't be misaligned
> +static_assert(AlignOf<AttributeSetNode>::Alignment >=
> +                  AlignOf<Attribute>::Alignment,
> +              "");

Same here.

> @@ -267,6 +274,10 @@
>  
>    void dump() const;
>  };
> +// Assert objects tacked on the end of AttributeSetImpl won't be misaligned
> +static_assert(AlignOf<AttributeSetImpl>::Alignment >=
> +                  AlignOf<AttributeSetImpl::IndexAttrPair>::Alignment,
> +              "");

Same here.

>  
>  } // end llvm namespace
>  
> Index: lib/IR/Metadata.cpp
> ===================================================================
> --- lib/IR/Metadata.cpp
> +++ lib/IR/Metadata.cpp
> @@ -381,20 +381,38 @@
>  // MDNode implementation.
>  //
>  
> +// Assert that the MDNode types will not be unaligned by the objects
> +// prepended to them.
> +#define HANDLE_MDNODE_LEAF(CLASS)                                              \
> +  static_assert(llvm::AlignOf<uint64_t>::Alignment >=                          \
> +                    llvm::AlignOf<CLASS>::Alignment,                           \
> +                "");

Same here.  You can even shove `CLASS` into the error message:

    static_assert(..., "Expected ... not to change alignment of " #CLASS);





More information about the llvm-commits mailing list