This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Add CheckerManager::getChecker, make sure that a registry function registers no more than 1 checker
ClosedPublic

Authored by Szelethus on Dec 7 2018, 5:44 AM.

Diff Detail

Event Timeline

Szelethus created this revision.Dec 7 2018, 5:44 AM
Szelethus updated this revision to Diff 177245.Dec 7 2018, 10:13 AM
Szelethus retitled this revision from [analyzer] Add CheckerManager::getChecker that asserts on non-registered checkers, assert on registering already registered checkers to [analyzer] Add CheckerManager::getChecker, make sure that a registry function registers no more than 1 checker.

Actually, ensuring that a registry function registers no more than one checker can be pulled off very easily -- the change required is so little, I added it to this patch. With that, the checker name bug is "officially" fixed.

Szelethus edited the summary of this revision. (Show Details)Dec 7 2018, 10:13 AM
NoQ accepted this revision.Dec 7 2018, 2:42 PM

Aha, ok, so what's the final procedure now to register a checker that's artificially split in two? Something like this, right?

def CommonModel : Checker<"Common">,
  HelpText<"Doesn't emit warnings but models common stuff.">;

def SubChecker : Checker<"Sub">,
  HelpText<"Emits common warnings for the sub-stuff.">,
  Dependencies<[CommonModel]>;
void registerCommonModel(CheckerManager &Mgr) {
  Mgr.registerChecker<CommonModel>();
}

void registerSubChecker(CheckerManager &Mgr) {
  CommonModel *Model = Mgr.getChecker<CommonModel>();
  Model->EnableSubChecker = true;
}

This looks quite usable to me.

test/Analysis/free.c
1

When cleaning this stuff up, please feel free to drop -analyzer-store=region entirely (same for other options that allow only one value).

This revision is now accepted and ready to land.Dec 7 2018, 2:42 PM
Szelethus added a comment.EditedDec 7 2018, 3:14 PM
In D55429#1324035, @NoQ wrote:

Aha, ok, so what's the final procedure now to register a checker that's artificially split in two? Something like this, right?

def CommonModel : Checker<"Common">,
  HelpText<"Doesn't emit warnings but models common stuff.">;

def SubChecker : Checker<"Sub">,
  HelpText<"Emits common warnings for the sub-stuff.">,
  Dependencies<[CommonModel]>;
void registerCommonModel(CheckerManager &Mgr) {
  Mgr.registerChecker<CommonModel>();
}

void registerSubChecker(CheckerManager &Mgr) {
  CommonModel *Model = Mgr.getChecker<CommonModel>();
  Model->EnableSubChecker = true;
}

This looks quite usable to me.

Correct! But since I spent so much time with these files, and I don't expect maaajor changes to them in the foreseeable future, I'll take the time to properly document how the frontend of the analyzer (especially how checker registration) works. Maybe with the new sphinx format if it goes through by then, but any format is better than none.

This revision was automatically updated to reflect the committed changes.