https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/67147
>From 54840541b94b5ccc02c1c563678991ea230acbb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Fri, 22 Sep 2023 16:27:11 +0200 Subject: [PATCH] [clang][Interp] Handle CXXScalarValueInitExprs --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 6 ++++++ clang/lib/AST/Interp/ByteCodeExprGen.h | 1 + clang/test/AST/Interp/literals.cpp | 27 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 02b35583636bf13..9bd040a208b3f95 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1531,6 +1531,12 @@ bool ByteCodeExprGen<Emitter>::VisitOffsetOfExpr(const OffsetOfExpr *E) { return this->emitOffsetOf(T, E, E); } +template <class Emitter> +bool ByteCodeExprGen<Emitter>::VisitCXXScalarValueInitExpr( + const CXXScalarValueInitExpr *E) { + return this->visitZeroInitializer(E->getType(), E); +} + template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) { if (E->containsErrors()) return false; diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h index 47a3f75f13459d0..7cfe4d9251c5f05 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.h +++ b/clang/lib/AST/Interp/ByteCodeExprGen.h @@ -106,6 +106,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>, bool VisitCXXConstructExpr(const CXXConstructExpr *E); bool VisitSourceLocExpr(const SourceLocExpr *E); bool VisitOffsetOfExpr(const OffsetOfExpr *E); + bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E); protected: bool visitExpr(const Expr *E) override; diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index ceda59405ea9105..a83dcd234111587 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -31,6 +31,33 @@ static_assert(b, ""); constexpr int one = true; static_assert(one == 1, ""); +constexpr bool b2 = bool(); +static_assert(!b2, ""); + +namespace ScalarTypes { + constexpr int ScalarInitInt = int(); + static_assert(ScalarInitInt == 0, ""); + constexpr float ScalarInitFloat = float(); + static_assert(ScalarInitFloat == 0.0f, ""); + + static_assert(decltype(nullptr)() == nullptr, ""); + + template<typename T> + constexpr T getScalar() { return T(); } + + static_assert(getScalar<const int>() == 0, ""); + static_assert(getScalar<const double>() == 0.0, ""); + + static_assert(getScalar<void*>() == nullptr, ""); + static_assert(getScalar<void(*)(void)>() == nullptr, ""); + + enum E { + First = 0, + }; + static_assert(getScalar<E>() == First, ""); + /// FIXME: Member pointers. +} + namespace IntegralCasts { constexpr int i = 12; constexpr unsigned int ui = i; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits