[clang] [clang][Interp] Handle SizeOfPackExprs (PR #71929)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 10 04:06:39 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
---
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<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, "");
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/71929
More information about the cfe-commits
mailing list