[PATCH] D126198: [analyzer][NFCi] Annotate major nonnull returning functions

2022-06-01 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

@steakhal : Thanks for the quick fix!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126198/new/

https://reviews.llvm.org/D126198

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126198: [analyzer][NFCi] Annotate major nonnull returning functions

2022-06-01 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

In D126198#3549790 , @uabelho wrote:

> Hi,
>
> I see crashes like this with this patch:
>
>   clang: 
> ../../clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h:94:
>  clang::ento::PointerToMemberData::PointerToMemberData(const clang::NamedDecl 
> *, llvm::ImmutableList): Assertion `D' failed.
>
> Anyhting known or familiar?
>
> Unfortunately I don't have any reproducer to share (yet).

Reproducer:

  clang -cc1 -analyze -analyzer-checker=core bbi-70461.C

on bbi-70461.C being

  class B{
  };
  
  class D: public B{
  };
  
  int f(int D::* pd);
  
  int test(void)
  {
int B::* pb = 0;
  
return f(pb);
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126198/new/

https://reviews.llvm.org/D126198

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126198: [analyzer][NFCi] Annotate major nonnull returning functions

2022-06-01 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

Hi,

I see crashes like this with this patch:

  clang: 
../../clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h:94:
 clang::ento::PointerToMemberData::PointerToMemberData(const clang::NamedDecl 
*, llvm::ImmutableList): Assertion `D' failed.

Anyhting known or familiar?

Unfortunately I don't have any reproducer to share (yet).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126198/new/

https://reviews.llvm.org/D126198

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126198: [analyzer][NFCi] Annotate major nonnull returning functions

2022-05-27 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

A sanitizer buildbot caught a wrong annotation, fixed by 
e651ed8621c3719937517ddb0b0815b18ec888e4 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126198/new/

https://reviews.llvm.org/D126198

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126198: [analyzer][NFCi] Annotate major nonnull returning functions

2022-05-27 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf13050eca356: [analyzer][NFCi] Annotate major nonnull 
returning functions (authored by steakhal).

Changed prior to commit:
  https://reviews.llvm.org/D126198?vs=431379=432498#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126198/new/

https://reviews.llvm.org/D126198

Files:
  clang/include/clang/Analysis/AnalysisDeclContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp

Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -162,7 +162,9 @@
 }
 
 ObjCIvarRegion::ObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *sReg)
-: DeclRegion(sReg, ObjCIvarRegionKind), IVD(ivd) {}
+: DeclRegion(sReg, ObjCIvarRegionKind), IVD(ivd) {
+  assert(IVD);
+}
 
 const ObjCIvarDecl *ObjCIvarRegion::getDecl() const { return IVD; }
 
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -48,6 +48,7 @@
 assert(isValidTypeForSymbol(r->getValueType()));
   }
 
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   const TypedValueRegion* getRegion() const { return R; }
 
   static void Profile(llvm::FoldingSetNodeID& profile, const TypedValueRegion* R) {
@@ -95,8 +96,10 @@
 assert(isValidTypeForSymbol(t));
   }
 
+  /// It might return null.
   const Stmt *getStmt() const { return S; }
   unsigned getCount() const { return Count; }
+  /// It might return null.
   const void *getTag() const { return SymbolTag; }
 
   QualType getType() const override;
@@ -140,7 +143,9 @@
 assert(isValidTypeForSymbol(r->getValueType()));
   }
 
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   SymbolRef getParentSymbol() const { return parentSymbol; }
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   const TypedValueRegion *getRegion() const { return R; }
 
   QualType getType() const override;
@@ -179,6 +184,7 @@
 assert(r);
   }
 
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   const SubRegion *getRegion() const { return R; }
 
   QualType getType() const override;
@@ -226,29 +232,37 @@
   assert(tag);
 }
 
-  const MemRegion *getRegion() const { return R; }
-  const Stmt *getStmt() const { return S; }
-  const LocationContext *getLocationContext() const { return LCtx; }
-  unsigned getCount() const { return Count; }
-  const void *getTag() const { return Tag; }
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const MemRegion *getRegion() const { return R; }
 
-  QualType getType() const override;
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const Stmt *getStmt() const { return S; }
 
-  StringRef getKindStr() const override;
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const LocationContext *getLocationContext() const { return LCtx; }
 
-  void dumpToStream(raw_ostream ) const override;
+unsigned getCount() const { return Count; }
 
