Bug 36804 - For-loop never exits in gcc for ARM.
Summary: For-loop never exits in gcc for ARM.
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.2.4
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-11 08:46 UTC by Dan Åberg
Modified: 2008-12-16 16:45 UTC (History)
2 users (show)

See Also:
Host: i686-linux-gnu
Target: arm-linux-gnu
Build: i686-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Åberg 2008-07-11 08:46:23 UTC
I've made a small example where a for-loop never exits when it should. I have tried gcc 4.2.1, 4.2.4 and 4.3.1 with the same result. Gcc 4.1.1 works.

GCC is configured with:
../configure --prefix=/opt/arm-linux/arm --host=i686-linux-gnu --target=arm-linux-gnu  --build=i686-linux-gnu --includedir=/opt/arm-linux/arm/arm-linux-gnu/usr/include --enable-multilib --enable-threads --disable-nls --enable-shared --enable-languages=c,c++ --enable-__cxa_atexit --enable-c99 --enable-long-long

The example is compiled with:
arm-linux-gnu-gcc -O1 -Wall -march=armv5 -o bug main.c

main.c:
---
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

struct dummy {
	unsigned short count;
	unsigned short options;
};

unsigned foo (unsigned x)
{
	return x << 1;
}

int main (int argc, char* argv[])
{
	struct dummy *d;
	unsigned count;
	unsigned i;
	unsigned short* w;
	unsigned phase;
	unsigned long long val;

	d          = malloc (sizeof(struct dummy));
	d->count   = 1;
	d->options = 0;
	count      = d->count;
	w          = malloc (sizeof(unsigned short));

	for (i=0; i<count; i++) {
		phase = (unsigned)((long long)(0xFFFFFFFF) * i / count);
		val   = foo (phase);
		w[i]  = (unsigned short)val;
		fprintf (stderr, "i: %u, count: %u\n", i, count);
	}

	return 0;
}
---
Comment 1 Richard Earnshaw 2008-12-16 16:45:49 UTC
I'm unable to reproduce this with any of svn-trunk, gcc-4.1.3 (debian), gcc-4.3.3 (SVN) or gcc-4.3.2 (debian).  The loop essentially reads as

  mov  r7, #1
  mov  r6, #0
L5:
  ...
  add  r6, r6, #1
  cmp  r7, r6
  bhi  L5

This will iterate only while r7 is larger than r6 -- that is, exactly once, when r6 is 0.