Bug 113999 - [14 Regression] ICE: in string_cst_has_null_terminator, at analyzer/region-model.cc:3651 with -fanalyzer on gcc.dg/tree-ssa/strncpy-2.c
Summary: [14 Regression] ICE: in string_cst_has_null_terminator, at analyzer/region-mo...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: analyzer (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: 14.0
Assignee: David Malcolm
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2024-02-19 17:19 UTC by Zdenek Sojka
Modified: 2024-02-21 00:52 UTC (History)
0 users

See Also:
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Build:
Known to work: 13.2.1
Known to fail: 14.0
Last reconfirmed: 2024-02-19 00:00:00


Attachments
auto-reduced testcase (107 bytes, text/plain)
2024-02-19 17:19 UTC, Zdenek Sojka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zdenek Sojka 2024-02-19 17:19:05 UTC
Created attachment 57464 [details]
auto-reduced testcase

Maybe related to PR113998

Compiler output:
$ x86_64-pc-linux-gnu-gcc -fanalyzer gcc.dg/tree-ssa/strncpy-2.c
during IPA pass: analyzer
gcc.dg/tree-ssa/strncpy-2.c: In function 'main':
gcc.dg/tree-ssa/strncpy-2.c:24:15: internal compiler error: in string_cst_has_null_terminator, at analyzer/region-model.cc:3651
   24 |   size_t n1 = __builtin_strlen (a);
      |               ^~~~~~~~~~~~~~~~~~~~
0x8c3351 string_cst_has_null_terminator
        /repo/gcc-trunk/gcc/analyzer/region-model.cc:3651
0x195c069 svalue_byte_range_has_null_terminator_1
        /repo/gcc-trunk/gcc/analyzer/region-model.cc:3712
0x195c069 svalue_byte_range_has_null_terminator
        /repo/gcc-trunk/gcc/analyzer/region-model.cc:3809
0x195c3c8 svalue_byte_range_has_null_terminator_1
        /repo/gcc-trunk/gcc/analyzer/region-model.cc:3774
0x195c3c8 svalue_byte_range_has_null_terminator
        /repo/gcc-trunk/gcc/analyzer/region-model.cc:3809
0x1969838 ana::region_model::scan_for_null_terminator_1(ana::region const*, tree_node*, ana::svalue const**, ana::region_model_context*) const
        /repo/gcc-trunk/gcc/analyzer/region-model.cc:4066
0x196a67e ana::region_model::check_for_null_terminated_string_arg(ana::call_details const&, unsigned int, bool, ana::svalue const**) const
        /repo/gcc-trunk/gcc/analyzer/region-model.cc:4337
0x1945766 ana::kf_strlen::impl_call_pre(ana::call_details const&) const
        /repo/gcc-trunk/gcc/analyzer/kf.cc:1389
0x1961a57 ana::region_model::on_call_pre(gcall const*, ana::region_model_context*)
        /repo/gcc-trunk/gcc/analyzer/region-model.cc:1700
0x196600a ana::region_model::on_stmt_pre(gimple const*, bool*, ana::region_model_context*)
        /repo/gcc-trunk/gcc/analyzer/region-model.cc:1337
0x192cf70 ana::exploded_node::on_stmt(ana::exploded_graph&, ana::supernode const*, gimple const*, ana::program_state*, ana::uncertainty_t*, bool*, ana::path_context*)
        /repo/gcc-trunk/gcc/analyzer/engine.cc:1512
0x192ff05 ana::exploded_graph::process_node(ana::exploded_node*)
        /repo/gcc-trunk/gcc/analyzer/engine.cc:4124
0x1930e3a ana::exploded_graph::process_worklist()
        /repo/gcc-trunk/gcc/analyzer/engine.cc:3515
0x19335a3 ana::impl_run_checkers(ana::logger*)
        /repo/gcc-trunk/gcc/analyzer/engine.cc:6209
0x19344b6 ana::run_checkers()
        /repo/gcc-trunk/gcc/analyzer/engine.cc:6300
0x1922e58 execute
        /repo/gcc-trunk/gcc/analyzer/analyzer-pass.cc:87
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

$ x86_64-pc-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/repo/gcc-trunk/binary-latest-amd64/bin/x86_64-pc-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-r14-9062-20240219114159-geb17bdc211a-checking-yes-rtl-df-extra-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/14.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++ --enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra --with-cloog --with-ppl --with-isl --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-gnu --with-ld=/usr/bin/x86_64-pc-linux-gnu-ld --with-as=/usr/bin/x86_64-pc-linux-gnu-as --disable-libstdcxx-pch --prefix=/repo/gcc-trunk//binary-trunk-r14-9062-20240219114159-geb17bdc211a-checking-yes-rtl-df-extra-amd64
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.1 20240219 (experimental) (GCC)
Comment 1 David Malcolm 2024-02-19 19:07:19 UTC
Thanks for filing this bug report.

Confirmed affects trunk:
  https://godbolt.org/z/ao1a7xchq
and doesn't affect GCC 13.

Am investigating.
Comment 2 GCC Commits 2024-02-21 00:46:43 UTC
The master branch has been updated by David Malcolm <dmalcolm@gcc.gnu.org>:

https://gcc.gnu.org/g:0a6a5f8656ccf9a60ac516c68cd4eb40ff4630c4

commit r14-9091-g0a6a5f8656ccf9a60ac516c68cd4eb40ff4630c4
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Tue Feb 20 19:44:51 2024 -0500

    analyzer: handle array-initialization from a string_cst [PR113999]
    
    gcc/analyzer/ChangeLog:
            PR analyzer/113999
            * analyzer.h (get_string_cst_size): New decl.
            * region-model-manager.cc (get_string_cst_size): New.
            (region_model_manager::maybe_get_char_from_string_cst): Treat
            single-byte accesses within string_cst but beyond
            TREE_STRING_LENGTH as being 0.
            * region-model.cc (string_cst_has_null_terminator): Likewise.
    
    gcc/testsuite/ChangeLog:
            PR analyzer/113999
            * c-c++-common/analyzer/strlen-pr113999.c: New test.
            * gcc.dg/analyzer/strlen-1.c: More test coverage.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Comment 3 David Malcolm 2024-02-21 00:52:17 UTC
Should be fixed by the above patch; marking as resolved.