diff options
author | David Malcolm <dmalcolm@redhat.com> | 2025-03-12 20:51:06 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2025-03-12 20:51:06 -0400 |
commit | 8015a72ae496401e05942f4d33c94aa45174f841 (patch) | |
tree | 8ffda062c88d51163e69e43f1d42fd46215c1ff1 /gcc/testsuite | |
parent | 03855565ae8fb8a256139b353ef14e7b9f7df6b8 (diff) | |
download | gcc-master.zip gcc-master.tar.gz gcc-master.tar.bz2 |
gcc/analyzer/ChangeLog:
PR analyzer/117262
* region-model-manager.cc
(region_model_manager::get_or_create_constant_svalue): Use
NULL_TREE for the types of constant_svalue for RAW_DATA_CST.
(region_model_manager::maybe_fold_sub_svalue): Generalize
STRING_CST logic to also handle RAW_DATA_CST.
(region_model_manager::maybe_get_char_from_cst): New.
(region_model_manager::maybe_get_char_from_raw_data_cst): New.
* region-model-manager.h
(region_model_manager::maybe_get_char_from_cst): New decl.
(region_model_manager::maybe_get_char_from_raw_data_cst): New decl.
* region-model.cc (region_model::get_rvalue_1): Handle
RAW_DATA_CST.
* store.cc (get_subregion_within_ctor_for_ctor_pair): New.
(binding_map::apply_ctor_pair_to_child_region): Call
get_subregion_within_ctor_for_ctor_pair so that we handle
RAW_DATA_CST.
gcc/testsuite/ChangeLog:
PR analyzer/117262
* c-c++-common/analyzer/raw-data-cst-pr117262-1.c: New test.
* c-c++-common/analyzer/raw-data-cst-pr117262-2.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/c-c++-common/analyzer/raw-data-cst-pr117262-1.c | 17 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/analyzer/raw-data-cst-pr117262-2.c | 36 |
2 files changed, 53 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/analyzer/raw-data-cst-pr117262-1.c b/gcc/testsuite/c-c++-common/analyzer/raw-data-cst-pr117262-1.c new file mode 100644 index 0000000..0c8d3e6 --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/raw-data-cst-pr117262-1.c @@ -0,0 +1,17 @@ +int +main () +{ + const unsigned char meow_bytes[] = { + 0x69, 0x6e, 0x74, 0x0a, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, + 0x7b, 0x0a, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x75, 0x6e, + 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, + 0x6d, 0x65, 0x6f, 0x77, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x5b, 0x5d, + 0x20, 0x3d, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x0a, 0x20, 0x20, + 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x20, 0x6d, + }; + short meow[sizeof (meow_bytes) / sizeof (short)] = {}; + for (int i = 0; i < (int) (sizeof (meow) / sizeof (short)); i++) + meow[i] = (meow_bytes[i * 2] << 8) | meow_bytes[i * 2 + 1]; + if (meow[0] != (0x69 << 8) + 0x6e) + __builtin_abort (); +} diff --git a/gcc/testsuite/c-c++-common/analyzer/raw-data-cst-pr117262-2.c b/gcc/testsuite/c-c++-common/analyzer/raw-data-cst-pr117262-2.c new file mode 100644 index 0000000..8d43efe --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/raw-data-cst-pr117262-2.c @@ -0,0 +1,36 @@ +#include "analyzer-decls.h" + +extern void use (unsigned char); + +void +test () +{ + const unsigned char meow_bytes[] = { + 0x69, 0x6e, 0x74, 0x0a, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, + 0x7b, 0x0a, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x75, 0x6e, + 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20, + 0x6d, 0x65, 0x6f, 0x77, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x5b, 0x5d, + 0x20, 0x3d, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x0a, 0x20, 0x20, + 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x20, 0x6d, + }; + + /* Verify that analyzer "knows" the values of individual bytes in + the array. */ + + /* First row. */ + __analyzer_eval (meow_bytes[0] == 0x69); /* { dg-warning "TRUE" } */ + __analyzer_eval (meow_bytes[1] == 0x6e); /* { dg-warning "TRUE" } */ + __analyzer_eval (meow_bytes[11] == 0x0a); /* { dg-warning "TRUE" } */ + + /* Second row. */ + __analyzer_eval (meow_bytes[12] == 0x7b); /* { dg-warning "TRUE" } */ + __analyzer_eval (meow_bytes[23] == 0x6e); /* { dg-warning "TRUE" } */ + + /* Final row. */ + __analyzer_eval (meow_bytes[60] == 0x7d); /* { dg-warning "TRUE" } */ + __analyzer_eval (meow_bytes[70] == 0x20); /* { dg-warning "TRUE" } */ + __analyzer_eval (meow_bytes[71] == 0x6d); /* { dg-warning "TRUE" } */ + + use (meow_bytes[-1]); /* { dg-warning "stack-based buffer under-read" } */ + use (meow_bytes[72]); /* { dg-warning "stack-based buffer over-read" } */ +} |