[clang] 190b917 - [clang][Interp] Handle SizeOfPackExprs (#71929)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 11 20:34:20 PST 2023
Author: Timm Baeder
Date: 2023-11-12T05:34:16+01:00
New Revision: 190b9179a5def1db3483617286d5a8f4a8dde1f3
URL: https://github.com/llvm/llvm-project/commit/190b9179a5def1db3483617286d5a8f4a8dde1f3
DIFF: https://github.com/llvm/llvm-project/commit/190b9179a5def1db3483617286d5a8f4a8dde1f3.diff
LOG: [clang][Interp] Handle SizeOfPackExprs (#71929)
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/AST/Interp/functions.cpp
Removed:
################################################################################
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<Emitter>::VisitCXXScalarValueInitExpr(
return this->visitZeroInitializer(classifyPrim(Ty), Ty, E);
}
+template <class Emitter>
+bool ByteCodeExprGen<Emitter>::VisitSizeOfPackExpr(const SizeOfPackExpr *E) {
+ return this->emitConst(E->getPackLength(), 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 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<ByteCodeExprGen<Emitter>, 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<typename...T>
+ constexpr int foo() { return sizeof...(T); }
+ static_assert(foo<int, char>() == 2, "");
+ static_assert(foo<>() == 0, "");
+}
More information about the cfe-commits
mailing list