aboutsummaryrefslogtreecommitdiff
path: root/gcc/function.cc
diff options
context:
space:
mode:
authorMartin Uecker <uecker@tugraz.at>2023-05-21 19:32:01 +0200
committerMartin Uecker <uecker@tugraz.at>2023-05-23 22:04:56 +0200
commit42d1612eb5c3b2ee327bc3336bfcbc43a0d0fc5b (patch)
tree86c5c0a342f020de9a34b3e47471a73a7fc2cdce /gcc/function.cc
parentf9b5be322358ee63798e02a9103b6bbe459e7aea (diff)
downloadgcc-42d1612eb5c3b2ee327bc3336bfcbc43a0d0fc5b.zip
gcc-42d1612eb5c3b2ee327bc3336bfcbc43a0d0fc5b.tar.gz
gcc-42d1612eb5c3b2ee327bc3336bfcbc43a0d0fc5b.tar.bz2
Fix ICEs related to VM types in C 2/2 [PR109450]
Size expressions were sometimes lost and not gimplified correctly, leading to ICEs and incorrect evaluation order. Fix this by 1) not recursing pointers when gimplifying parameters, which was incorrect because it might access variables declared later for incomplete structs, and 2) adding a decl expr for variably-modified arrays that are pointed to by parameters declared as arrays. PR c/109450 gcc/ * function.cc (gimplify_parm_type): Remove function. (gimplify_parameters): Call gimplify_type_sizes. gcc/c/ * c-decl.cc (add_decl_expr): New function. (grokdeclarator): Add decl expr for size expression in types pointed to by parameters declared as arrays. gcc/testsuite/ * gcc.dg/pr109450-1.c: New test. * gcc.dg/pr109450-2.c: New test. * gcc.dg/vla-26.c: New test.
Diffstat (limited to 'gcc/function.cc')
-rw-r--r--gcc/function.cc27
1 files changed, 1 insertions, 26 deletions
diff --git a/gcc/function.cc b/gcc/function.cc
index f0ae641..82102ed 100644
--- a/gcc/function.cc
+++ b/gcc/function.cc
@@ -3872,30 +3872,6 @@ assign_parms (tree fndecl)
}
}
-/* A subroutine of gimplify_parameters, invoked via walk_tree.
- For all seen types, gimplify their sizes. */
-
-static tree
-gimplify_parm_type (tree *tp, int *walk_subtrees, void *data)
-{
- tree t = *tp;
-
- *walk_subtrees = 0;
- if (TYPE_P (t))
- {
- if (POINTER_TYPE_P (t))
- *walk_subtrees = 1;
- else if (TYPE_SIZE (t) && !TREE_CONSTANT (TYPE_SIZE (t))
- && !TYPE_SIZES_GIMPLIFIED (t))
- {
- gimplify_type_sizes (t, (gimple_seq *) data);
- *walk_subtrees = 1;
- }
- }
-
- return NULL;
-}
-
/* Gimplify the parameter list for current_function_decl. This involves
evaluating SAVE_EXPRs of variable sized parameters and generating code
to implement callee-copies reference parameters. Returns a sequence of
@@ -3931,8 +3907,7 @@ gimplify_parameters (gimple_seq *cleanup)
SAVE_EXPRs (amongst others) onto a pending sizes list. This
turned out to be less than manageable in the gimple world.
Now we have to hunt them down ourselves. */
- walk_tree_without_duplicates (&data.arg.type,
- gimplify_parm_type, &stmts);
+ gimplify_type_sizes (TREE_TYPE (parm), &stmts);
if (TREE_CODE (DECL_SIZE_UNIT (parm)) != INTEGER_CST)
{