Switch some realignment calculations over to llvm::RoundUpToAlignment.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162297 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h
index 5985437..a2355ca 100644
--- a/include/clang/AST/ExprCXX.h
+++ b/include/clang/AST/ExprCXX.h
@@ -1281,9 +1281,9 @@
   
   /// \brief Retrieve the complete set of array-index variables.
   VarDecl **getArrayIndexVars() const {
-    unsigned ArrayIndexSize = sizeof(unsigned) * (NumCaptures + 1);
-    unsigned Align = llvm::alignOf<VarDecl*>();
-    ArrayIndexSize = (ArrayIndexSize + Align - 1) & ~(Align - 1);
+    unsigned ArrayIndexSize =
+        llvm::RoundUpToAlignment(sizeof(unsigned) * (NumCaptures + 1),
+                                 llvm::alignOf<VarDecl*>());
     return reinterpret_cast<VarDecl **>(
         reinterpret_cast<char*>(getArrayIndexStarts()) + ArrayIndexSize);
   }
diff --git a/include/clang/Basic/OnDiskHashTable.h b/include/clang/Basic/OnDiskHashTable.h
index 79273fc..66109e7 100644
--- a/include/clang/Basic/OnDiskHashTable.h
+++ b/include/clang/Basic/OnDiskHashTable.h
@@ -65,8 +65,7 @@
 
 inline void Pad(raw_ostream& Out, unsigned A) {
   Offset off = (Offset) Out.tell();
-  uint32_t n = ((uintptr_t)(off+A-1) & ~(uintptr_t)(A-1)) - off;
-  for (; n ; --n)
+  for (uint32_t n = llvm::OffsetToAlignment(off, A); n; --n)
     Emit8(Out, 0);
 }
 
diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp
index 97814af..40d218b 100644
--- a/lib/AST/ExprCXX.cpp
+++ b/lib/AST/ExprCXX.cpp
@@ -880,8 +880,7 @@
   if (!ArrayIndexVars.empty()) {
     Size += sizeof(unsigned) * (Captures.size() + 1);
     // Realign for following VarDecl array.
-    unsigned Align = llvm::alignOf<VarDecl*>();
-    Size = (Size + Align - 1) & ~(Align - 1);
+    Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<VarDecl*>());
     Size += sizeof(VarDecl *) * ArrayIndexVars.size();
   }
   void *Mem = Context.Allocate(Size);