[clang] [clang][Interp] Handle SizeOfPackExprs (PR #71929)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/71929 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Handle SizeOfPackExprs (PR #71929)
https://github.com/cor3ntin approved this pull request. LGTM, thanks https://github.com/llvm/llvm-project/pull/71929 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Handle SizeOfPackExprs (PR #71929)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/71929.diff 3 Files Affected: - (modified) clang/lib/AST/Interp/ByteCodeExprGen.cpp (+5) - (modified) clang/lib/AST/Interp/ByteCodeExprGen.h (+1) - (modified) clang/test/AST/Interp/functions.cpp (+7) ``diff diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 15a717089660337..c8d3c1243fc1094 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1624,6 +1624,11 @@ bool ByteCodeExprGen::VisitCXXScalarValueInitExpr( return this->visitZeroInitializer(classifyPrim(Ty), Ty, E); } +template +bool ByteCodeExprGen::VisitSizeOfPackExpr(const SizeOfPackExpr *E) { + return this->emitConst(E->getPackLength(), E); +} + template bool ByteCodeExprGen::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 83986d3dd579ed6..ec9b6bb1408453c 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.h +++ b/clang/lib/AST/Interp/ByteCodeExprGen.h @@ -107,6 +107,7 @@ class ByteCodeExprGen : public ConstStmtVisitor, bool>, bool VisitSourceLocExpr(const SourceLocExpr *E); bool VisitOffsetOfExpr(const OffsetOfExpr *E); bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E); + bool VisitSizeOfPackExpr(const SizeOfPackExpr *E); protected: bool visitExpr(const Expr *E) override; diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 4bef9c2f7c0d1fa..ab562e70606b672 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -371,3 +371,10 @@ namespace Variadic { constexpr int (*VFP)(...) = variadic_function2; static_assert(VFP() == 12, ""); } + +namespace Packs { + template + constexpr int foo() { return sizeof...(T); } + static_assert(foo() == 2, ""); + static_assert(foo<>() == 0, ""); +} `` https://github.com/llvm/llvm-project/pull/71929 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Handle SizeOfPackExprs (PR #71929)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/71929 None >From 1fe6815c82c1df26f35edcd64e85d4a2fd584f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Fri, 10 Nov 2023 13:04:30 +0100 Subject: [PATCH] [clang][Interp] Handle SizeOfPackExprs --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 5 + clang/lib/AST/Interp/ByteCodeExprGen.h | 1 + clang/test/AST/Interp/functions.cpp | 7 +++ 3 files changed, 13 insertions(+) diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 15a717089660337..c8d3c1243fc1094 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1624,6 +1624,11 @@ bool ByteCodeExprGen::VisitCXXScalarValueInitExpr( return this->visitZeroInitializer(classifyPrim(Ty), Ty, E); } +template +bool ByteCodeExprGen::VisitSizeOfPackExpr(const SizeOfPackExpr *E) { + return this->emitConst(E->getPackLength(), E); +} + template bool ByteCodeExprGen::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 83986d3dd579ed6..ec9b6bb1408453c 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.h +++ b/clang/lib/AST/Interp/ByteCodeExprGen.h @@ -107,6 +107,7 @@ class ByteCodeExprGen : public ConstStmtVisitor, bool>, bool VisitSourceLocExpr(const SourceLocExpr *E); bool VisitOffsetOfExpr(const OffsetOfExpr *E); bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E); + bool VisitSizeOfPackExpr(const SizeOfPackExpr *E); protected: bool visitExpr(const Expr *E) override; diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 4bef9c2f7c0d1fa..ab562e70606b672 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -371,3 +371,10 @@ namespace Variadic { constexpr int (*VFP)(...) = variadic_function2; static_assert(VFP() == 12, ""); } + +namespace Packs { + template + constexpr int foo() { return sizeof...(T); } + static_assert(foo() == 2, ""); + static_assert(foo<>() == 0, ""); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits