This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix crash when handling invalid config values
AbandonedPublic

Authored by PiotrZSL on Mar 24 2023, 1:00 PM.

Details

Summary

Currently due to missing DiagnosticsEngine when invalid
enum config value is passed to check, and --dump-config
is used, clang-tidy would crash. This change fixes this
and extends --verify-config command to actually verify
those invalid enum values instead of ignoring them and
printing that 'No config errors detected.'.

Fixes:

Diff Detail

Event Timeline

PiotrZSL created this revision.Mar 24 2023, 1:00 PM
Herald added a project: Restricted Project. · View Herald Transcript
PiotrZSL requested review of this revision.Mar 24 2023, 1:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 24 2023, 1:00 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
PiotrZSL updated this revision to Diff 513692.Apr 14 2023, 11:35 AM

Ping + Rebase

njames93 added inline comments.Apr 15 2023, 3:56 AM
clang-tools-extra/clang-tidy/ClangTidy.h
61–69

I don't think this is the correct approach here
getAllChecksAndOptions should instead return an llvm::Expected<NamesAndOptions>.
You can create an error class that wraps a std::vector<ClangTidyError> and then still get the same behaviour on the error path.

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
528

Given how options are read, we only care about the last option source that defined the option
Therefore this should be changed to return a std::optional<StringRef> and the for loop below can just search the RawOptions backwards for the first match, then return that.

529
542

CheckOptions is a StringMap, so key lookup should be used instead of iterating through all the entries

PiotrZSL added inline comments.Apr 15 2023, 4:19 AM
clang-tools-extra/clang-tidy/ClangTidy.h
61–69

No, I need both Errors and Names. Not one of them.
And I think that some usages ignore Errors even if they exist.

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
528

--verify-config checks all config files, and prints diagnostic for all of them with a path of file.
In this way if I will have same invalid value in 2 different files, even that one override second, it will still provide warning for both.
No need to limit only to last entry...

529

Ack.

542

Ack.

njames93 requested changes to this revision.Apr 15 2023, 5:21 AM

Ok, taking a step back here, this patch is trying to address 2 unrelated things at once:

  • using --dump-config with bad check options results in a crash
  • using --verify-config won't actually verify that the checks are able to parse values from their respective CheckOptions

I think this should be split up into 2 separate patches, one for each of the proposed changes and each can be reviewed on their own.

This revision now requires changes to proceed.Apr 15 2023, 5:21 AM

I think this should be split up into 2 separate patches, one for each of the proposed changes and each can be reviewed on their own.

I don't plan to split this.

I think this should be split up into 2 separate patches, one for each of the proposed changes and each can be reviewed on their own.

I don't plan to split this.

The LLVM Guidelines state that patches should only contain one isolated change, independent changes should be sent as multiple patches.
Given the only overlap between these 2 changes is the fact they are using the same test file. These qualify as being isolated changes and should be handled as such.

PiotrZSL abandoned this revision.Apr 15 2023, 8:34 AM