[PATCH] D137235: [clang][Interp] Fix ImplicitValueInitExprs for pointer types
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 2 02:30:03 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 ran into an "unknown type" assertion when trying to emit
a 'Zero' op for a pointer type. Emit a NullPtr op instead.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137235
Files:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/literals.cpp
Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -49,7 +49,10 @@
static_assert(!nu, "");
};
-
+constexpr int UninitI; // expected-error {{must be initialized by a constant expression}} \
+ // ref-error {{must be initialized by a constant expression}}
+constexpr int *UninitPtr; // expected-error {{must be initialized by a constant expression}} \
+ // ref-error {{must be initialized by a constant expression}}
constexpr bool getTrue() { return true; }
constexpr bool getFalse() { return false; }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -359,10 +359,15 @@
template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) {
- if (Optional<PrimType> T = classify(E))
- return this->emitZero(*T, E);
+ Optional<PrimType> T = classify(E);
- return false;
+ if (!T)
+ return false;
+
+ if (E->getType()->isPointerType())
+ return this->emitNullPtr(E);
+
+ return this->emitZero(*T, E);
}
template <class Emitter>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137235.472545.patch
Type: text/x-patch
Size: 1351 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221102/83def662/attachment.bin>
More information about the cfe-commits
mailing list