[clang] 54aca3f - [clang][NFC] Use a more accurate size type in the new operation

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 20 11:55:13 PDT 2023


Author: CaprYang
Date: 2023-07-20T14:54:51-04:00
New Revision: 54aca3f33f630d2b2955b225401efeb1b4225177

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

LOG: [clang][NFC] Use a more accurate size type in the new operation

This prevents issues when PointerWidth and the SizeType width are not same.

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

Added: 
    

Modified: 
    clang/lib/Sema/SemaExprCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 3e43b69dc8bb29..423d5372a6f65a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -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;


        


More information about the cfe-commits mailing list