-  static void Profile(llvm::FoldingSetNodeID& profile, const MemRegion *R,
-  const Stmt *S, QualType T, const LocationContext *LCtx,
-  unsigned Count, const void *Tag) {
-profile.AddInteger((unsigned) SymbolMetadataKind);
-profile.AddPointer(R);
-profile.AddPointer(S);
-profile.Add(T);
-profile.AddPointer(LCtx);
-profile.AddInteger(Count);
-profile.AddPointer(Tag);
-  }
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const void *getTag() const { return Tag; }
+
+QualType getType() const override;
+
+StringRef getKindStr() const override;
+
+void dumpToStream(raw_ostream ) const override;
+
+static void Profile(llvm::FoldingSetNodeID , const MemRegion *R,
+const Stmt *S, QualType T, const LocationContext *LCtx,
+unsigned Count, const void *Tag) {
+  profile.AddInteger((unsigned)SymbolMetadataKind);
+  profile.AddPointer(R);
+  profile.AddPointer(S);
+  profile.Add(T);
+  profile.AddPointer(LCtx);
+  profile.AddInteger(Count);
+  profile.AddPointer(Tag);
+}
 
   void Profile(llvm::FoldingSetNodeID& profile) override {
 

[PATCH] D126198: [analyzer][NFCi] Annotate major nonnull returning functions

2022-05-23 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 431379.
steakhal marked an inline comment as done.
steakhal added a comment.

`assert(ctx)`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126198/new/

https://reviews.llvm.org/D126198

Files:
  clang/include/clang/Analysis/AnalysisDeclContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp

Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -162,7 +162,9 @@
 }
 
 ObjCIvarRegion::ObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *sReg)
-: DeclRegion(sReg, ObjCIvarRegionKind), IVD(ivd) {}
+: DeclRegion(sReg, ObjCIvarRegionKind), IVD(ivd) {
+  assert(IVD);
+}
 
 const ObjCIvarDecl *ObjCIvarRegion::getDecl() const { return IVD; }
 
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -48,6 +48,7 @@
 assert(isValidTypeForSymbol(r->getValueType()));
   }
 
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   const TypedValueRegion* getRegion() const { return R; }
 
   static void Profile(llvm::FoldingSetNodeID& profile, const TypedValueRegion* R) {
@@ -95,8 +96,10 @@
 assert(isValidTypeForSymbol(t));
   }
 
+  /// It might return null.
   const Stmt *getStmt() const { return S; }
   unsigned getCount() const { return Count; }
+  /// It might return null.
   const void *getTag() const { return SymbolTag; }
 
   QualType getType() const override;
@@ -140,7 +143,9 @@
 assert(isValidTypeForSymbol(r->getValueType()));
   }
 
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   SymbolRef getParentSymbol() const { return parentSymbol; }
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   const TypedValueRegion *getRegion() const { return R; }
 
   QualType getType() const override;
@@ -179,6 +184,7 @@
 assert(r);
   }
 
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   const SubRegion *getRegion() const { return R; }
 
   QualType getType() const override;
@@ -226,29 +232,37 @@
   assert(tag);
 }
 
-  const MemRegion *getRegion() const { return R; }
-  const Stmt *getStmt() const { return S; }
-  const LocationContext *getLocationContext() const { return LCtx; }
-  unsigned getCount() const { return Count; }
-  const void *getTag() const { return Tag; }
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const MemRegion *getRegion() const { return R; }
 
-  QualType getType() const override;
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const Stmt *getStmt() const { return S; }
 
-  StringRef getKindStr() const override;
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const LocationContext *getLocationContext() const { return LCtx; }
 
-  void dumpToStream(raw_ostream ) const override;
+unsigned getCount() const { return Count; }
 
