[PATCH] D125195: [asan][ARMCXXABI] Added missing asan poison array cookie hooks.

Roy Sundahl via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 11 11:19:01 PDT 2022


rsundahl updated this revision to Diff 428718.
rsundahl added a comment.

Revert ItaniumCXXABI.cpp for now (unintentional push)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125195/new/

https://reviews.llvm.org/D125195

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp


Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===================================================================
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2339,10 +2339,16 @@
                                              QualType ElementType) {
   assert(requiresArrayCookie(expr));
 
-  CharUnits SizeSize = CGF.getSizeSize();
-  CharUnits CookieSize = getArrayCookieSizeImpl(ElementType);
   unsigned AS = NewPtr.getAddressSpace();
 
+  ASTContext &Ctx = getContext();
+  CharUnits SizeSize = CGF.getSizeSize();
+
+  // The size of the cookie.
+  CharUnits CookieSize =
+      std::max(SizeSize, Ctx.getPreferredTypeAlignInChars(ElementType));
+  assert(CookieSize == getArrayCookieSizeImpl(ElementType));
+
   // Compute an offset to the cookie.
   Address CookiePtr = NewPtr;
   CharUnits CookieOffset = CookieSize - SizeSize;
@@ -2418,19 +2424,11 @@
                                          QualType elementType) {
   assert(requiresArrayCookie(expr));
 
-  CharUnits sizeSize = CGF.getSizeSize();
-  CharUnits cookieSize = getArrayCookieSizeImpl(elementType);
   unsigned AS = newPtr.getAddressSpace();
 
   // The cookie is always at the start of the buffer.
   Address cookie = newPtr;
 
-  // Compute an offset to the cookie.
-  CharUnits cookieOffset = cookieSize - sizeSize*2;
-  assert(cookieOffset.isZero());
-  if (!cookieOffset.isZero())
-    cookie = CGF.Builder.CreateConstInBoundsByteGEP(cookie, cookieOffset);
-
   // The first element is the element size.
   cookie = CGF.Builder.CreateElementBitCast(cookie, CGF.SizeTy);
   llvm::Value *elementSize = llvm::ConstantInt::get(CGF.SizeTy,
@@ -2456,6 +2454,7 @@
 
   // Finally, compute a pointer to the actual data buffer by skipping
   // over the cookie completely.
+  CharUnits cookieSize = ARMCXXABI::getArrayCookieSizeImpl(elementType);
   return CGF.Builder.CreateConstInBoundsByteGEP(newPtr, cookieSize);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125195.428718.patch
Type: text/x-patch
Size: 1926 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220511/d0c9a14a/attachment.bin>


More information about the cfe-commits mailing list