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).
Confirmed, the ICE is at least a regression.
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++.
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.
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; }) )}.
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>
won't fix in GCC-4.0.x. Adjusting milestone.
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
Fixed so far in 4.3.
Closing 4.1 branch.
Closing 4.2 branch, fixed in 4.3.