]> granicus.if.org Git - clang/commitdiff
[clang] Ensure that comment classes are trivially destructible
authorBruno Ricci <riccibrun@gmail.com>
Tue, 27 Aug 2019 11:21:00 +0000 (11:21 +0000)
committerBruno Ricci <riccibrun@gmail.com>
Tue, 27 Aug 2019 11:21:00 +0000 (11:21 +0000)
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

lib/AST/Comment.cpp

index 25339c7901e30b5876b590495dd6e5bd846edbfa..23dc7ba93591e4c8aa81fdb9cd8aa2b78d3f1701 100644 (file)
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/CharInfo.h"
 #include "llvm/Support/ErrorHandling.h"
+#include <type_traits>
 
 namespace clang {
 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 {
   switch (getCommentKind()) {
   case NoCommentKind: return "NoCommentKind";