[clang] aa0dc1c - [analyzer][NFCi] Mark CallEvent::getOriginExpr virtual, some cleanup

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 6 07:51:54 PST 2020


Author: Balazs Benics
Date: 2020-11-06T16:51:34+01:00
New Revision: aa0dc1c3b8628bed8c8b91a75258d13eefa88dfe

URL: https://github.com/llvm/llvm-project/commit/aa0dc1c3b8628bed8c8b91a75258d13eefa88dfe
DIFF: https://github.com/llvm/llvm-project/commit/aa0dc1c3b8628bed8c8b91a75258d13eefa88dfe.diff

LOG: [analyzer][NFCi] Mark CallEvent::getOriginExpr virtual, some cleanup

Previously we just shadowed the original implementation with a virtual
declaration - which is really bugprone in a long run.

This patch marks `CallEvent::getOriginExpr` virtual to let subclasses
override it's behavior.
At the same time, I checked all virtual functions of this class hierarchy
to make sure we don't suffer from this elsewhere.
Removes redundant declarations of `virtual` if `override` is already present.

In theory, this patch is a functional change, but no tests were broken.
I suspect that there were no meaningful changes in behavior in the
subclasses compared to the shadowed `CallEvent::getOriginExpr`.

That being said, I had a hard time coming up with unit-tests covering this.
Motivation: https://reviews.llvm.org/D74735#2370909

Reviewed By: NoQ

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

Added: 
    

Modified: 
    clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