-  static void Profile(llvm::FoldingSetNodeID& profile, const MemRegion *R,
-  const Stmt *S, QualType T, const LocationContext *LCtx,
-  unsigned Count, const void *Tag) {
-profile.AddInteger((unsigned) SymbolMetadataKind);
-profile.AddPointer(R);
-profile.AddPointer(S);
-profile.Add(T);
-profile.AddPointer(LCtx);
-profile.AddInteger(Count);
-profile.AddPointer(Tag);
-  }
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const void *getTag() const { return Tag; }
+
+QualType getType() const override;
+
+StringRef getKindStr() const override;
+
+void dumpToStream(raw_ostream ) const override;
+
+static void Profile(llvm::FoldingSetNodeID , const MemRegion *R,
+const Stmt *S, QualType T, const LocationContext *LCtx,
+unsigned Count, const void *Tag) {
+  profile.AddInteger((unsigned)SymbolMetadataKind);
+  profile.AddPointer(R);
+  profile.AddPointer(S);
+  profile.Add(T);
+  profile.AddPointer(LCtx);
+  profile.AddInteger(Count);
+  profile.AddPointer(Tag);
+}
 
   void Profile(llvm::FoldingSetNodeID& profile) override {
 Profile(profile, R, S, T, LCtx, Count, Tag);
@@ -287,6 +301,7 @@
 
   QualType getType() const override { return ToTy; }
 
+  

[PATCH] D126198: [analyzer][NFCi] Annotate major nonnull returning functions

2022-05-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

I prefer references to annotations, but this is also a step in the right 
direction :l


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126198/new/

https://reviews.llvm.org/D126198

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126198: [analyzer][NFCi] Annotate major nonnull returning functions

2022-05-23 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/include/clang/Analysis/AnalysisDeclContext.h:233
+  : Kind(k), Ctx(ctx), Parent(parent), ID(ID) {
+assert(Ctx);
+  }

martong wrote:
> To be consistent with the other hunks, where you assert on the parameter, not 
> on the member.
It's totally messed up, there is absolutely no consistency regarding this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126198/new/

https://reviews.llvm.org/D126198

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126198: [analyzer][NFCi] Annotate major nonnull returning functions

2022-05-23 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

Looks good, with minor revisions.




Comment at: clang/include/clang/Analysis/AnalysisDeclContext.h:233
+  : Kind(k), Ctx(ctx), Parent(parent), ID(ID) {
+assert(Ctx);
+  }

To be consistent with the other hunks, where you assert on the parameter, not 
on the member.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h:919
 public:
+  // TODO what does this return?
   virtual const ValueDecl *getDecl() const = 0;





Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h:1021
 assert(!cast(SReg)->getStackFrame()->inTopFrame());
+assert(OriginExpr);
   }





Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h:1091
+  : DeclRegion(sReg, FieldRegionKind), FD(fd) {
+assert(FD);
+  }




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126198/new/

https://reviews.llvm.org/D126198

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126198: [analyzer][NFCi] Annotate major nonnull returning functions

2022-05-23 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 431343.
steakhal added a comment.

fix typo `migth` -> `might`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126198/new/

https://reviews.llvm.org/D126198

Files:
  clang/include/clang/Analysis/AnalysisDeclContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp

Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -162,7 +162,9 @@
 }
 
 ObjCIvarRegion::ObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *sReg)
-: DeclRegion(sReg, ObjCIvarRegionKind), IVD(ivd) {}
+: DeclRegion(sReg, ObjCIvarRegionKind), IVD(ivd) {
+  assert(IVD);
+}
 
 const ObjCIvarDecl *ObjCIvarRegion::getDecl() const { return IVD; }
 
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -48,6 +48,7 @@
 assert(isValidTypeForSymbol(r->getValueType()));
   }
 
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   const TypedValueRegion* getRegion() const { return R; }
 
   static void Profile(llvm::FoldingSetNodeID& profile, const TypedValueRegion* R) {
@@ -95,8 +96,10 @@
 assert(isValidTypeForSymbol(t));
   }
 
+  /// It might return null.
   const Stmt *getStmt() const { return S; }
   unsigned getCount() const { return Count; }
+  /// It might return null.
   const void *getTag() const { return SymbolTag; }
 
   QualType getType() const override;
@@ -140,7 +143,9 @@
 assert(isValidTypeForSymbol(r->getValueType()));
   }
 
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   SymbolRef getParentSymbol() const { return parentSymbol; }
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   const TypedValueRegion *getRegion() const { return R; }
 
   QualType getType() const override;
@@ -179,6 +184,7 @@
 assert(r);
   }
 
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   const SubRegion *getRegion() const { return R; }
 
   QualType getType() const override;
@@ -226,29 +232,37 @@
   assert(tag);
 }
 
-  const MemRegion *getRegion() const { return R; }
-  const Stmt *getStmt() const { return S; }
-  const LocationContext *getLocationContext() const { return LCtx; }
-  unsigned getCount() const { return Count; }
-  const void *getTag() const { return Tag; }
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const MemRegion *getRegion() const { return R; }
 
-  QualType getType() const override;
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const Stmt *getStmt() const { return S; }
 
-  StringRef getKindStr() const override;
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const LocationContext *getLocationContext() const { return LCtx; }
 
-  void dumpToStream(raw_ostream ) const override;
+unsigned getCount() const { return Count; }
 
