From 8d2899acbcf1b8ce120bc219aeb30207d4422042 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Tue, 24 Jan 2023 12:11:45 +0100 Subject: [PATCH] [clang][Interp] Handle TypeTraitExprs Differential Revision: https://reviews.llvm.org/D142448 --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 5 +++++ clang/lib/AST/Interp/ByteCodeExprGen.h | 1 + clang/test/AST/Interp/literals.cpp | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 1b605a9..7332477 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -897,6 +897,11 @@ bool ByteCodeExprGen::VisitCompoundLiteralExpr( return false; } +template +bool ByteCodeExprGen::VisitTypeTraitExpr(const TypeTraitExpr *E) { + return this->emitConstBool(E->getValue(), 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 03d2eb8..4baf5d4 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.h +++ b/clang/lib/AST/Interp/ByteCodeExprGen.h @@ -92,6 +92,7 @@ public: bool VisitExprWithCleanups(const ExprWithCleanups *E); bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E); bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E); + bool VisitTypeTraitExpr(const TypeTraitExpr *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 fc36c13..5883c18 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -743,3 +743,26 @@ namespace CompoundLiterals { static_assert(get3() == 3, ""); #endif }; + +namespace TypeTraits { + static_assert(__is_trivial(int), ""); + static_assert(__is_trivial(float), ""); + static_assert(__is_trivial(E), ""); + struct S{}; + static_assert(__is_trivial(S), ""); + struct S2 { + S2() {} + }; + static_assert(!__is_trivial(S2), ""); + + template + struct S3 { + constexpr bool foo() const { return __is_trivial(T); } + }; + struct T { + ~T() {} + }; + struct U {}; + static_assert(S3{}.foo(), ""); + static_assert(!S3{}.foo(), ""); +} -- 2.7.4