Patchwork [PR50527] Don't assume alignment of vla-related allocas.

login
register
mail settings
Submitter Tom de Vries
Date Oct. 4, 2011, 11:13 p.m.
Message ID <4E8B9300.8080200@mentor.com>
Download mbox | patch
Permalink /patch/117710/
State New
Headers show

Comments

Tom de Vries - Oct. 4, 2011, 11:13 p.m.
On 10/04/2011 11:31 PM, Tom de Vries wrote:
> On 10/04/2011 10:58 PM, Richard Henderson wrote:
>> On 10/04/2011 01:17 PM, Tom de Vries wrote:
>>> In general, to fold vlas (which are lowered to allocas) to normal declarations,
>>> if the alloca argument is constant.
>>
>> Ah.  Ok, I suppose.  How often are you seeing this happening?  I can imagine
>> a few instances via inlining, but even there not so much...
>>
> 
> I have no statistics on this. But something simple like this is still translated
> into a vla, and can be folded:
> ...
> const int n = 5;
> int array[n];
> ...
> 
>>> Any guidance on what to do if we have to expand the __builtin_alloca_with_align
>>> to a function call, specifically, with the second argument? This is currently
>>> handled like this, which is not very nice:
>>
>> Don't do anything special.  Just let it fall through as with alloca.  This should
>> never happen, except for stupid user tricks like -fno-builtin-alloca_with_align.
>> And if the user does that, they get what they deserve wrt needing to implement
>> that function in their runtime.
>>
> 
> What currently causes this behaviour, is -fmudflap, see mf_xform_statements in
> tree-mudflap.c. The patch handles handles __builtin_allloca_with_align the same
> as __builtins_alloca in that function, meaning that both are marked with
> gimple_call_set_cannot_inline.
> 
> So:
> - we always expand alloca_with_align in expand_builtin_alloca, even for
>   -fmudflap, or
> - we need to handle the expansion of the call, or
> - ... ?
> 

Or we don't lower to alloca_with_align when -fmudflap is present?
...
...

> Thanks,
> - Tom
> 
>>
>> r~
>

Patch

Index: gimplify.c
===================================================================
--- gimplify.c (revision 179210)
+++ gimplify.c (working copy)
@@ -1329,8 +1329,17 @@  gimplify_vla_decl (tree decl, gimple_seq
   SET_DECL_VALUE_EXPR (decl, t);
   DECL_HAS_VALUE_EXPR_P (decl) = 1;

-  t = built_in_decls[BUILT_IN_ALLOCA];
-  t = build_call_expr (t, 1, DECL_SIZE_UNIT (decl));
+  if (flag_mudflap)
+    {
+      t = built_in_decls[BUILT_IN_ALLOCA];
+      t = build_call_expr (t, 1, DECL_SIZE_UNIT (decl));
+    }
+  else
+    {
+      t = built_in_decls[BUILT_IN_ALLOCA_WITH_ALIGN];
+      t = build_call_expr (t, 2, DECL_SIZE_UNIT (decl),
+			   build_int_cstu (size_type_node, DECL_ALIGN (decl)));
+    }
   /* The call has been built for a variable-sized object.  */
   CALL_ALLOCA_FOR_VAR_P (t) = 1;
   t = fold_convert (ptr_type, t);