User account creation filtered due to spam.

Bug 34205 - enum type/size error
Summary: enum type/size error
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: bootstrap (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: build, rejects-valid
Depends on:
Blocks:
 
Reported: 2007-11-23 10:58 UTC by Bernhard Reutner-Fischer
Modified: 2007-11-28 19:05 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.3.0 4.2.2
Last reconfirmed:


Attachments
reduced from gcc/tree.h (1.05 KB, text/plain)
2007-11-23 10:59 UTC, Bernhard Reutner-Fischer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bernhard Reutner-Fischer 2007-11-23 10:58:04 UTC
With current trunk:

In file included from toolchain_build_armeb_nofp
u/gcc-4.3.0/gcc/c-lang.c:26:
toolchain_build_armeb_nofpu/gcc-4.3.0/gcc/tree.h:371: error: width of 'code' exceeds its type


Works if omitting -march=iwmmxt -mabi=iwmmxt


Sample:
/there/build_armeb/staging_dir/usr/bin/armeb-linux-uclibcgnueabi-gcc -march=iwmmxt -mabi=iwmmxt -I/there/build_armeb/staging_dir/usr/include -I/there/build_armeb/staging_dir/include --sysroot=/there/build_armeb/staging_dir/ -isysroot /there/build_armeb/staging_dir  -I/there/build_armeb/staging_dir/usr/include -I/there/build_armeb/staging_dir/include --sysroot=/there/build_armeb/staging_dir/ -isysroot /there/build_armeb/staging_dir -fno-common   -DHAVE_CONFIG_H -I. -I. -I/there/toolchain_build_armeb_nofpu/gcc-4.3.0/gcc -I/there/toolchain_build_armeb_nofpu/gcc-4.3.0/gcc/. -I/there/toolchain_build_armeb_nofpu/gcc-4.3.0/gcc/../include -I/there/toolchain_build_armeb_nofpu/gcc-4.3.0/gcc/../libcpp/include -I/there/build_armeb/gmp-4.2.2/include -I/there/build_armeb/mpfr-2.3.0/include -I/there/toolchain_build_armeb_nofpu/gcc-4.3.0/gcc/../libdecnumber -I/there/toolchain_build_armeb_nofpu/gcc-4.3.0/gcc/../libdecnumber/dpd -I../libdecnumber    pr.c -o argh2.o -c
pr.c:201: error: width of 'code' exceeds its type
Comment 1 Bernhard Reutner-Fischer 2007-11-23 10:59:52 UTC
Created attachment 14625 [details]
reduced from gcc/tree.h
Comment 2 Daniel Jacobowitz 2007-11-26 13:50:33 UTC
I don't know how you configured to get this.  It looks like you've got -fshort-enums by default; GCC can not be built with that option (although it should be fixable).
Comment 3 Bernhard Reutner-Fischer 2007-11-26 17:09:09 UTC
I don't see an explicit -fshort-enums in my flags..

I'm using this:
CFLAGS_FOR_TARGET="-Os -pipe -fno-tree-loop-optimize -fno-tree-dominator-opts -fno-strength-reduce -fno-branch-count-reg  -I/there/build_armeb/staging_dir/usr/include -I/there/build_armeb/staging_dir/include --sysroot=/there/build_armeb/staging_dir/ -isysroot /there/build_armeb/staging_dir -mtune=iwmmxt -march=iwmmxt -mabi=iwmmxt -msoft-float -mfloat-abi=soft" \
/there/toolchain_build_armeb_nofpu/gcc-4.3.0/configure \
                --prefix=/usr \
                --build=i386-pc-linux-gnu \
                --host=armeb-linux-uclibcgnueabi \
                --target=armeb-linux-uclibcgnueabi \
                --enable-languages=c,fortran \
                --with-gxx-include-dir=/usr/include/c++ \
                --disable-__cxa_atexit \
                --with-gnu-ld \
                --enable-shared \
                --with-gmp="/there/build_armeb/gmp-4.2.2" \
                --with-mpfr="/there/build_armeb/mpfr-2.3.0" \
                --disable-nls \
                --enable-threads \
                --disable-multilib \
                --with-float=soft
Comment 4 Bernhard Reutner-Fischer 2007-11-26 17:11:56 UTC
While the configure explicitely lists armeb, the very same thing happens for arm(el), fwiw.
Does perhaps one of -m{arch,abi}=iwmmxt imply -fshort-enums ?
Comment 5 Daniel Jacobowitz 2007-11-27 19:27:29 UTC
Probably.  Why are you using the iwmmxt ABI?  Don't.  Just trust the AAPCS, it knows what's good for you.
Comment 6 Bernhard Reutner-Fischer 2007-11-27 19:48:55 UTC
I ment to build with arch=tune=abi for iwmmxt
As you say, arm.c suggests that iwmmxt defaults to -fshort-enums here, fwiw:

/* AAPCS based ABIs use short enums by default.  */

static bool
arm_default_short_enums (void)
{
  return TARGET_AAPCS_BASED && arm_abi != ARM_ABI_AAPCS_LINUX;
}

I'll see if turning on "int enums" per default (which i thought was mandated by C) for building GCC does what i intend.
Comment 7 Bernhard Reutner-Fischer 2007-11-27 20:15:22 UTC
s/int//. The enumerated type is implementation defined but shall be capable to represent the values of all members.

I'd read this as -fshort-enum violating that ":16"?
Comment 8 Khem Raj 2007-11-28 00:11:29 UTC
(In reply to comment #7)
> s/int//. The enumerated type is implementation defined but shall be capable to
> represent the values of all members.

Exactly and gcc for arm uses this definition to its advantage so that it can save some size.

> 
> I'd read this as -fshort-enum violating that ":16"?
> 

GCC can smartly chose type based on enum values for size reasons and it will choose the smallest type that can represent the enum. In this testcase enum can be represented by a char.
with
__extension__ enum tree_code code:16 

The testcase is asking for the bit-fields which are not defined for the enum type that gcc has chosen So I think error is ok here.




Comment 9 Bernhard Reutner-Fischer 2007-11-28 14:47:01 UTC
If the requested bitfield is larger than the type that was previously tried for enum, then you have to widen the type to fulfill that constaint.
Comment 10 Khem Raj 2007-11-28 16:40:19 UTC
(In reply to comment #9)
> If the requested bitfield is larger than the type that was previously tried for
> enum, then you have to widen the type to fulfill that constaint.
> 

is there a reference for this in the standards?
Comment 11 Bernhard Reutner-Fischer 2007-11-28 17:44:56 UTC
The standard (6.7.2.2, 4) talks about the note in #7.
I read this as for this input:
--------8<-------
enum e {ee};
struct s { __extension__ enum e baz:16; };
--------8<-------

The smallest type that can represent enum e has to be able to hold a bitfield of 16, i.e.:

--------8<-------
enum e {__GCC_CONSTRAINT_ee=SHRT_MAX};
struct s { __extension__ enum e baz /*now implied :16*/; };

--------8<-------
Comment 12 Bernhard Reutner-Fischer 2007-11-28 18:28:19 UTC
Not target specific, adjusting accordingly.
Observed everywhere with -fshort-enums
Comment 13 Paul Brook 2007-11-28 19:05:26 UTC
The short answer is don't do that.

-mabi=iwmmxt selects a bare-metal (short-enum) AAPCS variant with iWMMXt calling conventions. As such it is incompatible with the Linux EABI supplement (http://www.codesourcery.com/gnu_toolchains/arm/arm_gnu_linux_abi.pdf) which requires long-enums.

If you want iwmmxt calling conventions on linux you'll have to define and add a new ABI variant.

In theory gcc should probably be fixed to support short-enum host systems.
In practice all vaguely interesting host systems use long enums, and other bits of a linux system will explode if built with -fshort-enums, so I'm closing this as WONTFIX.