-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[clang-tidy][NFC] Enable bugprone-unchecked-optional-access in clang-tidy config and fix warnings
#170004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[clang-tidy][NFC] Enable bugprone-unchecked-optional-access in clang-tidy config and fix warnings
#170004
Changes from 7 commits
026c03a
8f291da
83e4eff
395da75
f6677ba
4f0c342
7f6239f
b1eeb05
d5e3c03
eabda17
4fd9989
a9d0e38
26d1aa7
8d712f4
ba06cb1
11e86d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,21 +43,21 @@ void ClangTidyProfiling::printUserFriendlyTable(llvm::raw_ostream &OS, | |
| } | ||
|
|
||
| void ClangTidyProfiling::printAsJSON(llvm::raw_ostream &OS, | ||
| llvm::TimerGroup &TG) { | ||
| llvm::TimerGroup &TG, | ||
| const StorageParams &Storage) { | ||
| OS << "{\n"; | ||
| OS << R"("file": ")" << Storage->SourceFilename << "\",\n"; | ||
| OS << R"("timestamp": ")" << Storage->Timestamp << "\",\n"; | ||
| OS << R"("file": ")" << Storage.SourceFilename << "\",\n"; | ||
| OS << R"("timestamp": ")" << Storage.Timestamp << "\",\n"; | ||
| OS << "\"profile\": {\n"; | ||
| TG.printJSONValues(OS, ""); | ||
| OS << "\n}\n"; | ||
| OS << "}\n"; | ||
| OS.flush(); | ||
| } | ||
|
|
||
| void ClangTidyProfiling::storeProfileData(llvm::TimerGroup &TG) { | ||
| assert(Storage && "We should have a filename."); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix the removal of this |
||
|
|
||
| llvm::SmallString<256> OutputDirectory(Storage->StoreFilename); | ||
| void ClangTidyProfiling::storeProfileData(llvm::TimerGroup &TG, | ||
| const StorageParams &Storage) { | ||
| llvm::SmallString<256> OutputDirectory(Storage.StoreFilename); | ||
| llvm::sys::path::remove_filename(OutputDirectory); | ||
| if (const std::error_code EC = | ||
| llvm::sys::fs::create_directories(OutputDirectory)) { | ||
|
|
@@ -67,14 +67,14 @@ void ClangTidyProfiling::storeProfileData(llvm::TimerGroup &TG) { | |
| } | ||
|
|
||
| std::error_code EC; | ||
| llvm::raw_fd_ostream OS(Storage->StoreFilename, EC, llvm::sys::fs::OF_None); | ||
| llvm::raw_fd_ostream OS(Storage.StoreFilename, EC, llvm::sys::fs::OF_None); | ||
| if (EC) { | ||
| llvm::errs() << "Error opening output file '" << Storage->StoreFilename | ||
| llvm::errs() << "Error opening output file '" << Storage.StoreFilename | ||
| << "': " << EC.message() << "\n"; | ||
| return; | ||
| } | ||
|
|
||
| printAsJSON(OS, TG); | ||
| printAsJSON(OS, TG, Storage); | ||
| } | ||
|
|
||
| ClangTidyProfiling::ClangTidyProfiling(std::optional<StorageParams> Storage) | ||
|
|
@@ -85,7 +85,7 @@ ClangTidyProfiling::~ClangTidyProfiling() { | |
| if (!Storage) | ||
| printUserFriendlyTable(llvm::errs(), TG); | ||
| else | ||
| storeProfileData(TG); | ||
| storeProfileData(TG, *Storage); | ||
| } | ||
|
|
||
| } // namespace clang::tidy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,8 @@ void TimeSubtractionCheck::registerMatchers(MatchFinder *Finder) { | |
| const std::string TimeInverse = (llvm::Twine("ToUnix") + ScaleName).str(); | ||
| std::optional<DurationScale> Scale = getScaleForTimeInverse(TimeInverse); | ||
| assert(Scale && "Unknown scale encountered"); | ||
| if (!Scale) | ||
| continue; | ||
|
Comment on lines
98
to
+100
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we then remove first
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels weird that dataflow framework didn't count it as "validation", could it be a FP? |
||
|
|
||
| auto TimeInverseMatcher = callExpr(callee( | ||
| functionDecl(hasName((llvm::Twine("::absl::") + TimeInverse).str())) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -440,7 +440,7 @@ bool IdentifierNamingCheck::HungarianNotation::isOptionEnabled( | |
| if (Iter == StrMap.end()) | ||
| return false; | ||
|
|
||
| return *llvm::yaml::parseBool(Iter->getValue()); | ||
| return llvm::yaml::parseBool(Iter->getValue()).value_or(false); | ||
| } | ||
|
|
||
| void IdentifierNamingCheck::HungarianNotation::loadFileConfig( | ||
|
|
@@ -834,26 +834,28 @@ void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { | |
| const ArrayRef<std::optional<NamingStyle>> Styles = | ||
| MainFileStyle->getStyles(); | ||
| for (size_t I = 0; I < SK_Count; ++I) { | ||
| if (!Styles[I]) | ||
| const auto &StyleOpt = Styles[I]; | ||
| if (!StyleOpt) | ||
| continue; | ||
| const NamingStyle &Style = *StyleOpt; | ||
| const size_t StyleSize = StyleNames[I].size(); | ||
| StyleString.assign({StyleNames[I], "HungarianPrefix"}); | ||
|
|
||
| Options.store(Opts, StyleString, Styles[I]->HPType); | ||
| Options.store(Opts, StyleString, Style.HPType); | ||
|
|
||
| memcpy(&StyleString[StyleSize], "IgnoredRegexp", 13); | ||
| StyleString.truncate(StyleSize + 13); | ||
| Options.store(Opts, StyleString, Styles[I]->IgnoredRegexpStr); | ||
| Options.store(Opts, StyleString, Style.IgnoredRegexpStr); | ||
| memcpy(&StyleString[StyleSize], "Prefix", 6); | ||
| StyleString.truncate(StyleSize + 6); | ||
| Options.store(Opts, StyleString, Styles[I]->Prefix); | ||
| Options.store(Opts, StyleString, Style.Prefix); | ||
| // Fast replacement of [Pre]fix -> [Suf]fix. | ||
| memcpy(&StyleString[StyleSize], "Suf", 3); | ||
| Options.store(Opts, StyleString, Styles[I]->Suffix); | ||
| if (Styles[I]->Case) { | ||
| Options.store(Opts, StyleString, Style.Suffix); | ||
| if (Style.Case) { | ||
| memcpy(&StyleString[StyleSize], "Case", 4); | ||
| StyleString.pop_back_n(2); | ||
| Options.store(Opts, StyleString, *Styles[I]->Case); | ||
| Options.store(Opts, StyleString, *Style.Case); | ||
| } | ||
| } | ||
| Options.store(Opts, "GetConfigPerFile", GetConfigPerFile); | ||
|
|
@@ -1344,10 +1346,14 @@ IdentifierNamingCheck::getFailureInfo( | |
| ArrayRef<std::optional<IdentifierNamingCheck::NamingStyle>> NamingStyles, | ||
| const IdentifierNamingCheck::HungarianNotationOption &HNOption, | ||
| StyleKind SK, const SourceManager &SM, bool IgnoreFailedSplit) const { | ||
| if (SK == SK_Invalid || !NamingStyles[SK]) | ||
| if (SK == SK_Invalid) | ||
| return std::nullopt; | ||
|
|
||
| const IdentifierNamingCheck::NamingStyle &Style = *NamingStyles[SK]; | ||
|
Comment on lines
-1347
to
-1350
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So dataflow couldn't handle checking for multiple optional values in one go? Seems like FP. |
||
| const auto &StyleOpt = NamingStyles[SK]; | ||
| if (!StyleOpt) | ||
| return std::nullopt; | ||
|
|
||
| const IdentifierNamingCheck::NamingStyle &Style = *StyleOpt; | ||
| if (Style.IgnoredRegexp.isValid() && Style.IgnoredRegexp.match(Name)) | ||
| return std::nullopt; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.