Bug 36470 - sizeof UTF-32 is 2 on AVR
Summary: sizeof UTF-32 is 2 on AVR
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2008-06-09 03:31 UTC by Andy Hutchinson
Modified: 2009-11-21 15:06 UTC (History)
3 users (show)

See Also:
Host: i686-pc-cygwin
Target: avr-unknown-none
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Andy Hutchinson 2008-06-09 03:31:08 UTC
AVR fails gcc.dg/utf32-1.c execution test. 

As AVR has 16 bit int, I tried fixing this by using unsigned long for char_32.

This failed, I was surprised to find this is apparently due to incorrect size of UTF-32 characters so that:

sizeof (U'\0')
sizeof (U'\u2029')
sizeof (U'\U00064321')

all give value of 2.

So it would seem size has been set as sizeof(int) perhaps? 

I can assign 32 bit values ok - just that sizeof says they are only 16 bits.

The modified testcase using 32 bit char_32t compiles to abort(), so I figure its not a target issue.

/****** Change this to unsigned long for AVR********/
typedef unsigned int char32_t;

extern void abort (void);

char32_t	c0 = U'a';
char32_t	c1 = U'\0';
char32_t	c2 = U'\u0024';
char32_t	c3 = U'\u2029';
char32_t	c4 = U'\U00064321';

#define A	0x00000061
#define D	0x00000024
#define X	0x00002029
#define Y	0x00064321

int main ()
    if (sizeof (U'a') != sizeof (char32_t))
	abort ();
    if (sizeof (U'\0') != sizeof (char32_t))
	abort ();
    if (sizeof (U'\u0024') != sizeof (char32_t))
	abort ();
    if (sizeof (U'\u2029') != sizeof (char32_t))
	abort ();
    if (sizeof (U'\U00064321') != sizeof (char32_t))
	abort ();

    if (c0 != A)
	abort ();
    if (c1 != 0x0000)
	abort ();
    if (c2 != D)
	abort ();
    if (c3 != X)
	abort ();
    if (c4 != Y)
	abort ();
Comment 1 Kris Van Hees 2008-06-09 13:25:39 UTC
It sound like AVR will need a different specification for CHAR32_TYPE given that the default in c-common.c (unsigned int) won't work.  Which would go in the appropriate file in gcc/config/avr, similar to how WCHAR_TYPE is defined.  That still won't solve the hardcoded specification of the typedef in the test, but that is going to be addressed "Real Soon Now" in an upcoming patch to provide a macro (by the compiler) for the underlying types that are used for char16_t and char32_t, which will then be used in the tests to get rid of the hardcoded underlying type in the typedefs.
Comment 2 Andy Hutchinson 2008-06-10 03:21:18 UTC
Fixing the testcase is easy, That is how i found problem.  Two wrongs make a right!

It is not a priority but it seems like the suggestions is right way to fix.
I'll mark as XFAIL sometime soon.
Comment 3 Joseph S. Myers 2009-03-31 20:36:11 UTC
I believe my patch for bug 448 should fix this, by using appropriate defaults
(taken from newlib) on all bare-metal targets.  It's possible the newlib
type settings aren't the same as those used on AVR, but that's another issue.
Comment 4 Andy Hutchinson 2009-11-21 15:06:39 UTC
Test and now passes for avr and m32 targets.


I will remove XFAIL in cleanup patch.

Comment 5 Andy Hutchinson 2009-11-23 22:10:41 UTC
Subject: Bug 36470

Author: hutchinsonandy
Date: Mon Nov 23 22:10:18 2009
New Revision: 154471

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=154471
PR testsuite/36470
* gcc.dg/utf-cvt.c: Skip int test for 16bit int targets.
Enable short test for avr target.
* gcc.dg/utf32-1.c: Enable test for avr and m32 targets.
* gcc.dg/utf32-2.c: Ditto.
* gcc.dg/utf32-3.c: Ditto.
* gcc.dg/utf32-4.c: Enable test for non-32bit targets.