From 6605736a956e32a785d71d0a5b808fa39583de84 Mon Sep 17 00:00:00 2001 From: MaartenBrock Date: Fri, 21 Mar 2008 22:55:47 +0000 Subject: [PATCH] * support/regression/tests/bug1839277.c: new, added git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5112 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 1 + support/regression/tests/bug1839277.c | 50 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 support/regression/tests/bug1839277.c diff --git a/ChangeLog b/ChangeLog index 67ae6773..86e619de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ fixed bug 1839277 * src/mcs51/gen.c: throughout only output hex constants * src/SDCCicode.c (getPtrType, geniCodeCast): fixed code size regression + * support/regression/tests/bug1839277.c: new, added 2008-03-21 Philipp Klaus Krause diff --git a/support/regression/tests/bug1839277.c b/support/regression/tests/bug1839277.c new file mode 100644 index 00000000..78dae846 --- /dev/null +++ b/support/regression/tests/bug1839277.c @@ -0,0 +1,50 @@ +/* + bug 1839277 +*/ + +#include + +code struct Value { + code char* Name[2]; +} Values[2]= {{{"abc", "def"}}, {{"ghi", "jkl"}}}; + +char i=1; + +void +testBug(void) +{ + volatile char code* * p; + unsigned long v = 0; +//first subexpression 'Values[0].Name' is evaluted as follows: +//mov r2,#_Values +//mov r3,#(_Values >> 8) +//mov r4,#(_Values >> 16) ;this is wrong - should be 'mov r4,#128' shouldn't it? +//second subexpression 'Values[1].Name' is evaluted as follows: +//mov a,#0x04 +//add a,#_Values +//mov r2,a +//clr a +//addc a,#(_Values >> 8) +//mov r3,a +//mov r4,#128 ;this is all right + p = i ? Values[0].Name : Values[1].Name; +#if defined(SDCC_mcs51) + v = (unsigned long)p; + ASSERT((unsigned char)(v>>16)==0x80); +#endif + +//everything is all right with explicit typecast - but why do I need it? + p = i ? (char code**)Values[0].Name : (char code**)Values[1].Name; +#if defined(SDCC_mcs51) + v = (unsigned long)p; + ASSERT((unsigned char)(v>>16)==0x80); +#endif + +//this is the best/optimal version - again with explicit typecast +//Question: Why is it necessary to have explicit typecast to make things right? + p = i ? (char code* code*)Values[0].Name : (char code* code*)Values[1].Name; +#if defined(SDCC_mcs51) + v = (unsigned long)p; + ASSERT((unsigned char)(v>>16)==0x80); +#endif +} -- 2.30.2