From 797fabaab2a5e02d00de4755ef8f5a38127110df Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Wed, 18 May 2022 17:03:03 -0500 Subject: [PATCH] [Analysis] Avoid virtual dtor. NFC. Replace virtual destructor by a protected non-virtual one. Additionally also making derived structs as virtual avoids the warning from reappearing. Also see the mailing list discussion: https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20220516/1038290.html Reviewed By: dblaikie, YangKeao Differential Revision: https://reviews.llvm.org/D125830 --- llvm/include/llvm/Analysis/DOTGraphTraitsPass.h | 26 ++++++++++++++++++++++-- llvm/include/llvm/Analysis/DomPrinter.h | 27 ++++++++++++------------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h index 30216c8..c35e189 100644 --- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h +++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h @@ -44,7 +44,6 @@ struct DOTGraphTraitsViewer : PassInfoMixin> { DOTGraphTraitsViewer(StringRef GraphName) : Name(GraphName) {} - virtual ~DOTGraphTraitsViewer() {} /// Return true if this function should be processed. /// @@ -68,6 +67,18 @@ struct DOTGraphTraitsViewer return PreservedAnalyses::all(); }; +protected: + /// Avoid compiler warning "has virtual functions but non-virtual destructor + /// [-Wnon-virtual-dtor]" in derived classes. + /// + /// DOTGraphTraitsViewer is also used as a mixin for avoiding repeated + /// implementation of viewer passes, ie there should be no + /// runtime-polymorphisms/downcasting involving this class and hence no + /// virtual destructor needed. Making this dtor protected stops accidental + /// invocation when the derived class destructor should have been called. + /// Those derived classes sould be marked final to avoid the warning. + ~DOTGraphTraitsViewer() {} + private: StringRef Name; }; @@ -99,7 +110,6 @@ struct DOTGraphTraitsPrinter : PassInfoMixin> { DOTGraphTraitsPrinter(StringRef GraphName) : Name(GraphName) {} - virtual ~DOTGraphTraitsPrinter() {} /// Return true if this function should be processed. /// @@ -124,6 +134,18 @@ struct DOTGraphTraitsPrinter return PreservedAnalyses::all(); }; +protected: + /// Avoid compiler warning "has virtual functions but non-virtual destructor + /// [-Wnon-virtual-dtor]" in derived classes. + /// + /// DOTGraphTraitsPrinter is also used as a mixin for avoiding repeated + /// implementation of printer passes, ie there should be no + /// runtime-polymorphisms/downcasting involving this class and hence no + /// virtual destructor needed. Making this dtor protected stops accidental + /// invocation when the derived class destructor should have been called. + /// Those derived classes sould be marked final to avoid the warning. + ~DOTGraphTraitsPrinter() {} + private: StringRef Name; }; diff --git a/llvm/include/llvm/Analysis/DomPrinter.h b/llvm/include/llvm/Analysis/DomPrinter.h index 5ba717f..83fe721 100644 --- a/llvm/include/llvm/Analysis/DomPrinter.h +++ b/llvm/include/llvm/Analysis/DomPrinter.h @@ -74,46 +74,45 @@ struct DOTGraphTraits } }; -struct DomViewer : public DOTGraphTraitsViewer { +struct DomViewer final : DOTGraphTraitsViewer { DomViewer() : DOTGraphTraitsViewer("dom") {} }; -struct DomOnlyViewer - : public DOTGraphTraitsViewer { +struct DomOnlyViewer final : DOTGraphTraitsViewer { DomOnlyViewer() : DOTGraphTraitsViewer("domonly") {} }; -struct PostDomViewer - : public DOTGraphTraitsViewer { +struct PostDomViewer final + : DOTGraphTraitsViewer { PostDomViewer() : DOTGraphTraitsViewer("postdom") {} }; -struct PostDomOnlyViewer - : public DOTGraphTraitsViewer { +struct PostDomOnlyViewer final + : DOTGraphTraitsViewer { PostDomOnlyViewer() : DOTGraphTraitsViewer("postdomonly") {} }; -struct DomPrinter : public DOTGraphTraitsPrinter { +struct DomPrinter final : DOTGraphTraitsPrinter { DomPrinter() : DOTGraphTraitsPrinter("dom") {} }; -struct DomOnlyPrinter - : public DOTGraphTraitsPrinter { +struct DomOnlyPrinter final + : DOTGraphTraitsPrinter { DomOnlyPrinter() : DOTGraphTraitsPrinter("domonly") {} }; -struct PostDomPrinter - : public DOTGraphTraitsPrinter { +struct PostDomPrinter final + : DOTGraphTraitsPrinter { PostDomPrinter() : DOTGraphTraitsPrinter("postdom") {} }; -struct PostDomOnlyPrinter - : public DOTGraphTraitsPrinter { +struct PostDomOnlyPrinter final + : DOTGraphTraitsPrinter { PostDomOnlyPrinter() : DOTGraphTraitsPrinter("postdomonly") {} }; -- 2.7.4