[clang-tools-extra] [clang-tidy] Fix crash on invalid file extension options (PR #227869)
Zeyi Xu via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 4 00:11:52 PDT 2026
================
@@ -245,15 +245,24 @@ void ClangTidyContext::setCurrentFile(StringRef File) {
WarningAsErrorFilter = std::make_unique<CachedGlobList>(
StringRef(getOptions().WarningsAsErrors.value_or("")));
static const std::vector<std::string> EmptyFileExtensions;
- if (!parseFileExtensions(getOptions().HeaderFileExtensions
- ? *getOptions().HeaderFileExtensions
- : EmptyFileExtensions,
- HeaderFileExtensions))
+ const bool ValidHeaderFileExtensions = parseFileExtensions(
----------------
zeyi2 wrote:
I think this can be simplified to the following:
```diff
WarningAsErrorFilter = std::make_unique<CachedGlobList>(
StringRef(getOptions().WarningsAsErrors.value_or("")));
static const std::vector<std::string> EmptyFileExtensions;
if (!parseFileExtensions(getOptions().HeaderFileExtensions
? *getOptions().HeaderFileExtensions
: EmptyFileExtensions,
- HeaderFileExtensions))
+ HeaderFileExtensions) &&
+ DiagEngine)
this->configurationDiag("Invalid header file extensions");
if (!parseFileExtensions(getOptions().ImplementationFileExtensions
? *getOptions().ImplementationFileExtensions
: EmptyFileExtensions,
- ImplementationFileExtensions))
+ ImplementationFileExtensions) &&
+ DiagEngine)
this->configurationDiag("Invalid implementation file extensions");
}
```
This keeps the change smaller while preserving the intended behavior.
WDYT?
https://github.com/llvm/llvm-project/pull/227869
More information about the cfe-commits
mailing list