[PATCH] D136839: [clang][Interp] Handle non-primitive locals without initializer
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 27 05:02:34 PDT 2022
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This previously made us crash later on when passing a `nullptr` initializer to `visitLocalInitializer`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D136839
Files:
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/test/AST/Interp/cxx20.cpp
Index: clang/test/AST/Interp/cxx20.cpp
===================================================================
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -70,6 +70,11 @@
}
static_assert(initializedLocal() == 20);
+constexpr void uninitializedLocalArray() {
+ int a[]; // expected-error {{needs an explicit size or an initializer}} \
+ // ref-error {{needs an explicit size or an initializer}}
+}
+
#if 0
// FIXME: This code should be rejected because we pass an uninitialized value
// as a function parameter.
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -394,10 +394,9 @@
return true;
}
+ const Expr *Init = VD->getInit();
// Integers, pointers, primitives.
if (Optional<PrimType> T = this->classify(VD->getType())) {
- const Expr *Init = VD->getInit();
-
unsigned Offset =
this->allocateLocalPrimitive(VD, *T, VD->getType().isConstQualified());
// Compile the initializer in its own scope.
@@ -412,8 +411,11 @@
}
// Composite types - allocate storage and initialize it.
- if (Optional<unsigned> Offset = this->allocateLocal(VD))
- return this->visitLocalInitializer(VD->getInit(), *Offset);
+ if (Optional<unsigned> Offset = this->allocateLocal(VD)) {
+ if (Init)
+ return this->visitLocalInitializer(Init, *Offset);
+ return true;
+ }
return this->bail(VD);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136839.471130.patch
Type: text/x-patch
Size: 1545 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221027/e5b01ab9/attachment.bin>
More information about the cfe-commits
mailing list