Bug 27301 - [4.2 Regression] ICE on convoluted inline asm with "m" (statement expression and vla)
Summary: [4.2 Regression] ICE on convoluted inline asm with "m" (statement expression ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.1
: P2 normal
Target Milestone: 4.3.0
Assignee: Jakub Jelinek
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-25 09:00 UTC by Jakub Jelinek
Modified: 2019-08-05 04:48 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.0
Known to fail: 4.1.0 4.0.0 4.0.4 4.2.0 4.2.5
Last reconfirmed: 2007-09-20 10:10:11


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2006-04-25 09:00:18 UTC
inline void
foo (void *ptr, long n)
{
  __asm__ __volatile__ ("" : : "m" (__extension__
                                    ({ struct { char x[n]; } *p = ptr;
                                     *p; })));

}

void
bar (void)
{
  char buf[16];
  foo (buf, sizeof foo);
}

ICEs in tree_cst_low, apparently GCC attempts to create a VLA through non-VLA
mechanism (expand_one_stack_var).
Comment 1 Andrew Pinski 2006-04-25 18:41:51 UTC
Confirmed, the ICE is at least a regression.
Comment 2 Andrew Pinski 2006-04-25 18:47:31 UTC
Hmm, interesting, we have a TARGET_EXPR before gimplifying:
  __asm__ __volatile__(""::"m" TARGET_EXPR <D.1284, {
    typedef struct
    {
      char x[0:(unsigned int) ((int) SAVE_EXPR <n> - 1)];
    } struct struct
    {
      char x[0:(unsigned int) ((int) SAVE_EXPR <n> - 1)];
    };
    struct
    {
      char x[0:(unsigned int) ((int) SAVE_EXPR <n> - 1)];
    } * p = (struct
    {
      char x[0:(unsigned int) ((int) SAVE_EXPR <n> - 1)];
    } *) ptr;


Which might be the real issue.
The C++ front-end rejects this code as a VLA type is invalid even for GNU C++.
Comment 3 Andrew Pinski 2006-04-30 06:11:38 UTC
Note the correct version of the inline-asm as far as I can tell is:

  __asm__ __volatile__ ("" : : "m" (__extension__
                                    *({ struct { char x[n]; } *p = ptr;
                                     p; })));

Which solves the ICE.
Comment 4 Enrico Scholz 2006-05-06 11:00:49 UTC
fwiw (I reported the issue in the RH bugzilla, which was then forwarded by Jakub):

I toke this syntax out of the gcc documentation: info gcc -> g Extended Asm

| As an example, if you access ten bytes of a string, you can use a memory input 
| like:
| 
|      {"m"( ({ struct { char x[10]; } *p = (void *)ptr ; *p; }) )}.

Comment 5 Andrew Pinski 2006-08-27 21:32:42 UTC
On the mainline we get a different ICE now:
[pinskia@celery gcc]$ ~/gcc-local//bin/gcc t.c
t.c: In function ‘foo’:
t.c:4: internal compiler error: in force_constant_size, at gimplify.c:709
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

Which showed up with:
2006-06-23  Olivier Hainque  <hainque@adacore.com>
Comment 6 Gabriel Dos Reis 2007-02-03 16:52:48 UTC
won't fix in GCC-4.0.x.  Adjusting milestone.
Comment 7 Jakub Jelinek 2007-09-20 21:19:51 UTC
Subject: Bug 27301

Author: jakub
Date: Thu Sep 20 21:19:36 2007
New Revision: 128629

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128629
Log:
	PR c/33238
	PR c/27301
	* gimplify.c (gimplify_vla_decl): New function.
	(gimplify_decl_expr): Move VLA decl handling to gimplify_vla_decl.
	Call it.
	(gimplify_target_expr): Handle variable length TARGET_EXPRs.

	* gcc.c-torture/execute/20070919-1.c: New test.
	* gcc.dg/pr33238.c: New test.
	* gcc.dg/pr27301.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/20070919-1.c
    trunk/gcc/testsuite/gcc.dg/pr27301.c
    trunk/gcc/testsuite/gcc.dg/pr33238.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimplify.c
    trunk/gcc/testsuite/ChangeLog

Comment 8 Jakub Jelinek 2007-09-21 09:50:59 UTC
Fixed so far in 4.3.
Comment 9 Joseph S. Myers 2008-07-04 21:20:55 UTC
Closing 4.1 branch.
Comment 10 Joseph S. Myers 2009-03-30 15:52:12 UTC
Closing 4.2 branch, fixed in 4.3.