[Bug c/70093] Instancing function with VM return type cases internal compiler error in 'assign_stack_temp_for_type'.

2016-03-19 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70093

--- Comment #13 from Marek Polacek  ---
Author: mpolacek
Date: Wed Mar 16 15:51:47 2016
New Revision: 234259

URL: https://gcc.gnu.org/viewcvs?rev=234259=gcc=rev
Log:
PR c/70093
* c-typeck.c (build_function_call_vec): Create a TARGET_EXPR for
nested functions returning VM types.

* cgraphunit.c (cgraph_node::expand_thunk): Also build call to the
function being thunked if the result type doesn't have fixed size.
* gimplify.c (gimplify_modify_expr): Also set LHS if the result type
doesn't have fixed size.

* gcc.dg/nested-func-10.c: New test.
* gcc.dg/nested-func-9.c: New test.

Added:
trunk/gcc/testsuite/gcc.dg/nested-func-10.c
trunk/gcc/testsuite/gcc.dg/nested-func-9.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/c/ChangeLog
trunk/gcc/c/c-typeck.c
trunk/gcc/cgraphunit.c
trunk/gcc/gimplify.c
trunk/gcc/testsuite/ChangeLog

[Bug c/70093] Instancing function with VM return type cases internal compiler error in 'assign_stack_temp_for_type'.

2016-03-18 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70093

Marek Polacek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED
   Target Milestone|--- |6.0

--- Comment #14 from Marek Polacek  ---
Fixed on the trunk.  Not planning to backport this one.

[Bug c/70093] Instancing function with VM return type cases internal compiler error in 'assign_stack_temp_for_type'.

2016-03-08 Thread sasho648 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70093

--- Comment #12 from sasho648 at gmail dot com ---
I would really love you guys if you actually could implement something like
this:

void fun(int a)
{
struct {int _[a];} fun();
}

In order to allow functions returning self-managed VLAs. What I'm proposing is
very simple. When a function is declared with the incomplete type 'void' - it
could be re-declared in it's definition scope with a VM type which will
complete it.

This isn't breaking any existing code nor introducing new complex syntax
(current compiler will emit error message for my above example stating
"conflicting types for 'fun'"). But it's providing us with a way for the return
type to access function local variables and so it's extending our possibilities
for writing code.

We can easily define the rules for such function definitions - first the
function re-declaration must be preceding any return statements. Second this
re-declaration syntax will be only valid for inside a 'void' function
definition and nowhere else. So if we have for example:


void fun(int a);

void fun(int a)
{
struct {int _[a];} fun();
}

The compiler should emit error for conflicting types as the 'fun' declaration
is of type 'void' and it's definition of VM type 'struct {int _[a];}'.

[Bug c/70093] Instancing function with VM return type cases internal compiler error in 'assign_stack_temp_for_type'.

2016-03-08 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70093

--- Comment #11 from Marek Polacek  ---
(The decl_function_context is probably redundant since I don't see how a
non-nested function could return VM type.)

[Bug c/70093] Instancing function with VM return type cases internal compiler error in 'assign_stack_temp_for_type'.

2016-03-08 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70093

--- Comment #10 from Marek Polacek  ---
Well, seems like the following fixes the ICEs!  I'm still not quite sure if
this makes sense at all, but the C FE testsuite still passes.  Needs a comment
and a bunch of tests.

--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -3068,6 +3068,15 @@ build_function_call_vec (location_t loc, vec
arg_loc,
 result = build_call_array_loc (loc, TREE_TYPE (fntype),
   function, nargs, argarray);

+  if (fundecl
+  && decl_function_context (fundecl)
+  && variably_modified_type_p (TREE_TYPE (fntype), NULL_TREE))
+{
+  tree tmp = create_tmp_var_raw (TREE_TYPE (fntype));
+  result = build4 (TARGET_EXPR, TREE_TYPE (fntype), tmp, result,
NULL_TREE,
+  NULL_TREE);
+}
+
   if (VOID_TYPE_P (TREE_TYPE (result)))
 {
   if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED)

[Bug c/70093] Instancing function with VM return type cases internal compiler error in 'assign_stack_temp_for_type'.

2016-03-08 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70093

--- Comment #9 from Marek Polacek  ---
So that would mean creating a TARGET_EXPR in the C FE I suppose...

[Bug c/70093] Instancing function with VM return type cases internal compiler error in 'assign_stack_temp_for_type'.

2016-03-08 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70093

--- Comment #8 from Marek Polacek  ---
Probably.  Because this doesn't (to my surprise) ICE:

void
foo (int n)
{
  struct S { int a[n]; };

  struct S
  fn (void)
  {
struct S s;
s.a[0] = 1;
return s;
  }

  struct S x;
  x = fn (); // just "fn();" ICEs
}

[Bug c/70093] Instancing function with VM return type cases internal compiler error in 'assign_stack_temp_for_type'.

2016-03-08 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70093

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #7 from Jakub Jelinek  ---
Maybe we need to treat functions returning VL types similarly to how we treat
functions returning C++ non-PODs, make sure the lhs of the call is always
present.

[Bug c/70093] Instancing function with VM return type cases internal compiler error in 'assign_stack_temp_for_type'.

2016-03-08 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70093

--- Comment #6 from Marek Polacek  ---
Ugh, a combination of a nested function and a VLA-in-a-struct.

We're trying to allocate variable-sized temporary.  Guess that's a wrong thing
to do, we should generate __builtin_alloca or __builtin_alloca_with_align when
expanding the call.

[Bug c/70093] Instancing function with VM return type cases internal compiler error in 'assign_stack_temp_for_type'.

2016-03-07 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70093

--- Comment #5 from Marek Polacek  ---
Even gcc34 ICEs here, so dunno when exactly it started, but it was a long long
time ago in a galaxy far far away.

[Bug c/70093] Instancing function with VM return type cases internal compiler error in 'assign_stack_temp_for_type'.

2016-03-07 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70093

Marek Polacek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
 CC||mpolacek at gcc dot gnu.org
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org

--- Comment #4 from Marek Polacek  ---
I'll look.

[Bug c/70093] Instancing function with VM return type cases internal compiler error in 'assign_stack_temp_for_type'.

2016-03-07 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70093

Richard Biener  changed:

   What|Removed |Added

   Keywords||ice-on-valid-code
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2016-03-07
 Ever confirmed|0   |1
  Known to fail||4.3.5, 5.3.0, 6.0

--- Comment #3 from Richard Biener  ---
Confirmed.  Not sure if the code is valid.

[Bug c/70093] Instancing function with VM return type cases internal compiler error in 'assign_stack_temp_for_type'.

2016-03-05 Thread sasho648 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70093

--- Comment #2 from sasho648 at gmail dot com ---
The bug occurs at the most simple 'gcc test_code.c' command.

[Bug c/70093] Instancing function with VM return type cases internal compiler error in 'assign_stack_temp_for_type'.

2016-03-05 Thread sasho648 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70093

--- Comment #1 from sasho648 at gmail dot com ---
As a comment - I'll add that this feature looks fascinating and my personal
opinion is that code like this should be allowed.

I even suggest a way of allowing the return VM type access to the function
parameters or locals. This way we could write self-contained functions which
can directly return VLA (with size varying on each instance) without the need
of the caller to maintain storage life-time (compared to 'malloc').