]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Add missing conditions in Walloc-size to avoid ICEs [PR112347]
authorMartin Uecker <uecker@tugraz.at>
Thu, 2 Nov 2023 12:12:15 +0000 (13:12 +0100)
committerMartin Uecker <uecker@tugraz.at>
Thu, 2 Nov 2023 13:54:53 +0000 (14:54 +0100)
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.

gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/Walloc-size-3.c [new file with mode: 0644]

index 16fadfb546876d8ddc7075e5c7a894d310a49e31..bdd57aae3ff80a5e14721f020d1a8f9f55b6f613 100644 (file)
@@ -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 (file)
index 0000000..b95e04a
--- /dev/null
@@ -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));
+}
+
+