https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124094

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Malcolm <[email protected]>:

https://gcc.gnu.org/g:5d12019d75b1968411ef342f42620aa069aee161

commit r16-7823-g5d12019d75b1968411ef342f42620aa069aee161
Author: David Malcolm <[email protected]>
Date:   Fri Feb 27 23:35:46 2026 -0500

    aarch64: improve diagnostics for bogus JSON tuning inputs [PR124094]

    Use json-diagnostic.{h,cc} to improve the diagnostics issued
    for malformed and invalid JSON tuning inputs: report the
    file/line/column and, if possible, the JSON Pointer of the
    problematic input.

    Before
    ------

    $ ./xgcc -B. -S test.c -muser-provided-CPU=malformed.json
    cc1: error: error parsing JSON data: expected ':'; got number

    $ ./xgcc -B. -S test.c -muser-provided-CPU=unsigned-3.json
    cc1: warning: JSON tuning file does not contain version information;
compatibility cannot be verified
    cc1: error: key âtune_params.sve_widthâ value 5000000000 is out of
range for âuintâ type [0, 4294967295]
    cc1: error: validation failed for the provided JSON data

    After
    -----

    $ ./xgcc -B. -S test.c -muser-provided-CPU=malformed.json
    malformed.json:3:17: error: error parsing JSON data: expected ':'; got
number
        3 |     "sve_width" 128
          |                 ^~~

    $ ./xgcc -B. -S test.c -muser-provided-CPU=unsigned-3.json
    cc1: warning: JSON tuning file does not contain version information;
compatibility cannot be verified
    unsigned-3.json: In JSON value â/tune_params/sve_widthâ
    unsigned-3.json:3:18: error: key âtune_params.sve_widthâ value
5000000000 is out of range for âuintâ type [0, 4294967295]
        3 |     "sve_width": 5000000000
          |                  ^~~~~~~~~~
    cc1: error: validation failed for the provided JSON data

    gcc/ChangeLog:
            PR target/124094
            * config/aarch64/aarch64-generate-json-tuning-routines.py
            (generate_field_code): Add "ctxt, " arg to function call when
            operation is "parse".
            (generate_function): Add "gcc_json_context &ctxt, " param to
            function decl when operation is "parse".
            * config/aarch64/aarch64-json-tunings-parser-generated.inc:
            Regenerate, passing around a gcc_json_context &.
            * config/aarch64/aarch64-json-tunings-parser.cc: Include
            "json-diagnostic.h".
            (WARNING_OPT) New macro.
            (PARSE_INTEGER_FIELD): Add "ctxt" param and pass it around.
            (PARSE_UNSIGNED_INTEGER_FIELD): Likewise.
            (PARSE_BOOLEAN_FIELD): Likewise.
            (PARSE_STRING_FIELD): Likewise.
            (PARSE_OBJECT): Likewise.
            (PARSE_ARRAY_FIELD): Likewise.
            (PARSE_ENUM_FIELD): Likewise.
            (parse_func_type): Likewise.
            (parse_object_helper): Likewise.  Use json_error rather than error.
            (inform_about_wrong_kind_of_json_value): New.
            (extract_string): Add "ctxt" param.  Replace "warning" with a pair
            of calls to json_warning and
            inform_about_wrong_kind_of_json_value, tweaking wording
            accordingly.
            (extract_integer): Likewise.
            (extract_unsigned_integer): Likewise.
            (parse_enum_field): Likewise.
            (validate_and_traverse): Replace "warning" and "error" with
            "json_warning" and "json_error".
            (check_version_compatibility): Use WARNING_OPT.  Add
            auto_diagnostic_group to group the error and note.
            (aarch64_load_tuning_params_from_json_string): Add "js_filename"
            param.  Use gcc_json_context to capture location info.  Use it
            when reporting errors to get file/line/column info.  Replace check
            on root being non-null with assertion, as this is guaranteed if
            error is non-null.  Replace warning with json_warning.
            (aarch64_load_tuning_params_from_json): Pass data_filename to
            aarch64_load_tuning_params_from_json_string for use when reporting
            diagnostics.
            (selftest::test_json_integers): Add a placeholder filename.
            (selftest::test_json_boolean): Likewise.
            (selftest::test_json_strings): Likewise.
            (selftest::test_json_enums): Likewise.

    gcc/testsuite/ChangeLog:
            PR target/124094
            * gcc.target/aarch64/aarch64-json-tunings/boolean-2.c: Add options
            -fdiagnostics-show-caret -fdiagnostics-show-line-numbers.  Replace
            dg-error with a pair of dg-regexps to verify that we report the
            filename and JSON Pointer of where the error occurs, and then
            the filename and location within the JSON file.  Verify that we
            quote and underline the pertinent part of the JSON file.
            * gcc.target/aarch64/aarch64-json-tunings/empty-brackets.c:
Likewise.
            * gcc.target/aarch64/aarch64-json-tunings/enum-2.c: Likewise.
            * gcc.target/aarch64/aarch64-json-tunings/integer-2.c: Likewise.
            * gcc.target/aarch64/aarch64-json-tunings/integer-3.c: Likewise.
            * gcc.target/aarch64/aarch64-json-tunings/string-2.c: Likewise.
            * gcc.target/aarch64/aarch64-json-tunings/unidentified-key.c:
Likewise.
            * gcc.target/aarch64/aarch64-json-tunings/unsigned-2.c: Likewise.
            * gcc.target/aarch64/aarch64-json-tunings/unsigned-3.c: Likewise.
            * gcc.target/aarch64/aarch64-json-tunings/malformed.c: New test,
            to verify behavior on a malformed JSON input file.
            * gcc.target/aarch64/aarch64-json-tunings/malformed.json: New
            test file.  This is malformed JSON, due to a missing ':" between
            key and value.

    Signed-off-by: David Malcolm <[email protected]>

Reply via email to