[cc65] cc65 function pointer bugs

From: Greg King <greg.king51verizon.net>
Date: 2015-03-11 18:21:47
cc65 version 2.13.9, Subversion revision 5990, fails to handle some 
operations on function pointers.

-------------------------------------------------------
static int func(void) {return 0;}
static int (*p)(void);
static int n;

void main(void) {
     p = func;
     n = (p == &func);
     n = (p == func);    /* error */
     ++p;
     n = (p > &func);
     n = (p > func);     /* error */
//    n = func - func;  /* error, abort */
//    n = func - &func; /* error, abort */
     n = &func - func;   /* error, warning */
     n = &func - &func;
     n = p - &func;
     n = p - func;       /* error, warning */
     n = &func - p;
     n = func - p;       /* error, abort */
}
-------------------------------------------------------

$ cc65 -v -v test.c
test1.c(1): static int func(void) {return 0;}
test1.c(2): static int (*p)(void);
test1.c(3): static int n;
test1.c(5): void main(void) {
test1.c(6): p = func;
test1.c(7): n = (p == &func);
test1.c(8): n = (p == func);
test1.c(8): Error: Incompatible types
Input: n = (p == func);
test1.c(9): ++p;
test1.c(10): n = (p > &func);
test1.c(11): n = (p > func);
test1.c(11): Error: Incompatible types
Input: n = (p > func);
test1.c(12):
test1.c(13):
test1.c(14): n = &func - func;
test1.c(15): n = &func - &func;
test1.c(14): Error: Invalid operands for binary operator `-'
Input: n = &func - &func;
test1.c(14): Warning: Converting pointer to integer without a cast
Input: n = &func - &func;
test1.c(16): n = p - &func;
test1.c(17): n = p - func;
test1.c(18): n = &func - p;
test1.c(17): Error: Invalid operands for binary operator `-'
Input: n = &func - p;
test1.c(17): Warning: Converting pointer to integer without a cast
Input: n = &func - p;
test1.c(19): n = func - p;
test1.c(20): }
test1.c(19): Error: Invalid operands for binary operator `-'
Input: }
test1.c(19): Internal compiler error:
Code generation messed up: StackPtr is -2, should be 0

Input: }
Aborted
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Wed Mar 11 19:22:17 2015

This archive was generated by hypermail 2.1.8 : 2015-03-11 19:22:19 CET