index a2a98c558a4b..060fff1a7407 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -225,7 +225,7 @@ class CallEvent {
 
   /// Returns the expression whose value will be the result of this call.
   /// May be null.
-  const Expr *getOriginExpr() const {
+  virtual const Expr *getOriginExpr() const {
     return Origin.dyn_cast<const Expr *>();
   }
 
@@ -530,7 +530,7 @@ class SimpleFunctionCall : public AnyFunctionCall {
   }
 
 public:
-  virtual const CallExpr *getOriginExpr() const {
+  const CallExpr *getOriginExpr() const override {
     return cast<CallExpr>(AnyFunctionCall::getOriginExpr());
   }
 
@@ -543,9 +543,7 @@ class SimpleFunctionCall : public AnyFunctionCall {
   }
 
   Kind getKind() const override { return CE_Function; }
-  virtual StringRef getKindAsString() const override {
-    return "SimpleFunctionCall";
-  }
+  StringRef getKindAsString() const override { return "SimpleFunctionCall"; }
 
   static bool classof(const CallEvent *CA) {
     return CA->getKind() == CE_Function;
@@ -570,7 +568,7 @@ class BlockCall : public CallEvent {
          RegionAndSymbolInvalidationTraits *ETraits) const override;
 
 public:
-  virtual const CallExpr *getOriginExpr() const {
+  const CallExpr *getOriginExpr() const override {
     return cast<CallExpr>(CallEvent::getOriginExpr());
   }
 
@@ -653,7 +651,7 @@ class BlockCall : public CallEvent {
   ArrayRef<ParmVarDecl *> parameters() const override;
 
   Kind getKind() const override { return CE_Block; }
-  virtual StringRef getKindAsString() const override { return "BlockCall"; }
+  StringRef getKindAsString() const override { return "BlockCall"; }
 
   static bool classof(const CallEvent *CA) { return CA->getKind() == CE_Block; }
 };
@@ -708,7 +706,7 @@ class CXXMemberCall : public CXXInstanceCall {
   void cloneTo(void *Dest) const override { new (Dest) CXXMemberCall(*this); }
 
 public:
-  virtual const CXXMemberCallExpr *getOriginExpr() const {
+  const CXXMemberCallExpr *getOriginExpr() const override {
     return cast<CXXMemberCallExpr>(CXXInstanceCall::getOriginExpr());
   }
 
@@ -727,7 +725,7 @@ class CXXMemberCall : public CXXInstanceCall {
   RuntimeDefinition getRuntimeDefinition() const override;
 
   Kind getKind() const override { return CE_CXXMember; }
-  virtual StringRef getKindAsString() const override { return "CXXMemberCall"; }
+  StringRef getKindAsString() const override { return "CXXMemberCall"; }
 
   static bool classof(const CallEvent *CA) {
     return CA->getKind() == CE_CXXMember;
@@ -752,7 +750,7 @@ class CXXMemberOperatorCall : public CXXInstanceCall {
   }
 
 public:
-  virtual const CXXOperatorCallExpr *getOriginExpr() const {
+  const CXXOperatorCallExpr *getOriginExpr() const override {
     return cast<CXXOperatorCallExpr>(CXXInstanceCall::getOriginExpr());
   }
 
@@ -767,9 +765,7 @@ class CXXMemberOperatorCall : public CXXInstanceCall {
   const Expr *getCXXThisExpr() const override;
 
   Kind getKind() const override { return CE_CXXMemberOperator; }
-  virtual StringRef getKindAsString() const override {
-    return "CXXMemberOperatorCall";
-  }
+  StringRef getKindAsString() const override { return "CXXMemberOperatorCall"; }
 
   static bool classof(const CallEvent *CA) {
     return CA->getKind() == CE_CXXMemberOperator;
@@ -838,9 +834,7 @@ class CXXDestructorCall : public CXXInstanceCall {
   }
 
   Kind getKind() const override { return CE_CXXDestructor; }
-  virtual StringRef getKindAsString() const override {
-    return "CXXDestructorCall";
-  }
+  StringRef getKindAsString() const override { return "CXXDestructorCall"; }
 
   static bool classof(const CallEvent *CA) {
     return CA->getKind() == CE_CXXDestructor;
@@ -898,7 +892,7 @@ class CXXConstructorCall : public AnyCXXConstructorCall {
   void cloneTo(void *Dest) const override { new (Dest) CXXConstructorCall(*this); }
 
 public:
-  virtual const CXXConstructExpr *getOriginExpr() const {
+  const CXXConstructExpr *getOriginExpr() const override {
     return cast<CXXConstructExpr>(AnyFunctionCall::getOriginExpr());
   }
 
@@ -913,9 +907,7 @@ class CXXConstructorCall : public AnyCXXConstructorCall {
   }
 
   Kind getKind() const override { return CE_CXXConstructor; }
-  virtual StringRef getKindAsString() const override {
-    return "CXXConstructorCall";
-  }
+  StringRef getKindAsString() const override { return "CXXConstructorCall"; }
 
   static bool classof(const CallEvent *CA) {
     return CA->getKind() == CE_CXXConstructor;
@@ -959,7 +951,7 @@ class CXXInheritedConstructorCall : public AnyCXXConstructorCall {
   }
 
 public:
-  virtual const CXXInheritedCtorInitExpr *getOriginExpr() const {
+  const CXXInheritedCtorInitExpr *getOriginExpr() const override {
     return cast<CXXInheritedCtorInitExpr>(AnyFunctionCall::getOriginExpr());
   }
 
@@ -986,14 +978,14 @@ class CXXInheritedConstructorCall : public AnyCXXConstructorCall {
     return getInheritingConstructor()->getArg(Index);
   }
 
-  virtual SVal getArgSVal(unsigned Index) const override {
+  SVal getArgSVal(unsigned Index) const override {
     return getState()->getSVal(
         getArgExpr(Index),
         getInheritingStackFrame()->getParent()->getStackFrame());
   }
 
   Kind getKind() const override { return CE_CXXInheritedConstructor; }
-  virtual StringRef getKindAsString() const override {
+  StringRef getKindAsString() const override {
     return "CXXInheritedConstructorCall";
   }
 
@@ -1017,7 +1009,7 @@ class CXXAllocatorCall : public AnyFunctionCall {
   void cloneTo(void *Dest) const override { new (Dest) CXXAllocatorCall(*this); }
 
 public:
-  virtual const CXXNewExpr *getOriginExpr() const {
+  const CXXNewExpr *getOriginExpr() const override {
     return cast<CXXNewExpr>(AnyFunctionCall::getOriginExpr());
   }
 
@@ -1058,9 +1050,7 @@ class CXXAllocatorCall : public AnyFunctionCall {
   }
 
   Kind getKind() const override { return CE_CXXAllocator; }
-  virtual StringRef getKindAsString() const override {
-    return "CXXAllocatorCall";
-  }
+  StringRef getKindAsString() const override { return "CXXAllocatorCall"; }
 
   static bool classof(const CallEvent *CE) {
     return CE->getKind() == CE_CXXAllocator;
@@ -1091,7 +1081,7 @@ class CXXDeallocatorCall : public AnyFunctionCall {
   }
 
 public:
-  virtual const CXXDeleteExpr *getOriginExpr() const {
+  const CXXDeleteExpr *getOriginExpr() const override {
     return cast<CXXDeleteExpr>(AnyFunctionCall::getOriginExpr());
   }
 
@@ -1107,9 +1097,7 @@ class CXXDeallocatorCall : public AnyFunctionCall {
   }
 
   Kind getKind() const override { return CE_CXXDeallocator; }
-  virtual StringRef getKindAsString() const override {
-    return "CXXDeallocatorCall";
-  }
+  StringRef getKindAsString() const override { return "CXXDeallocatorCall"; }
 
   static bool classof(const CallEvent *CE) {
     return CE->getKind() == CE_CXXDeallocator;
@@ -1153,7 +1141,7 @@ class ObjCMethodCall : public CallEvent {
                                         Selector Sel) const;
 
 public:
-  virtual const ObjCMessageExpr *getOriginExpr() const {
+  const ObjCMessageExpr *getOriginExpr() const override {
     return cast<ObjCMessageExpr>(CallEvent::getOriginExpr());
   }
 
@@ -1230,9 +1218,7 @@ class ObjCMethodCall : public CallEvent {
   ArrayRef<ParmVarDecl*> parameters() const override;
 
   Kind getKind() const override { return CE_ObjCMessage; }
-  virtual StringRef getKindAsString() const override {
-    return "ObjCMethodCall";
-  }
+  StringRef getKindAsString() const override { return "ObjCMethodCall"; }
 
   static bool classof(const CallEvent *CA) {
     return CA->getKind() == CE_ObjCMessage;


        


More information about the cfe-commits mailing list