[PATCH] D137235: [clang][Interp] Fix ImplicitValueInitExprs for pointer types
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 25 03:32:06 PST 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2725e2c0323f: [clang][Interp] Fix ImplicitValueInitExprs for pointer types (authored by tbaeder).
Changed prior to commit:
https://reviews.llvm.org/D137235?vs=472545&id=492049#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137235/new/
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
@@ -279,10 +279,15 @@
template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) {
- if (std::optional<PrimType> T = classify(E))
- return this->emitZero(*T, E);
+ std::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.492049.patch
Type: text/x-patch
Size: 1361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230125/896e4c73/attachment.bin>
More information about the cfe-commits
mailing list