From: Jakub Jelinek Date: Thu, 21 Dec 2023 10:20:17 +0000 (+0100) Subject: Fix -Wcalloc-transposed-args warning in collect2.cc and work around -Walloc-size... X-Git-Tag: basepoints/gcc-15~3357 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b99353c33f09201e3cee34387cee6cdccbe31660;p=thirdparty%2Fgcc.git Fix -Wcalloc-transposed-args warning in collect2.cc and work around -Walloc-size warning This fixes one warning and works around another one where we allocate less than what we cast to. 2023-12-21 Jakub Jelinek * gimple-fold.cc (maybe_fold_comparisons_from_match_pd): Use unsigned char buffers for lhs1 and lhs2 instead of allocating them through XALLOCA. * collect2.cc (maybe_run_lto_and_relink): Swap xcalloc arguments. --- diff --git a/gcc/collect2.cc b/gcc/collect2.cc index c943f9f577cf..70e6ca9ccdc7 100644 --- a/gcc/collect2.cc +++ b/gcc/collect2.cc @@ -622,7 +622,7 @@ maybe_run_lto_and_relink (char **lto_ld_argv, char **object_lst, LTO object replaced by all partitions and other LTO objects removed. */ - lto_c_argv = (char **) xcalloc (sizeof (char *), num_lto_c_args); + lto_c_argv = (char **) xcalloc (num_lto_c_args, sizeof (char *)); lto_c_ptr = CONST_CAST2 (const char **, char **, lto_c_argv); *lto_c_ptr++ = lto_wrapper; diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index cb4b57250a82..2c8848f8d748 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -7086,14 +7086,16 @@ maybe_fold_comparisons_from_match_pd (tree type, enum tree_code code, gimple_set_bb (stmt2, NULL); /* Allocate SSA names(lhs1) on the stack. */ - tree lhs1 = (tree)XALLOCA (tree_ssa_name); + alignas (tree_node) unsigned char lhs1buf[sizeof (tree_ssa_name)]; + tree lhs1 = (tree) &lhs1buf[0]; memset (lhs1, 0, sizeof (tree_ssa_name)); TREE_SET_CODE (lhs1, SSA_NAME); TREE_TYPE (lhs1) = type; init_ssa_name_imm_use (lhs1); /* Allocate SSA names(lhs2) on the stack. */ - tree lhs2 = (tree)XALLOCA (tree_ssa_name); + alignas (tree_node) unsigned char lhs2buf[sizeof (tree_ssa_name)]; + tree lhs2 = (tree) &lhs2buf[0]; memset (lhs2, 0, sizeof (tree_ssa_name)); TREE_SET_CODE (lhs2, SSA_NAME); TREE_TYPE (lhs2) = type;