[PATCH] Fix PR middle-end/26306

Eric Botcazou ebotcazou@adacore.com
Sun Nov 5 16:01:00 GMT 2006


Hi,

This is a regression present in every compiler of the 4.x series.  The 
compiler aborts on the attached Ada testcase because it is trying to
force a load of a volatile aggregate object with variable size.

The problematic bits are in the gimplifier:

      else if (COMPLETE_TYPE_P (TREE_TYPE (*expr_p)))
	{
	  /* Historically, the compiler has treated a bare
	     reference to a volatile lvalue as forcing a load.  */

That's partially wrong.  On the following C testcase:

struct S { double d; int i; };

int count;

void tick (void)
{
  count++;
}

volatile int a;

void foo(void)
{
  volatile struct S arr[4];

  (void) arr[tick (), a];
}

the 3.4.6 compiler generates at -O0 on x86:

foo:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$56, %esp
	call	tick
	movl	a, %eax
	leave
	ret

The relevant bits in the RTL expander are:

      /* Ensure we reference a volatile object even if value is ignored, but
	 don't do this if all we are doing is taking its address.  */
      if (TREE_THIS_VOLATILE (exp)
	  && TREE_CODE (exp) != FUNCTION_DECL
	  && mode != VOIDmode && mode != BLKmode
	  && modifier != EXPAND_CONST_ADDRESS)
	{
	  temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
	  if (MEM_P (temp))
	    temp = copy_to_reg (temp);
	  return const0_rtx;
	}

Of course the crucial difference is the missing equivalent of

  mode != BLKmode

in the gimplifier.  Hence the proposed fix.

Tested on x86_64-suse-linux.  OK for mainline/4.2/4.1 branches?


2006-11-05  Eric Botcazou  <ebotcazou@adacore.com>

	PR middle-end/26306
	* gimplify.c (gimplify_expr): Only force a load for references to
	volatile scalar values.


2006-11-05  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/volatile_aggregate.adb: New test.


:ADDPATCH middle-end:


-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: f712-023-3_fsf.diff
Type: text/x-diff
Size: 1848 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20061105/51c10dd3/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr26306.adb
Type: text/x-adasrc
Size: 676 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20061105/51c10dd3/attachment-0001.bin>


More information about the Gcc-patches mailing list