[PATCH] D119525: [clang] Fix crash when array size is missing in initializer

Timm B├Ąder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 10 23:38:10 PST 2022


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, rsmith.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This fixes the crash from https://github.com/llvm/llvm-project/issues/53742

`CXXNewExpr::getArraySize()` may return a `llvm::Optional<>` pointing to a `nullptr`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119525

Files:
  clang/lib/AST/ExprConstant.cpp


Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -9427,8 +9427,8 @@
   bool ValueInit = false;
 
   QualType AllocType = E->getAllocatedType();
-  if (Optional<const Expr*> ArraySize = E->getArraySize()) {
-    const Expr *Stripped = *ArraySize;
+  Optional<const Expr*> ArraySize = E->getArraySize();
+  if (const Expr *Stripped = *ArraySize) {
     for (; auto *ICE = dyn_cast<ImplicitCastExpr>(Stripped);
          Stripped = ICE->getSubExpr())
       if (ICE->getCastKind() != CK_NoOp &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119525.407783.patch
Type: text/x-patch
Size: 622 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220211/f989ecca/attachment.bin>


More information about the cfe-commits mailing list