]> granicus.if.org Git - clang/commitdiff
[NFC] avoid AlignedCharArray in clang
authorJF Bastien <jfbastien@apple.com>
Mon, 29 Jul 2019 23:12:48 +0000 (23:12 +0000)
committerJF Bastien <jfbastien@apple.com>
Mon, 29 Jul 2019 23:12:48 +0000 (23:12 +0000)
As discussed in D65249, don't use AlignedCharArray or std::aligned_storage. Just use alignas(X) char Buf[Size];. This will allow me to remove AlignedCharArray entirely, and works on the current minimum version of Visual Studio.

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

include/clang/AST/Expr.h
include/clang/Sema/Overload.h
lib/CodeGen/CGCleanup.cpp
lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
lib/Sema/SemaOverload.cpp
lib/Sema/TypeLocBuilder.cpp
lib/Sema/TypeLocBuilder.h

index d44a815c8699ea3efa9b62744744cf815ab84c18..e6b16455c33f0590da720fe999cd61e82b769686 100644 (file)
@@ -2619,9 +2619,8 @@ public:
   /// + sizeof(Stmt *) bytes of storage, aligned to alignof(CallExpr):
   ///
   /// \code{.cpp}
-  ///   llvm::AlignedCharArray<alignof(CallExpr),
-  ///                          sizeof(CallExpr) + sizeof(Stmt *)> Buffer;
-  ///   CallExpr *TheCall = CallExpr::CreateTemporary(Buffer.buffer, etc);
+  ///   alignas(CallExpr) char Buffer[sizeof(CallExpr) + sizeof(Stmt *)];
+  ///   CallExpr *TheCall = CallExpr::CreateTemporary(Buffer, etc);
   /// \endcode
   static CallExpr *CreateTemporary(void *Mem, Expr *Fn, QualType Ty,
                                    ExprValueKind VK, SourceLocation RParenLoc,
index 96aadeac2ba389a5a042a0cd6eeb5c00b0a0558b..e9280103a34d6b303cbcba0c4638e0d38df92dbd 100644 (file)
@@ -881,7 +881,7 @@ class Sema;
     constexpr static unsigned NumInlineBytes =
         24 * sizeof(ImplicitConversionSequence);
     unsigned NumInlineBytesUsed = 0;
-    llvm::AlignedCharArray<alignof(void *), NumInlineBytes> InlineSpace;
+    alignas(void *) char InlineSpace[NumInlineBytes];
 
     // Address space of the object being constructed.
     LangAS DestAS = LangAS::Default;
@@ -904,7 +904,7 @@ class Sema;
       unsigned NBytes = sizeof(T) * N;
       if (NBytes > NumInlineBytes - NumInlineBytesUsed)
         return SlabAllocator.Allocate<T>(N);
-      char *FreeSpaceStart = InlineSpace.buffer + NumInlineBytesUsed;
+      char *FreeSpaceStart = InlineSpace + NumInlineBytesUsed;
       assert(uintptr_t(FreeSpaceStart) % alignof(void *) == 0 &&
              "Misaligned storage!");
 
index 5594f3030229dd99e20a8567f50fda9a50226b1c..3cf366e4635d5962cb16262bb3ae8dec918a8e42 100644 (file)
@@ -740,14 +740,15 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
   // here. Unfortunately, if you ask for a SmallVector<char>, the
   // alignment isn't sufficient.
   auto *CleanupSource = reinterpret_cast<char *>(Scope.getCleanupBuffer());
-  llvm::AlignedCharArray<EHScopeStack::ScopeStackAlignment, 8 * sizeof(void *)> CleanupBufferStack;
+  alignas(EHScopeStack::ScopeStackAlignment) char
+      CleanupBufferStack[8 * sizeof(void *)];
   std::unique_ptr<char[]> CleanupBufferHeap;
   size_t CleanupSize = Scope.getCleanupSize();
   EHScopeStack::Cleanup *Fn;
 
   if (CleanupSize <= sizeof(CleanupBufferStack)) {
-    memcpy(CleanupBufferStack.buffer, CleanupSource, CleanupSize);
-    Fn = reinterpret_cast<EHScopeStack::Cleanup *>(CleanupBufferStack.buffer);
+    memcpy(CleanupBufferStack, CleanupSource, CleanupSize);
+    Fn = reinterpret_cast<EHScopeStack::Cleanup *>(CleanupBufferStack);
   } else {
     CleanupBufferHeap.reset(new char[CleanupSize]);
     memcpy(CleanupBufferHeap.get(), CleanupSource, CleanupSize);
index 6d7d69da4db5a945a24619f36948b1273b49154c..114d0815ba4c940b69729fbed018cbcfd73e0ef3 100644 (file)
@@ -184,10 +184,11 @@ void DirectoryWatcherLinux::InotifyPollingLoop() {
   // the inotify file descriptor should have the same alignment as
   // struct inotify_event.
 
-  auto ManagedBuffer =
-      llvm::make_unique<llvm::AlignedCharArray<alignof(struct inotify_event),
-                                               EventBufferLength>>();
-  char *const Buf = ManagedBuffer->buffer;
+  struct Buffer {
+    alignas(struct inotify_event) char buffer[EventBufferLength];
+  };
+  auto ManagedBuffer = llvm::make_unique<Buffer>();
+  char *const Buf = ManagedBuffer.buffer;
 
   const int EpollFD = epoll_create1(EPOLL_CLOEXEC);
   if (EpollFD == -1) {
@@ -350,4 +351,4 @@ std::unique_ptr<DirectoryWatcher> clang::DirectoryWatcher::create(
   return llvm::make_unique<DirectoryWatcherLinux>(
       Path, Receiver, WaitForInitialSync, InotifyFD, InotifyWD,
       std::move(*InotifyPollingStopper));
-}
\ No newline at end of file
+}
index f632a4d3bd1a7251e17b589c81f518a918fd249e..3e2657b46c4f915686d18cc5701c99448fe5b450 100644 (file)
@@ -7052,10 +7052,9 @@ void Sema::AddConversionCandidate(
   // allocator).
   QualType CallResultType = ConversionType.getNonLValueExprType(Context);
 
-  llvm::AlignedCharArray<alignof(CallExpr), sizeof(CallExpr) + sizeof(Stmt *)>
-      Buffer;
+  alignas(CallExpr) char Buffer[sizeof(CallExpr) + sizeof(Stmt *)];
   CallExpr *TheTemporaryCall = CallExpr::CreateTemporary(
-      Buffer.buffer, &ConversionFn, CallResultType, VK, From->getBeginLoc());
+      Buffer, &ConversionFn, CallResultType, VK, From->getBeginLoc());
 
   ImplicitConversionSequence ICS =
       TryCopyInitialization(*this, TheTemporaryCall, ToType,
index b451403544ed955ed0638ef501205bff32983521..2dcbbd83c691227d25254d6ef653cae9c26a4131 100644 (file)
@@ -51,7 +51,7 @@ void TypeLocBuilder::grow(size_t NewCapacity) {
          &Buffer[Index],
          Capacity - Index);
 
-  if (Buffer != InlineBuffer.buffer)
+  if (Buffer != InlineBuffer)
     delete[] Buffer;
 
   Buffer = NewBuffer;
index 1e6883926a80f17ee7f6e0d1e2b420cbad4a881e..738f731c9fe25390fb3c0b114dc4c5f14115cf61 100644 (file)
@@ -39,18 +39,16 @@ class TypeLocBuilder {
 
   /// The inline buffer.
   enum { BufferMaxAlignment = alignof(void *) };
-  llvm::AlignedCharArray<BufferMaxAlignment, InlineCapacity> InlineBuffer;
+  alignas(BufferMaxAlignment) char InlineBuffer[InlineCapacity];
   unsigned NumBytesAtAlign4, NumBytesAtAlign8;
 
- public:
+public:
   TypeLocBuilder()
-    : Buffer(InlineBuffer.buffer), Capacity(InlineCapacity),
-      Index(InlineCapacity), NumBytesAtAlign4(0), NumBytesAtAlign8(0)
-  {
-  }
+      : Buffer(InlineBuffer), Capacity(InlineCapacity), Index(InlineCapacity),
+        NumBytesAtAlign4(0), NumBytesAtAlign8(0) {}
 
   ~TypeLocBuilder() {
-    if (Buffer != InlineBuffer.buffer)
+    if (Buffer != InlineBuffer)
       delete[] Buffer;
   }