public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Martin Liska <marxin@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/sphinx] analyzer: fix false +ves from -Wanalyzer-va-arg-type-mismatch on int promotion [PR106319] Date: Thu, 28 Jul 2022 12:10:08 +0000 (GMT) [thread overview] Message-ID: <20220728121008.01050385AE63@sourceware.org> (raw) https://gcc.gnu.org/g:4aa2b803c18542f76d565f77508e8fab12d66feb commit 4aa2b803c18542f76d565f77508e8fab12d66feb Author: David Malcolm <dmalcolm@redhat.com> Date: Tue Jul 26 17:17:18 2022 -0400 analyzer: fix false +ves from -Wanalyzer-va-arg-type-mismatch on int promotion [PR106319] gcc/analyzer/ChangeLog: PR analyzer/106319 * store.cc (store::set_value): Don't strip away casts if the region has NULL type. gcc/testsuite/ChangeLog: PR analyzer/106319 * gcc.dg/analyzer/stdarg-types-3.c: New test. * gcc.dg/analyzer/stdarg-types-4.c: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com> Diff: --- gcc/analyzer/store.cc | 4 +- gcc/testsuite/gcc.dg/analyzer/stdarg-types-3.c | 67 ++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/analyzer/stdarg-types-4.c | 22 +++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/gcc/analyzer/store.cc b/gcc/analyzer/store.cc index 0b3fb370d1e..46475f6a7fa 100644 --- a/gcc/analyzer/store.cc +++ b/gcc/analyzer/store.cc @@ -2445,7 +2445,9 @@ store::set_value (store_manager *mgr, const region *lhs_reg, remove_overlapping_bindings (mgr, lhs_reg, uncertainty); - rhs_sval = simplify_for_binding (rhs_sval); + if (lhs_reg->get_type ()) + rhs_sval = simplify_for_binding (rhs_sval); + /* ...but if we have no type for the region, retain any cast. */ const region *lhs_base_reg = lhs_reg->get_base_region (); binding_cluster *lhs_cluster; diff --git a/gcc/testsuite/gcc.dg/analyzer/stdarg-types-3.c b/gcc/testsuite/gcc.dg/analyzer/stdarg-types-3.c new file mode 100644 index 00000000000..7351261a55c --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/stdarg-types-3.c @@ -0,0 +1,67 @@ +static void __attribute__((noinline)) +__analyzer_consume_n_ints (int num, ...) +{ + __builtin_va_list ap; + __builtin_va_start (ap, num); + + int i, v; + for (i = 0; i < num; i++) + v = __builtin_va_arg (ap, int); + + __builtin_va_end (ap); +} + +void test_int (int x) +{ + __analyzer_consume_n_ints (1, x); +} + +void test_3_ints (int x, int y, int z) +{ + __analyzer_consume_n_ints (3, x, y, z); +} + +/* Verify that we don't complain about types that get promoted to int + at the variadic call. */ + +void test_short (short s) +{ + __analyzer_consume_n_ints (1, s); +} + +void test_ushort (unsigned short s) +{ + __analyzer_consume_n_ints (1, s); +} + +void test_schar (signed char ch) +{ + __analyzer_consume_n_ints (1, ch); +} + +void test_uchar (unsigned char ch) +{ + __analyzer_consume_n_ints (1, ch); +} + +struct ust +{ + int b0123 : 4; + int b4567 : 4; +}; + +void test_signed_bitfield (struct ust s) +{ + __analyzer_consume_n_ints (2, s.b0123, s.b4567); +} + +struct sst +{ + unsigned int b0123 : 4; + unsigned int b4567 : 4; +}; + +void test_unsigned_bitfield (struct sst s) +{ + __analyzer_consume_n_ints (2, s.b0123, s.b4567); +} diff --git a/gcc/testsuite/gcc.dg/analyzer/stdarg-types-4.c b/gcc/testsuite/gcc.dg/analyzer/stdarg-types-4.c new file mode 100644 index 00000000000..920eccebc2b --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/stdarg-types-4.c @@ -0,0 +1,22 @@ +static void __attribute__((noinline)) +__analyzer_consume_n_uints (int num, ...) +{ + __builtin_va_list ap; + __builtin_va_start (ap, num); + + int i, v; + for (i = 0; i < num; i++) + v = __builtin_va_arg (ap, unsigned int); + + __builtin_va_end (ap); +} + +void test_uint (unsigned int x) +{ + __analyzer_consume_n_uints (1, x); +} + +void test_3_uints (unsigned int x, unsigned int y, unsigned int z) +{ + __analyzer_consume_n_uints (3, x, y, z); +}
reply other threads:[~2022-07-28 12:10 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220728121008.01050385AE63@sourceware.org \ --to=marxin@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).