Author: Timm Bäder Date: 2023-01-25T12:31:49+01:00 New Revision: 2725e2c0323f1408467452e3cc2a4a8cb3ea49a7
URL: https://github.com/llvm/llvm-project/commit/2725e2c0323f1408467452e3cc2a4a8cb3ea49a7 DIFF: https://github.com/llvm/llvm-project/commit/2725e2c0323f1408467452e3cc2a4a8cb3ea49a7.diff LOG: [clang][Interp] Fix ImplicitValueInitExprs for pointer types This previously ran into an "unknown type" assertion when trying to emit a 'Zero' op for a pointer type. Emit a NullPtr op instead. Differential Revision: https://reviews.llvm.org/D137235 Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/literals.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index dd7d88ae715d..5952e3aa681c 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -279,10 +279,15 @@ bool ByteCodeExprGen<Emitter>::VisitPointerArithBinOp(const BinaryOperator *E) { 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> diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index 4fc9489941e5..4c88e861a443 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -49,7 +49,10 @@ namespace IntegralCasts { 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; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits