r233912 - Partially revert "Replace custom alignment enforcement with LLVM_ALIGNAS."

Benjamin Kramer benny.kra at googlemail.com
Thu Apr 2 05:43:31 PDT 2015


Author: d0k
Date: Thu Apr  2 07:43:31 2015
New Revision: 233912

URL: http://llvm.org/viewvc/llvm-project?rev=233912&view=rev
Log:
Partially revert "Replace custom alignment enforcement with LLVM_ALIGNAS."

MSVC 2013 can't even parse __declspec(align(sizeof(foo))). We'll have to
wait until MSVC 2015 for this.

This partially reverts commit r233911.

Modified:
    cfe/trunk/include/clang/AST/DeclGroup.h
    cfe/trunk/include/clang/AST/DeclTemplate.h
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/lib/AST/Decl.cpp

Modified: cfe/trunk/include/clang/AST/DeclGroup.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclGroup.h?rev=233912&r1=233911&r2=233912&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclGroup.h (original)
+++ cfe/trunk/include/clang/AST/DeclGroup.h Thu Apr  2 07:43:31 2015
@@ -14,7 +14,6 @@
 #ifndef LLVM_CLANG_AST_DECLGROUP_H
 #define LLVM_CLANG_AST_DECLGROUP_H
 
-#include "llvm/Support/Compiler.h"
 #include "llvm/Support/DataTypes.h"
 #include <cassert>
 
@@ -25,9 +24,13 @@ class Decl;
 class DeclGroup;
 class DeclGroupIterator;
 
-class LLVM_ALIGNAS(sizeof(void *)) DeclGroup {
+class DeclGroup {
   // FIXME: Include a TypeSpecifier object.
-  unsigned NumDecls;
+  union {
+    unsigned NumDecls;
+
+    Decl *Aligner;
+  };
 
 private:
   DeclGroup() : NumDecls(0) {}

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=233912&r1=233911&r2=233912&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Thu Apr  2 07:43:31 2015
@@ -460,12 +460,21 @@ public:
 ///     friend void foo<>(T);
 ///   };
 /// \endcode
-class LLVM_ALIGNAS(sizeof(void *)) DependentFunctionTemplateSpecializationInfo {
-  /// The number of potential template candidates.
-  unsigned NumTemplates;
-
-  /// The number of template arguments.
-  unsigned NumArgs;
+class DependentFunctionTemplateSpecializationInfo {
+  struct CA {
+    /// The number of potential template candidates.
+    unsigned NumTemplates;
+
+    /// The number of template arguments.
+    unsigned NumArgs;
+  };
+
+  union {
+    // Force sizeof to be a multiple of sizeof(void*) so that the
+    // trailing data is aligned.
+    void *Aligner;
+    struct CA d;
+  };
 
   /// The locations of the left and right angle brackets.
   SourceRange AngleLocs;
@@ -481,7 +490,9 @@ public:
 
   /// \brief Returns the number of function templates that this might
   /// be a specialization of.
-  unsigned getNumTemplates() const { return NumTemplates; }
+  unsigned getNumTemplates() const {
+    return d.NumTemplates;
+  }
 
   /// \brief Returns the i'th template candidate.
   FunctionTemplateDecl *getTemplate(unsigned I) const {
@@ -496,7 +507,9 @@ public:
   }
 
   /// \brief Returns the number of explicit template arguments that were given.
-  unsigned getNumTemplateArgs() const { return NumArgs; }
+  unsigned getNumTemplateArgs() const {
+    return d.NumArgs;
+  }
 
   /// \brief Returns the nth template argument.
   const TemplateArgumentLoc &getTemplateArg(unsigned I) const {

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=233912&r1=233911&r2=233912&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Thu Apr  2 07:43:31 2015
@@ -101,7 +101,7 @@ namespace clang {
 
 /// Stmt - This represents one statement.
 ///
-class LLVM_ALIGNAS(sizeof(void *)) Stmt {
+class Stmt {
 public:
   enum StmtClass {
     NoStmtClass = 0,
@@ -287,6 +287,9 @@ protected:
   };
 
   union {
+    // FIXME: this is wasteful on 64-bit platforms.
+    void *Aligner;
+
     StmtBitfields StmtBits;
     CompoundStmtBitfields CompoundStmtBits;
     ExprBitfields ExprBits;

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=233912&r1=233911&r2=233912&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Apr  2 07:43:31 2015
@@ -3103,11 +3103,13 @@ FunctionDecl::setDependentTemplateSpecia
 DependentFunctionTemplateSpecializationInfo::
 DependentFunctionTemplateSpecializationInfo(const UnresolvedSetImpl &Ts,
                                       const TemplateArgumentListInfo &TArgs)
-  : NumTemplates(Ts.size()), NumArgs(TArgs.size()),
-    AngleLocs(TArgs.getLAngleLoc(), TArgs.getRAngleLoc()) {
+  : AngleLocs(TArgs.getLAngleLoc(), TArgs.getRAngleLoc()) {
   static_assert(sizeof(*this) % llvm::AlignOf<void *>::Alignment == 0,
                 "Trailing data is unaligned!");
 
+  d.NumTemplates = Ts.size();
+  d.NumArgs = TArgs.size();
+
   FunctionTemplateDecl **TsArray =
     const_cast<FunctionTemplateDecl**>(getTemplates());
   for (unsigned I = 0, E = Ts.size(); I != E; ++I)





More information about the cfe-commits mailing list