This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][NFCi] Annotate major nonnull returning functions
ClosedPublic

Authored by steakhal on May 23 2022, 5:18 AM.

Details

Summary

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.

Diff Detail

Event Timeline

steakhal created this revision.May 23 2022, 5:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2022, 5:18 AM
steakhal requested review of this revision.May 23 2022, 5:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2022, 5:18 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
steakhal updated this revision to Diff 431343.May 23 2022, 5:20 AM

fix typo migth -> might

martong accepted this revision.May 23 2022, 5:30 AM

Looks good, with minor revisions.

clang/include/clang/Analysis/AnalysisDeclContext.h
233

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

clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
919
1021
1091
This revision is now accepted and ready to land.May 23 2022, 5:30 AM
steakhal added inline comments.May 23 2022, 6:16 AM
clang/include/clang/Analysis/AnalysisDeclContext.h
233

It's totally messed up, there is absolutely no consistency regarding this.

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

steakhal updated this revision to Diff 431379.May 23 2022, 8:03 AM
steakhal marked an inline comment as done.

assert(ctx)

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

uabelho added a subscriber: uabelho.Jun 1 2022, 4:04 AM

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<const CXXBaseSpecifier *>): Assertion `D' failed.

Anyhting known or familiar?

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

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<const CXXBaseSpecifier *>): 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);
}

@steakhal : Thanks for the quick fix!