ahatanak updated this revision to Diff 462938.
ahatanak added a comment.

Check whether the allocated type is an array type before calling 
`checkArrayElementAlignment`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133711

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/array-alignment.cpp


Index: clang/test/SemaCXX/array-alignment.cpp
===================================================================
--- clang/test/SemaCXX/array-alignment.cpp
+++ clang/test/SemaCXX/array-alignment.cpp
@@ -33,4 +33,5 @@
   auto p3 = new AlignedStruct[1];
   auto p4 = (AlignedPackedStruct(*)[1])p; // expected-error {{size of array 
element}}
   auto p5 = new AlignedPackedStruct[1]; // expected-error {{size of array 
element}}
+  auto p6 = new AlignedPackedStruct;
 }
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -2079,6 +2079,9 @@
   if (CheckAllocatedType(AllocType, TypeRange.getBegin(), TypeRange))
     return ExprError();
 
+  if (ArraySize && !checkArrayElementAlignment(AllocType, 
TypeRange.getBegin()))
+    return ExprError();
+
   // In ARC, infer 'retaining' for the allocated
   if (getLangOpts().ObjCAutoRefCount &&
       AllocType.getObjCLifetime() == Qualifiers::OCL_None &&
@@ -2449,8 +2452,6 @@
   else if (RequireNonAbstractType(Loc, AllocType,
                                   diag::err_allocation_of_abstract_type))
     return true;
-  else if (!checkArrayElementAlignment(AllocType, Loc))
-    return true;
   else if (AllocType->isVariablyModifiedType())
     return Diag(Loc, diag::err_variably_modified_new_type)
              << AllocType;


Index: clang/test/SemaCXX/array-alignment.cpp
===================================================================
--- clang/test/SemaCXX/array-alignment.cpp
+++ clang/test/SemaCXX/array-alignment.cpp
@@ -33,4 +33,5 @@
   auto p3 = new AlignedStruct[1];
   auto p4 = (AlignedPackedStruct(*)[1])p; // expected-error {{size of array element}}
   auto p5 = new AlignedPackedStruct[1]; // expected-error {{size of array element}}
+  auto p6 = new AlignedPackedStruct;
 }
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -2079,6 +2079,9 @@
   if (CheckAllocatedType(AllocType, TypeRange.getBegin(), TypeRange))
     return ExprError();
 
+  if (ArraySize && !checkArrayElementAlignment(AllocType, TypeRange.getBegin()))
+    return ExprError();
+
   // In ARC, infer 'retaining' for the allocated
   if (getLangOpts().ObjCAutoRefCount &&
       AllocType.getObjCLifetime() == Qualifiers::OCL_None &&
@@ -2449,8 +2452,6 @@
   else if (RequireNonAbstractType(Loc, AllocType,
                                   diag::err_allocation_of_abstract_type))
     return true;
-  else if (!checkArrayElementAlignment(AllocType, Loc))
-    return true;
   else if (AllocType->isVariablyModifiedType())
     return Diag(Loc, diag::err_variably_modified_new_type)
              << AllocType;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to