Skip to content

Commit 8577e44

Browse files
committed
[Clang] Fix crash when -header-include-filtering is not specified
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.
1 parent da959c9 commit 8577e44

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,8 +2440,8 @@ static bool ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
24402440
(Opts.HeaderIncludeFormat == HIFMT_JSON &&
24412441
Opts.HeaderIncludeFiltering != HIFIL_Only_Direct_System))
24422442
Diags.Report(diag::err_drv_print_header_env_var_combination_cc1)
2443-
<< Args.getLastArg(OPT_header_include_format_EQ)->getValue()
2444-
<< Args.getLastArg(OPT_header_include_filtering_EQ)->getValue();
2443+
<< headerIncludeFormatKindToString(Opts.HeaderIncludeFormat)
2444+
<< headerIncludeFilteringKindToString(Opts.HeaderIncludeFiltering);
24452445

24462446
return Diags.getNumErrors() == NumErrorsBefore;
24472447
}

clang/test/Preprocessor/print-header-json.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: cat %t.txt | FileCheck %s --check-prefix=SUPPORTED
33
// RUN: not %clang_cc1 -E -header-include-format=textual -header-include-filtering=only-direct-system -header-include-file %t.txt -I %S/Inputs/print-header-json -isystem %S/Inputs/print-header-json/system %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=UNSUPPORTED0
44
// RUN: not %clang_cc1 -E -header-include-format=json -header-include-filtering=none -header-include-file %t.txt -I %S/Inputs/print-header-json -isystem %S/Inputs/print-header-json/system %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=UNSUPPORTED1
5+
// RUN: not %clang_cc1 -E -header-include-format=json -header-include-file %t.txt -I %S/Inputs/print-header-json -isystem %S/Inputs/print-header-json/system %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=UNSUPPORTED1
56
// RUN: rm %t.txt
67
// RUN: env CC_PRINT_HEADERS_FORMAT=json CC_PRINT_HEADERS_FILTERING=only-direct-system CC_PRINT_HEADERS_FILE=%t.txt %clang -fsyntax-only -I %S/Inputs/print-header-json -isystem %S/Inputs/print-header-json/system %s -o /dev/null
78
// RUN: env CC_PRINT_HEADERS_FORMAT=textual CC_PRINT_HEADERS_FILTERING=only-direct-system CC_PRINT_HEADERS_FILE=%t.txt not %clang -fsyntax-only -I %S/Inputs/print-header-json -isystem %S/Inputs/print-header-json/system %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=UNSUPPORTED2

0 commit comments

Comments
 (0)