diff options
author | Bob Wilson <bob.wilson@apple.com> | 2025-04-23 16:09:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-23 16:09:38 -0700 |
commit | 4f36ada1e205df08ad4377df88729f8defb36558 (patch) | |
tree | aa1902402082fdd5d0b5b36bfeed78c6335935ba /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | f75295f7982ee893473db6c3dc59886e02cd728c (diff) | |
download | llvm-4f36ada1e205df08ad4377df88729f8defb36558.zip llvm-4f36ada1e205df08ad4377df88729f8defb36558.tar.gz llvm-4f36ada1e205df08ad4377df88729f8defb36558.tar.bz2 |
[Clang] Fix crash when -header-include-filtering is not specified (#136232)
If you specify -header-include-format=json, the only filtering option
currently supported is -header-include-filtering=only-direct-system. If
you specify some other filtering option, Clang gives an error message.
But, if you do not specify the filtering option at all, Clang crashes
when producing the error message, since it tries to get the value of the
unused option.
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 9e9eed4..1df5038 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -2435,13 +2435,25 @@ static bool ParseDependencyOutputArgs(DependencyOutputOptions &Opts, // Check for invalid combinations of header-include-format // and header-include-filtering. - if ((Opts.HeaderIncludeFormat == HIFMT_Textual && - Opts.HeaderIncludeFiltering != HIFIL_None) || - (Opts.HeaderIncludeFormat == HIFMT_JSON && - Opts.HeaderIncludeFiltering != HIFIL_Only_Direct_System)) - Diags.Report(diag::err_drv_print_header_env_var_combination_cc1) - << Args.getLastArg(OPT_header_include_format_EQ)->getValue() - << Args.getLastArg(OPT_header_include_filtering_EQ)->getValue(); + if (Opts.HeaderIncludeFormat == HIFMT_Textual && + Opts.HeaderIncludeFiltering != HIFIL_None) { + if (Args.hasArg(OPT_header_include_format_EQ)) + Diags.Report(diag::err_drv_print_header_cc1_invalid_combination) + << headerIncludeFormatKindToString(Opts.HeaderIncludeFormat) + << headerIncludeFilteringKindToString(Opts.HeaderIncludeFiltering); + else + Diags.Report(diag::err_drv_print_header_cc1_invalid_filtering) + << headerIncludeFilteringKindToString(Opts.HeaderIncludeFiltering); + } else if (Opts.HeaderIncludeFormat == HIFMT_JSON && + Opts.HeaderIncludeFiltering == HIFIL_None) { + if (Args.hasArg(OPT_header_include_filtering_EQ)) + Diags.Report(diag::err_drv_print_header_cc1_invalid_combination) + << headerIncludeFormatKindToString(Opts.HeaderIncludeFormat) + << headerIncludeFilteringKindToString(Opts.HeaderIncludeFiltering); + else + Diags.Report(diag::err_drv_print_header_cc1_invalid_format) + << headerIncludeFormatKindToString(Opts.HeaderIncludeFormat); + } return Diags.getNumErrors() == NumErrorsBefore; } |