Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug-3471.c
blob47f822aeeb3dde3033dbff922f8caa7268a8bc36
1 /* bug-3459.c
2 A bug in code generation for restoring registers after a builtin call.
3 */
5 #include <testfwk.h>
7 #pragma disable_warning 85
9 // Based on code by "Under4Mhz" licensed under GPL 2.0 or later
11 #include <string.h>
12 #include <stdint.h>
13 #include <stdarg.h>
15 const char TextPunc[] = ":%! ";
17 #define TEXT_SPACE ( TEXT_PUNC + 3 )
18 #define TEXT_UPPER ( TEXT_NUM + 10 )
19 #define TEXT_PUNC ( TEXT_UPPER + 26 )
20 #define TEXT_NUM ( TEXT_START + 0 )
21 #define TEXT_START 0
23 int myprintf( const char *restrict format, ... );
25 void ImageCompleteText( uint8_t x, uint8_t y, const char *text ) {
27 while( *text ) {
29 uint8_t ch = *text++;
31 uint8_t index = 0;
32 uint8_t start = TEXT_SPACE;
34 if ( ch == ' ' ) ;
35 else{
37 char *ptr = strchr( TextPunc, ch ); // One of the two bytes of the result of this builtin call got corrupted.
38 if ( ptr )
40 index = ptr - TextPunc;
41 start = TEXT_PUNC;
45 myprintf( "%d %d %c\n", index, start, ch );
47 x += 2;
51 int myprintf ( const char *restrict format, ... )
53 int index, start, ch;
54 va_list v;
55 va_start ( v, format );
56 index = va_arg ( v, int );
57 ASSERT (index == 2);
58 start = va_arg ( v, int );
59 ASSERT (start == 36);
60 ch = va_arg ( v, int );
61 ASSERT (ch == '!');
62 va_end ( v );
65 void
66 testBug( void) {
67 ImageCompleteText(0,0,"!");