diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-01-18 12:11:57 -0500 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-01-18 12:11:57 -0500 |
commit | 84096e665c5f7d7ffb07f18a5fd5e804a94b237b (patch) | |
tree | 6715a673b8a6665564f487beb49765a419cd63b5 /gcc/testsuite/c-c++-common/analyzer | |
parent | e254d1224df306a07f3b0b572af2582f509b7d67 (diff) | |
download | gcc-84096e665c5f7d7ffb07f18a5fd5e804a94b237b.zip gcc-84096e665c5f7d7ffb07f18a5fd5e804a94b237b.tar.gz gcc-84096e665c5f7d7ffb07f18a5fd5e804a94b237b.tar.bz2 |
analyzer: fix offsets in has_null_terminator [PR112811]
PR analyzer/112811 reports an ICE attempting to determine whether a
string is null-terminated.
The root cause is confusion in the code about whether byte offsets are
relative to the start of the base region, or relative to the bound
fragment within the the region.
This patch rewrites the code to enforce a clearer separation between
the kinds of offset, fixing the ICE, and adds logging to help track
down future issues in this area of the code.
gcc/analyzer/ChangeLog:
PR analyzer/112811
* region-model.cc (fragment::dump_to_pp): New.
(fragment::has_null_terminator): Convert to...
(svalue_byte_range_has_null_terminator_1): ...this new function,
updating to use a byte_range relative to the start of the svalue.
(svalue_byte_range_has_null_terminator): New.
(fragment::string_cst_has_null_terminator): Convert to...
(string_cst_has_null_terminator): ...this, updating to use a
byte_range relative to the start of the svalue.
(iterable_cluster::dump_to_pp): New.
(region_model::scan_for_null_terminator): Add logging, moving body
to...
(region_model::scan_for_null_terminator_1): ...this new function,
adding more logging, and updating to use
svalue_byte_range_has_null_terminator.
* region-model.h (region_model::scan_for_null_terminator_1): New
decl.
gcc/testsuite/ChangeLog:
PR analyzer/112811
* c-c++-common/analyzer/strlen-pr112811.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/testsuite/c-c++-common/analyzer')
-rw-r--r-- | gcc/testsuite/c-c++-common/analyzer/strlen-pr112811.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/analyzer/strlen-pr112811.c b/gcc/testsuite/c-c++-common/analyzer/strlen-pr112811.c new file mode 100644 index 0000000..6bf5d7a --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/strlen-pr112811.c @@ -0,0 +1,18 @@ +struct foo_laptop_debug { + struct dentry *root; + unsigned long size; +}; +struct foo_laptop { + void *placeholder; + struct foo_laptop_debug debug; + char sdiag[64]; +}; + +extern struct dentry *debugfs_create_dir(void); + +void foo_debugfs_init(struct foo_laptop *foo) { + struct dentry *root; + root = debugfs_create_dir(); + foo->debug.root = root; + foo->debug.size = __builtin_strlen(foo->sdiag); +} |