Possible compiler issue

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Possible compiler issue

Post by Folknology »

It could be me of course doing something I should not or just missing the obvious but I have a problem with both 13.1.0 and 13.2.0 tool chains compiling the following:

Code: Select all

#include <platform.h>

#define STX 0x02
#define ETX 0x03

int rx(unsigned char * alias buffer) {
	unsigned char * alias org;
	unsigned char * alias buf;

	org = buffer;
	buf = buffer;

	if(*buffer++ != STX) return 0;
	while(*buffer != ETX)
		*buf++ = *buffer++;
	return buf-org;
}

int main(void) {
	unsigned char buffer[128];

	rx(buffer);
	return 1;
}
When I build this I get the following compile error:

Code: Select all

C:\Users\Alan\xmos\inccharpointbug>xmake
No modules used.
Creating dependencies for main.xc
Compiling main.xc
../src/main.xc: In function `rx':
../src/main.xc:15: error: use of `buf' causes an ambiguous evaluation
xmake[1]: *** [.build/src/main.xc.o] Error 1
xmake: *** [bin//inccharpointbug.xe] Error 2

C:\Users\Alan\xmos\inccharpointbug>
If I change the offending line (*buf++ = *buffer++;) and separately increment buf/buffer pointers :

Code: Select all

#include <platform.h>

#define STX 0x02
#define ETX 0x03

int rx(unsigned char * alias buffer) {
	unsigned char * alias org;
	unsigned char * alias buf;

	org = buffer;
	buf = buffer;

	if(*buffer++ != STX) return 0;
	while(*buffer != ETX) {
		*buf = *buffer;
		buf++;
		buffer++;
   }
	return buf-org;
}

int main(void) {
	unsigned char buffer[128];

	rx(buffer);

	return 1;
Everything then works hunky dory. Am I missing something (i.e. is my XC fu slipping) or is this some sort of compiler bug?

regards
Al


richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

Your code is valid so this looks like a bug. I've filed an internal bug report so this can get fixed in a future release. If you had written the following:

Code: Select all

*buf = (*buffer)++;
Then the compiler would have been correct to give an error. I suspect the compiler isn't keeping track of the level of pointer indirection correctly.