Parcourir la source

Wdeprecated: BugReporterVisitors are copied for cloning (BugReporterVisitorImpl), make sure such copies are safe

Make the copy/move ctors defaulted in the base class and make the
derived classes final to avoid any intermediate hierarchy slicing if
these types were further derived.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244979 91177308-0d34-0410-b5e6-96231b3b80d8
David Blaikie il y a 10 ans
Parent
commit
f95b352161

+ 17 - 16
include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h

@@ -37,6 +37,9 @@ class PathDiagnosticPiece;
 /// will have to provide your own implementation.)
 /// will have to provide your own implementation.)
 class BugReporterVisitor : public llvm::FoldingSetNode {
 class BugReporterVisitor : public llvm::FoldingSetNode {
 public:
 public:
+  BugReporterVisitor() = default;
+  BugReporterVisitor(const BugReporterVisitor &) = default;
+  BugReporterVisitor(BugReporterVisitor &&) = default;
   virtual ~BugReporterVisitor();
   virtual ~BugReporterVisitor();
 
 
   /// \brief Returns a copy of this BugReporter.
   /// \brief Returns a copy of this BugReporter.
@@ -92,9 +95,8 @@ class BugReporterVisitorImpl : public BugReporterVisitor {
   }
   }
 };
 };
 
 
-class FindLastStoreBRVisitor
-  : public BugReporterVisitorImpl<FindLastStoreBRVisitor>
-{
+class FindLastStoreBRVisitor final
+    : public BugReporterVisitorImpl<FindLastStoreBRVisitor> {
   const MemRegion *R;
   const MemRegion *R;
   SVal V;
   SVal V;
   bool Satisfied;
   bool Satisfied;
@@ -124,9 +126,8 @@ public:
                                  BugReport &BR) override;
                                  BugReport &BR) override;
 };
 };
 
 
-class TrackConstraintBRVisitor
-  : public BugReporterVisitorImpl<TrackConstraintBRVisitor>
-{
+class TrackConstraintBRVisitor final
+    : public BugReporterVisitorImpl<TrackConstraintBRVisitor> {
   DefinedSVal Constraint;
   DefinedSVal Constraint;
   bool Assumption;
   bool Assumption;
   bool IsSatisfied;
   bool IsSatisfied;
@@ -161,8 +162,8 @@ private:
 
 
 /// \class NilReceiverBRVisitor
 /// \class NilReceiverBRVisitor
 /// \brief Prints path notes when a message is sent to a nil receiver.
 /// \brief Prints path notes when a message is sent to a nil receiver.
-class NilReceiverBRVisitor
-  : public BugReporterVisitorImpl<NilReceiverBRVisitor> {
+class NilReceiverBRVisitor final
+    : public BugReporterVisitorImpl<NilReceiverBRVisitor> {
 public:
 public:
 
 
   void Profile(llvm::FoldingSetNodeID &ID) const override {
   void Profile(llvm::FoldingSetNodeID &ID) const override {
@@ -181,7 +182,8 @@ public:
 };
 };
 
 
 /// Visitor that tries to report interesting diagnostics from conditions.
 /// Visitor that tries to report interesting diagnostics from conditions.
-class ConditionBRVisitor : public BugReporterVisitorImpl<ConditionBRVisitor> {
+class ConditionBRVisitor final
+    : public BugReporterVisitorImpl<ConditionBRVisitor> {
 public:
 public:
   void Profile(llvm::FoldingSetNodeID &ID) const override {
   void Profile(llvm::FoldingSetNodeID &ID) const override {
     static int x = 0;
     static int x = 0;
@@ -247,8 +249,8 @@ public:
 /// \brief Suppress reports that might lead to known false positives.
 /// \brief Suppress reports that might lead to known false positives.
 ///
 ///
 /// Currently this suppresses reports based on locations of bugs.
 /// Currently this suppresses reports based on locations of bugs.
-class LikelyFalsePositiveSuppressionBRVisitor
-  : public BugReporterVisitorImpl<LikelyFalsePositiveSuppressionBRVisitor> {
+class LikelyFalsePositiveSuppressionBRVisitor final
+    : public BugReporterVisitorImpl<LikelyFalsePositiveSuppressionBRVisitor> {
 public:
 public:
   static void *getTag() {
   static void *getTag() {
     static int Tag = 0;
     static int Tag = 0;
@@ -276,8 +278,8 @@ public:
 ///
 ///
 /// As a result, BugReporter will not prune the path through the function even
 /// As a result, BugReporter will not prune the path through the function even
 /// if the region's contents are not modified/accessed by the call.
 /// if the region's contents are not modified/accessed by the call.
-class UndefOrNullArgVisitor
-  : public BugReporterVisitorImpl<UndefOrNullArgVisitor> {
+class UndefOrNullArgVisitor final
+    : public BugReporterVisitorImpl<UndefOrNullArgVisitor> {
 
 
   /// The interesting memory region this visitor is tracking.
   /// The interesting memory region this visitor is tracking.
   const MemRegion *R;
   const MemRegion *R;
@@ -297,9 +299,8 @@ public:
                                  BugReport &BR) override;
                                  BugReport &BR) override;
 };
 };
 
 
-class SuppressInlineDefensiveChecksVisitor
-: public BugReporterVisitorImpl<SuppressInlineDefensiveChecksVisitor>
-{
+class SuppressInlineDefensiveChecksVisitor final
+    : public BugReporterVisitorImpl<SuppressInlineDefensiveChecksVisitor> {
   /// The symbolic value for which we are tracking constraints.
   /// The symbolic value for which we are tracking constraints.
   /// This value is constrained to null in the end of path.
   /// This value is constrained to null in the end of path.
   DefinedSVal V;
   DefinedSVal V;

+ 2 - 3
lib/StaticAnalyzer/Checkers/MallocChecker.cpp

@@ -392,7 +392,8 @@ private:
   /// The bug visitor which allows us to print extra diagnostics along the
   /// The bug visitor which allows us to print extra diagnostics along the
   /// BugReport path. For example, showing the allocation site of the leaked
   /// BugReport path. For example, showing the allocation site of the leaked
   /// region.
   /// region.
-  class MallocBugVisitor : public BugReporterVisitorImpl<MallocBugVisitor> {
+  class MallocBugVisitor final
+      : public BugReporterVisitorImpl<MallocBugVisitor> {
   protected:
   protected:
     enum NotificationMode {
     enum NotificationMode {
       Normal,
       Normal,
@@ -414,8 +415,6 @@ private:
     MallocBugVisitor(SymbolRef S, bool isLeak = false)
     MallocBugVisitor(SymbolRef S, bool isLeak = false)
        : Sym(S), Mode(Normal), FailedReallocSymbol(nullptr), IsLeak(isLeak) {}
        : Sym(S), Mode(Normal), FailedReallocSymbol(nullptr), IsLeak(isLeak) {}
 
 
-    ~MallocBugVisitor() override {}
-
     void Profile(llvm::FoldingSetNodeID &ID) const override {
     void Profile(llvm::FoldingSetNodeID &ID) const override {
       static int X = 0;
       static int X = 0;
       ID.AddPointer(&X);
       ID.AddPointer(&X);