From 48d573c2e13904741c9505d513bf5156eab512b8 Mon Sep 17 00:00:00 2001 From: Bruno Ricci Date: Tue, 27 Aug 2019 11:35:49 +0000 Subject: [PATCH] [clang] Ensure that statements, expressions and types are trivially destructible Since statements, expressions and types are allocated with the BumpPtrAllocator from ASTContext their destructor is not executed. Two classes are currently exempted from the check : InitListExpr due to its ASTVector and ConstantArrayType due to its APInt. No functional changes. Differential Revision: https://reviews.llvm.org/D66646 Reviewed By: lebedev.ri, gribozavr git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370044 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Stmt.cpp | 11 +++++++++++ lib/AST/Type.cpp | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 0a4d403106..80a1451ac7 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -41,6 +41,7 @@ #include #include #include +#include using namespace clang; @@ -83,6 +84,16 @@ const char *Stmt::getStmtClassName() const { #CLASS " should not be polymorphic!"); #include "clang/AST/StmtNodes.inc" +// Check that no statement / expression class has a non-trival destructor. +// Statements and expressions are allocated with the BumpPtrAllocator from +// ASTContext and therefore their destructor is not executed. +#define STMT(CLASS, PARENT) \ + static_assert(std::is_trivially_destructible::value, \ + #CLASS " should be trivially destructible!"); +// FIXME: InitListExpr is not trivially destructible due to its ASTVector. +#define INITLISTEXPR(CLASS, PARENT) +#include "clang/AST/StmtNodes.inc" + void Stmt::PrintStats() { // Ensure the table is primed. getStmtInfoTableEntry(Stmt::NullStmtClass); diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 7e08e72f4e..608626820a 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -50,6 +50,7 @@ #include #include #include +#include using namespace clang; @@ -299,6 +300,18 @@ QualType QualType::getSingleStepDesugaredTypeImpl(QualType type, #CLASS "Type should not be polymorphic!"); #include "clang/AST/TypeNodes.def" +// Check that no type class has a non-trival destructor. Types are +// allocated with the BumpPtrAllocator from ASTContext and therefore +// their destructor is not executed. +// +// FIXME: ConstantArrayType is not trivially destructible because of its +// APInt member. It should be replaced in favor of ASTContext allocation. +#define TYPE(CLASS, BASE) \ + static_assert(std::is_trivially_destructible::value || \ + std::is_same::value, \ + #CLASS "Type should be trivially destructible!"); +#include "clang/AST/TypeNodes.def" + QualType Type::getLocallyUnqualifiedSingleStepDesugaredType() const { switch (getTypeClass()) { #define ABSTRACT_TYPE(Class, Parent) -- 2.40.0