aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2024-03-15 17:15:15 +0100
committerTimm Bäder <tbaeder@redhat.com>2024-03-16 12:46:28 +0100
commit8e69052b0e2f3b1bc7dbcf56a0c771e30d2edbf7 (patch)
treec8ed6056cdae801e0fff774feabb521b490e751c
parent367f355fbfe30b1769368c93f30e04b2ecba613e (diff)
downloadllvm-8e69052b0e2f3b1bc7dbcf56a0c771e30d2edbf7.zip
llvm-8e69052b0e2f3b1bc7dbcf56a0c771e30d2edbf7.tar.gz
llvm-8e69052b0e2f3b1bc7dbcf56a0c771e30d2edbf7.tar.bz2
[clang][Interp] Handle ArrayTypeTraitExprs
-rw-r--r--clang/lib/AST/Interp/ByteCodeExprGen.cpp8
-rw-r--r--clang/lib/AST/Interp/ByteCodeExprGen.h1
-rw-r--r--clang/test/AST/Interp/literals.cpp12
3 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index f07e430..2e48ec2 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1756,6 +1756,14 @@ bool ByteCodeExprGen<Emitter>::VisitTypeTraitExpr(const TypeTraitExpr *E) {
}
template <class Emitter>
+bool ByteCodeExprGen<Emitter>::VisitArrayTypeTraitExpr(
+ const ArrayTypeTraitExpr *E) {
+ if (DiscardResult)
+ return true;
+ return this->emitConst(E->getValue(), E);
+}
+
+template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitLambdaExpr(const LambdaExpr *E) {
if (DiscardResult)
return true;
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 969598c..db0d73c 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -99,6 +99,7 @@ public:
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E);
bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
bool VisitTypeTraitExpr(const TypeTraitExpr *E);
+ bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E);
bool VisitLambdaExpr(const LambdaExpr *E);
bool VisitPredefinedExpr(const PredefinedExpr *E);
bool VisitCXXThrowExpr(const CXXThrowExpr *E);
diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp
index 0a9580b..277438d 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -910,6 +910,18 @@ namespace TypeTraits {
struct U {};
static_assert(S3<U>{}.foo(), "");
static_assert(!S3<T>{}.foo(), "");
+
+ typedef int Int;
+ typedef Int IntAr[10];
+ typedef const IntAr ConstIntAr;
+ typedef ConstIntAr ConstIntArAr[4];
+
+ static_assert(__array_rank(IntAr) == 1, "");
+ static_assert(__array_rank(ConstIntArAr) == 2, "");
+
+ static_assert(__array_extent(IntAr, 0) == 10, "");
+ static_assert(__array_extent(ConstIntArAr, 0) == 4, "");
+ static_assert(__array_extent(ConstIntArAr, 1) == 10, "");
}
#if __cplusplus >= 201402L