mirror of
https://github.com/cc65/cc65.git
synced 2025-01-11 11:30:13 +00:00
Merge pull request #336 from cacciatc/switch-error-fix
Switch error fix
This commit is contained in:
commit
0fca806b0a
@ -144,13 +144,8 @@ void SwitchStatement (void)
|
||||
/* Create a loop so we may use break. */
|
||||
AddLoop (ExitLabel, 0);
|
||||
|
||||
/* Make sure a curly brace follows */
|
||||
if (CurTok.Tok != TOK_LCURLY) {
|
||||
Error ("`{' expected");
|
||||
}
|
||||
|
||||
/* Parse the following statement, which will actually be a compound
|
||||
** statement because of the curly brace at the current input position
|
||||
/* Parse the following statement, which may actually be a compound
|
||||
** statement if there is a curly brace at the current input position
|
||||
*/
|
||||
HaveBreak = Statement (&RCurlyBrace);
|
||||
|
||||
@ -199,7 +194,7 @@ void SwitchStatement (void)
|
||||
/* Free the case value tree */
|
||||
FreeCaseNodeColl (SwitchData.Nodes);
|
||||
|
||||
/* If the case statement was (correctly) terminated by a closing curly
|
||||
/* If the case statement was terminated by a closing curly
|
||||
** brace, skip it now.
|
||||
*/
|
||||
if (RCurlyBrace) {
|
||||
|
76
test/val/duffs-device.c
Normal file
76
test/val/duffs-device.c
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
!!DESCRIPTION!! Implementation of Duff's device (loop unrolling).
|
||||
!!ORIGIN!!
|
||||
!!LICENCE!! GPL, read COPYING.GPL
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define ASIZE (100)
|
||||
|
||||
unsigned char success=0;
|
||||
unsigned char failures=0;
|
||||
unsigned char dummy=0;
|
||||
|
||||
#ifdef SUPPORT_BIT_TYPES
|
||||
bit bit0 = 0;
|
||||
#endif
|
||||
|
||||
void done()
|
||||
{
|
||||
dummy++;
|
||||
}
|
||||
|
||||
int acmp(char* a, char* b, int count)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < count; i++) {
|
||||
if(a[i] != b[i]) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void duffit (char* to, char* from, int count)
|
||||
{
|
||||
int n = (count + 7) / 8;
|
||||
|
||||
switch(count % 8) {
|
||||
case 0: do { *to++ = *from++;
|
||||
case 7: *to++ = *from++;
|
||||
case 6: *to++ = *from++;
|
||||
case 5: *to++ = *from++;
|
||||
case 4: *to++ = *from++;
|
||||
case 3: *to++ = *from++;
|
||||
case 2: *to++ = *from++;
|
||||
case 1: *to++ = *from++;
|
||||
} while(--n > 0);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char a[ASIZE] = {1};
|
||||
char b[ASIZE] = {2};
|
||||
|
||||
/* a and b should be different */
|
||||
if(!acmp(a, b, ASIZE)) {
|
||||
failures++;
|
||||
}
|
||||
|
||||
duffit(a, b, ASIZE);
|
||||
|
||||
/* a and b should be the same */
|
||||
if(acmp(a, b, ASIZE)) {
|
||||
failures++;
|
||||
}
|
||||
|
||||
success=failures;
|
||||
done();
|
||||
printf("failures: %d\n",failures);
|
||||
|
||||
return failures;
|
||||
}
|
39
test/val/switch2.c
Normal file
39
test/val/switch2.c
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
!!DESCRIPTION!! Testing empty bodied switch statements.
|
||||
!!ORIGIN!!
|
||||
!!LICENCE!! GPL, read COPYING.GPL
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
unsigned char success=0;
|
||||
unsigned char failures=0;
|
||||
unsigned char dummy=0;
|
||||
|
||||
void done()
|
||||
{
|
||||
dummy++;
|
||||
}
|
||||
|
||||
void switch_no_body(void)
|
||||
{
|
||||
switch(0);
|
||||
}
|
||||
|
||||
void switch_empty_body(void)
|
||||
{
|
||||
switch(0) {}
|
||||
}
|
||||
|
||||
/* only worried about this file compiling successfully */
|
||||
int main(void)
|
||||
{
|
||||
switch_no_body();
|
||||
switch_empty_body();
|
||||
|
||||
success=failures;
|
||||
done();
|
||||
printf("failures: %d\n",failures);
|
||||
|
||||
return failures;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user