Browse Source

[clang] Ensure that comment classes are trivially destructible

As in D66646, these classes are also allocated with a BumpPtrAllocator,
and therefore should be trivially destructible.

Differential Revision: https://reviews.llvm.org/D66722

Reviewed By: Mordante, gribozavr

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370041 91177308-0d34-0410-b5e6-96231b3b80d8
Bruno Ricci 6 years ago
parent
commit
ea608fd0e4
1 changed files with 15 additions and 0 deletions
  1. 15 0
      lib/AST/Comment.cpp

+ 15 - 0
lib/AST/Comment.cpp

@@ -13,10 +13,25 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/CharInfo.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ErrorHandling.h"
+#include <type_traits>
 
 
 namespace clang {
 namespace clang {
 namespace comments {
 namespace comments {
 
 
+// Check that no comment class has a non-trival destructor. They are allocated
+// with a BumpPtrAllocator and therefore their destructor is not executed.
+#define ABSTRACT_COMMENT(COMMENT)
+#define COMMENT(CLASS, PARENT)                                                 \
+  static_assert(std::is_trivially_destructible<CLASS>::value,                  \
+                #CLASS " should be trivially destructible!");
+#include "clang/AST/CommentNodes.inc"
+#undef COMMENT
+#undef ABSTRACT_COMMENT
+
+// DeclInfo is also allocated with a BumpPtrAllocator.
+static_assert(std::is_trivially_destructible<DeclInfo>::value,
+              "DeclInfo should be trivially destructible!");
+
 const char *Comment::getCommentKindName() const {
 const char *Comment::getCommentKindName() const {
   switch (getCommentKind()) {
   switch (getCommentKind()) {
   case NoCommentKind: return "NoCommentKind";
   case NoCommentKind: return "NoCommentKind";