-  static void Profile(llvm::FoldingSetNodeID& profile, const MemRegion *R,
-  const Stmt *S, QualType T, const LocationContext *LCtx,
-  unsigned Count, const void *Tag) {
-profile.AddInteger((unsigned) SymbolMetadataKind);
-profile.AddPointer(R);
-profile.AddPointer(S);
-profile.Add(T);
-profile.AddPointer(LCtx);
-profile.AddInteger(Count);
-profile.AddPointer(Tag);
-  }
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const void *getTag() const { return Tag; }
+
+QualType getType() const override;
+
+StringRef getKindStr() const override;
+
+void dumpToStream(raw_ostream ) const override;
+
+static void Profile(llvm::FoldingSetNodeID , const MemRegion *R,
+const Stmt *S, QualType T, const LocationContext *LCtx,
+unsigned Count, const void *Tag) {
+  profile.AddInteger((unsigned)SymbolMetadataKind);
+  profile.AddPointer(R);
+  profile.AddPointer(S);
+  profile.Add(T);
+  profile.AddPointer(LCtx);
+  profile.AddInteger(Count);
+  profile.AddPointer(Tag);
+}
 
   void Profile(llvm::FoldingSetNodeID& profile) override {
 Profile(profile, R, S, T, LCtx, Count, Tag);
@@ -287,6 +301,7 @@
 
   QualType getType() const override { return ToTy; }
 
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   const 

[PATCH] D126198: [analyzer][NFCi] Annotate major nonnull returning functions

2022-05-23 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: NoQ, martong, Szelethus.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch annotates the most important analyzer function APIs.
Also adds a couple of assertions for uncovering any potential issues earlier in 
the constructor; in those cases, the member functions were already 
dereferencing the members unconditionally anyway.

Measurements showed no performance impact, nor crashes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126198

Files:
  clang/include/clang/Analysis/AnalysisDeclContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp

Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -162,7 +162,9 @@
 }
 
 ObjCIvarRegion::ObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *sReg)
-: DeclRegion(sReg, ObjCIvarRegionKind), IVD(ivd) {}
+: DeclRegion(sReg, ObjCIvarRegionKind), IVD(ivd) {
+  assert(IVD);
+}
 
 const ObjCIvarDecl *ObjCIvarRegion::getDecl() const { return IVD; }
 
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -48,6 +48,7 @@
 assert(isValidTypeForSymbol(r->getValueType()));
   }
 
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   const TypedValueRegion* getRegion() const { return R; }
 
   static void Profile(llvm::FoldingSetNodeID& profile, const TypedValueRegion* R) {
@@ -95,8 +96,10 @@
 assert(isValidTypeForSymbol(t));
   }
 
+  /// It might return null.
   const Stmt *getStmt() const { return S; }
   unsigned getCount() const { return Count; }
+  /// It might return null.
   const void *getTag() const { return SymbolTag; }
 
   QualType getType() const override;
@@ -140,7 +143,9 @@
 assert(isValidTypeForSymbol(r->getValueType()));
   }
 
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   SymbolRef getParentSymbol() const { return parentSymbol; }
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   const TypedValueRegion *getRegion() const { return R; }
 
   QualType getType() const override;
@@ -179,6 +184,7 @@
 assert(r);
   }
 
+  LLVM_ATTRIBUTE_RETURNS_NONNULL
   const SubRegion *getRegion() const { return R; }
 
   QualType getType() const override;
@@ -226,29 +232,37 @@
   assert(tag);
 }
 
-  const MemRegion *getRegion() const { return R; }
-  const Stmt *getStmt() const { return S; }
-  const LocationContext *getLocationContext() const { return LCtx; }
-  unsigned getCount() const { return Count; }
-  const void *getTag() const { return Tag; }
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const MemRegion *getRegion() const { return R; }
 
-  QualType getType() const override;
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const Stmt *getStmt() const { return S; }
 
-  StringRef getKindStr() const override;
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const LocationContext *getLocationContext() const { return LCtx; }
 
-  void dumpToStream(raw_ostream ) const override;
+unsigned getCount() const { return Count; }
 
-  static void Profile(llvm::FoldingSetNodeID& profile, const MemRegion *R,
-  const Stmt *S, QualType T, const LocationContext *LCtx,
-  unsigned Count, const void *Tag) {
-profile.AddInteger((unsigned) SymbolMetadataKind);
-profile.AddPointer(R);
-profile.AddPointer(S);
-profile.Add(T);
-profile.AddPointer(LCtx);
-profile.AddInteger(Count);
-profile.AddPointer(Tag);
-  }
+LLVM_ATTRIBUTE_RETURNS_NONNULL
+const void *getTag() const { return Tag; }
+
+QualType getType() const override;
+
+StringRef getKindStr() const override;
+
+void dumpToStream(raw_ostream ) const override;
+
+static void Profile(llvm::FoldingSetNodeID , const MemRegion *R,
+const Stmt *S, QualType T, const LocationContext *LCtx,
+