aboutsummaryrefslogtreecommitdiff
path: root/gcc/expr.cc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2025-01-28 16:20:30 +0100
committerRichard Biener <rguenth@gcc.gnu.org>2025-01-28 16:50:07 +0100
commit54bdeca3c6214485d15454df30183a56ad3e473b (patch)
treed8c284208420e802cb43f58779f096f4a27d1fd5 /gcc/expr.cc
parent50c37516958319e10a137d2b3dba7b070523248a (diff)
downloadgcc-54bdeca3c6214485d15454df30183a56ad3e473b.zip
gcc-54bdeca3c6214485d15454df30183a56ad3e473b.tar.gz
gcc-54bdeca3c6214485d15454df30183a56ad3e473b.tar.bz2
middle-end/118684 - wrongly aligned stack local during expansion
The following fixes a not properly aligned stack temporary created during RTL expansion of a MEM_REF that we handle as a BIT_FIELD_REF whose base was allocated to a register but which was originally aligned to allow a larger load not trapping. While probably UB in C the vectorizer creates aligned accesses that might overread a (static) allocation because it is then known not to trap. PR middle-end/118684 * expr.cc (expand_expr_real_1): When expanding a reference based on a register and we end up needing a MEM make sure that's aligned as the original reference required. * gcc.dg/pr118684.c: New testcase.
Diffstat (limited to 'gcc/expr.cc')
-rw-r--r--gcc/expr.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/gcc/expr.cc b/gcc/expr.cc
index a06411e..95f41f6 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -12148,7 +12148,11 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
and need be, put it there. */
else if (CONSTANT_P (op0) || (!MEM_P (op0) && must_force_mem))
{
- memloc = assign_temp (TREE_TYPE (tem), 1, 1);
+ poly_int64 size;
+ if (!poly_int_tree_p (TYPE_SIZE_UNIT (TREE_TYPE (tem)), &size))
+ size = max_int_size_in_bytes (TREE_TYPE (tem));
+ memloc = assign_stack_local (TYPE_MODE (TREE_TYPE (tem)), size,
+ get_object_alignment (tem));
emit_move_insn (memloc, op0);
op0 = memloc;
clear_mem_expr = true;