Use AlignOf traits to enable static_assert.
authorPete Cooper <peter_cooper@apple.com>
Tue, 9 Jun 2015 20:58:03 +0000 (20:58 +0000)
committerPete Cooper <peter_cooper@apple.com>
Tue, 9 Jun 2015 20:58:03 +0000 (20:58 +0000)
This is better than runtime asserts.  Thanks to David Blaikie for the help here.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239431 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCSymbol.cpp

index f0f35f7b29e17f92d948a74ffaa7c9683bf31cb2..836d28294f55fb7823ae502ab93f497fbeaff0f6 100644 (file)
@@ -28,9 +28,9 @@ void *MCSymbol::operator new(size_t s, const StringMapEntry<bool> *Name,
   // For safety, ensure that the alignment of a pointer is enough for an
   // MCSymbol.  This also ensures we don't need padding between the name and
   // symbol.
-  // FIXME: Use static_assert when constexpr is supported.
-  assert(alignOf<MCSymbol>() <= alignOf<NameEntryStorageTy>() &&
-         "Bad alignment of MCSymbol");
+  static_assert(AlignOf<MCSymbol>::Alignment <=
+                AlignOf<NameEntryStorageTy>::Alignment,
+                "Bad alignment of MCSymbol");
   void *Storage = Ctx.allocate(Size, alignOf<NameEntryStorageTy>());
   NameEntryStorageTy *Start = static_cast<NameEntryStorageTy*>(Storage);
   NameEntryStorageTy *End = Start + (Name ? 1 : 0);