public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-5084] c: Add missing conditions in Walloc-size to avoid ICEs [PR112347]
@ 2023-11-02 13:55 Martin Uecker
  0 siblings, 0 replies; only message in thread
From: Martin Uecker @ 2023-11-02 13:55 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f432a594fe6d3a0de1330ba69200d158e6248083

commit r14-5084-gf432a594fe6d3a0de1330ba69200d158e6248083
Author: Martin Uecker <uecker@tugraz.at>
Date:   Thu Nov 2 13:12:15 2023 +0100

    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:
---
 gcc/c/c-typeck.cc                    |  1 +
 gcc/testsuite/gcc.dg/Walloc-size-3.c | 15 +++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 16fadfb54687..bdd57aae3ff8 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 000000000000..b95e04a8d99a
--- /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));
+}
+
+

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-02 13:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-02 13:55 [gcc r14-5084] c: Add missing conditions in Walloc-size to avoid ICEs [PR112347] Martin Uecker

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).