From: "Uecker, Martin" <Martin.Uecker@med.uni-goettingen.de>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Cc: "joseph@codesourcery.com" <joseph@codesourcery.com>
Subject: [committed] c: Add missing conditions in Walloc-size to avoid ICEs [PR112347]
Date: Thu, 2 Nov 2023 13:58:28 +0000 [thread overview]
Message-ID: <d9429b0fc31dfc99897fabf8f44af58e882b4aa7.camel@med.uni-goettingen.de> (raw)
In-Reply-To: <bc0624c1f6b5c97100f80c2ddf55a0498ef6bf63.camel@tugraz.at>
I forget to guard against some more cases.
Committed as obvious.
Martin
c: Add missing conditions in Walloc-size to avoid ICEs [PR112347]
Fix ICE because of forgotten checks for pointers to void
and incomplete arrays.
Committed as obvious.
PR c/112347
gcc/c:
* c-typeck.cc (convert_for_assignment): Add missing check.
gcc/testsuite:
* gcc.dg/Walloc-size-3.c: New test.
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 16fadfb5468..bdd57aae3ff 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -7367,6 +7367,7 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
idx = TREE_INT_CST_LOW (TREE_VALUE (TREE_CHAIN (args))) - 1;
tree arg = CALL_EXPR_ARG (rhs, idx);
if (TREE_CODE (arg) == INTEGER_CST
+ && !VOID_TYPE_P (ttl) && TYPE_SIZE_UNIT (ttl)
&& INTEGER_CST == TREE_CODE (TYPE_SIZE_UNIT (ttl))
&& tree_int_cst_lt (arg, TYPE_SIZE_UNIT (ttl)))
warning_at (location, OPT_Walloc_size, "allocation of "
diff --git a/gcc/testsuite/gcc.dg/Walloc-size-3.c b/gcc/testsuite/gcc.dg/Walloc-size-3.c
new file mode 100644
index 00000000000..b95e04a8d99
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Walloc-size-3.c
@@ -0,0 +1,15 @@
+/* PR 112347
+ { dg-do compile }
+ { dg-options "-Walloc-size" }
+ * */
+
+// Test that various types without size do not crash with -Walloc-size
+
+int * mallocx(unsigned long) __attribute__((malloc)) __attribute__((alloc_size(1)));
+void test_oom(void) { void *a_ = mallocx(1); }
+
+void parse_args(char (**child_args_ptr_ptr)[]) {
+ *child_args_ptr_ptr = __builtin_calloc(1, sizeof(char));
+}
+
+
next prev parent reply other threads:[~2023-11-02 13:58 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-18 21:26 [C PATCH, v2] Add Walloc-size to warn about insufficient size in allocations [PR71219] Martin Uecker
2023-10-31 18:44 ` [PING] " Martin Uecker
2023-10-31 22:19 ` Joseph Myers
2023-11-01 15:37 ` Martin Uecker
2023-11-01 20:21 ` Joseph Myers
2023-11-02 13:58 ` Uecker, Martin [this message]
2023-12-06 12:24 ` Jakub Jelinek
2023-12-06 12:31 ` Xi Ruoyao
2023-12-06 12:57 ` Jakub Jelinek
2023-12-06 13:34 ` Martin Uecker
2023-12-06 13:43 ` Martin Uecker
2023-12-06 14:21 ` Jakub Jelinek
2023-12-06 14:30 ` Siddhesh Poyarekar
2023-12-06 14:41 ` Jakub Jelinek
2023-12-06 14:43 ` Siddhesh Poyarekar
2023-12-06 14:56 ` Martin Uecker
2023-12-06 15:01 ` Jakub Jelinek
2023-12-06 15:10 ` Martin Uecker
2023-12-06 18:00 ` Eric Gallager
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=d9429b0fc31dfc99897fabf8f44af58e882b4aa7.camel@med.uni-goettingen.de \
--to=martin.uecker@med.uni-goettingen.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=joseph@codesourcery.com \
/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: link
Be 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).