[clang] dd84d23 - Revert "[Clang][Sema] placement new initializes typedef array with correct size (#83124)"

Mikhail Goncharov via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 16 23:37:32 PDT 2024


Author: Mikhail Goncharov
Date: 2024-04-17T08:37:22+02:00
New Revision: dd84d23adc84cc0c3d2b8fb8f0c353279d99d27a

URL: https://github.com/llvm/llvm-project/commit/dd84d23adc84cc0c3d2b8fb8f0c353279d99d27a
DIFF: https://github.com/llvm/llvm-project/commit/dd84d23adc84cc0c3d2b8fb8f0c353279d99d27a.diff

LOG: Revert "[Clang][Sema] placement new initializes typedef array with correct size (#83124)"

This reverts commit c309dc6d0759b23b570c563f611530ff1a49e1bd.

Breaks builds, see discussion in https://github.com/llvm/llvm-project/pull/83124

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/TreeTransform.h

Removed: 
    clang/test/SemaCXX/instantiate-new-placement-size.cpp


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6099f8ab02f443..96ad92b540b47f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -534,7 +534,6 @@ Bug Fixes to C++ Support
   Fixes (#GH70604), (#GH79754), (#GH84163), (#GH84425), (#GH86054), (#GH86398), and (#GH86399).
 - Fix a crash when deducing ``auto`` from an invalid dereference (#GH88329).
 - Fix a crash in requires expression with templated base class member function. Fixes (#GH84020).
-- Placement new initializes typedef array with correct size (#GH41441)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 0c7fdb357235e1..eb05783a6219dc 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -12864,19 +12864,6 @@ TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
     ArraySize = NewArraySize.get();
   }
 
-  // Per C++0x [expr.new]p5, the type being constructed may be a
-  // typedef of an array type.
-  QualType AllocType = AllocTypeInfo->getType();
-  if (ArraySize) {
-    if (const ConstantArrayType *Array =
-            SemaRef.Context.getAsConstantArrayType(AllocType)) {
-      ArraySize = IntegerLiteral::Create(SemaRef.Context, Array->getSize(),
-                                         SemaRef.Context.getSizeType(),
-                                         E->getBeginLoc());
-      AllocType = Array->getElementType();
-    }
-  }
-
   // Transform the placement arguments (if any).
   bool ArgumentChanged = false;
   SmallVector<Expr*, 8> PlacementArgs;
@@ -12938,6 +12925,7 @@ TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
     return E;
   }
 
+  QualType AllocType = AllocTypeInfo->getType();
   if (!ArraySize) {
     // If no array size was specified, but the new expression was
     // instantiated with an array type (e.g., "new T" where T is

diff  --git a/clang/test/SemaCXX/instantiate-new-placement-size.cpp b/clang/test/SemaCXX/instantiate-new-placement-size.cpp
deleted file mode 100644
index 7a29d3dee8491e..00000000000000
--- a/clang/test/SemaCXX/instantiate-new-placement-size.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-// RUN: %clang -S -fno-discard-value-names -emit-llvm -o - %s | FileCheck %s
-// Issue no: 41441
-#include <new>
-
-// CHECK: call void @llvm.memset.p0.i64(ptr align 1 %x, i8 0, i64 8, i1 false)
-// CHECK: call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 32, i1 false)
-template <typename TYPE>
-void f()
-{
-    typedef TYPE TArray[8];
-
-    TArray x;
-    new(&x) TArray();
-}
-
-int main()
-{
-    f<char>();
-    f<int>();
-}


        


More information about the cfe-commits mailing list