[clang][NFC] Use a more accurate size type in the new operation
authorCaprYang <capryang@gmail.com>
Thu, 20 Jul 2023 18:53:56 +0000 (14:53 -0400)
committerAaron Ballman <aaron@aaronballman.com>
Thu, 20 Jul 2023 18:54:51 +0000 (14:54 -0400)
This prevents issues when PointerWidth and the SizeType width are not same.

Differential Revision: https://reviews.llvm.org/D152160

clang/lib/Sema/SemaExprCXX.cpp

index 3e43b69..423d537 100644 (file)
@@ -2657,11 +2657,10 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
   // FIXME: Should the Sema create the expression and embed it in the syntax
   // tree? Or should the consumer just recalculate the value?
   // FIXME: Using a dummy value will interact poorly with attribute enable_if.
-  IntegerLiteral Size(
-      Context,
-      llvm::APInt::getZero(
-          Context.getTargetInfo().getPointerWidth(LangAS::Default)),
-      Context.getSizeType(), SourceLocation());
+  QualType SizeTy = Context.getSizeType();
+  unsigned SizeTyWidth = Context.getTypeSize(SizeTy);
+  IntegerLiteral Size(Context, llvm::APInt::getZero(SizeTyWidth), SizeTy,
+                      SourceLocation());
   AllocArgs.push_back(&Size);
 
   QualType AlignValT = Context.VoidTy;