The attached patch modifies the setting of TYPE_SIZE for __intN types
to use GET_MODE_BITSIZE rather than the bitsize extracted from the N
value. TYPE_SIZE for sizetype and bitsizetype are also modified to use
GET_MODE_BITSIZE rather than the precision of the type.

This fixes an issue for the msp430 target where the TYPE_SIZE of the
__int20 type was set using the precision (20 bits) instead of the
in-memory size (32 bits) of the type. This was reported in PR78849:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78849

I've added a testcase for the bug report, however I had to modify the
test driver, msp430.exp, for the test to pass. The other test drivers
add -pedantic-errors to DEFAULT_CFLAGS, and this causes an error when
the __int20 type is used:
> pr78849.c:5:3: error: ISO C does not support '__int20' types [-Wpedantic]
msp430.exp now removes -pedantic-errors from DEFAULT_CFLAGS.

The patch passed bootstrap and regression testing with no regressions
on recent trunk (r247020) for x86_64-pc-linux-gnu.
The patch passed regression testing with "-mcpu=msp430x/-mlarge" for
msp430-elf with no regressions, and fixed some failures in the gcc and
g++ testsuites:

> c-c++-common/torture/builtin-arith-overflow-7.c   -O0  execution test
> c-c++-common/torture/builtin-arith-overflow-8.c   -O0  execution test
> c-c++-common/torture/builtin-arith-overflow-9.c   -O0  execution test
> gcc.dg/pow-sqrt-1.c execution test
> gcc.dg/pow-sqrt-2.c execution test
> gcc.dg/pow-sqrt-3.c execution test
> gcc.dg/pr47201.c (test for excess errors)
>
> g++.dg/torture/pr37922.C   -O1  execution test
> g++.dg/torture/pr37922.C   -O2  execution test
> g++.dg/torture/pr37922.C   -O2 -flto -fno-use-linker-plugin 
> -flto-partition=none  execution test
> g++.dg/torture/pr37922.C   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects 
>  execution test
> g++.dg/torture/pr37922.C   -O3 -fomit-frame-pointer -funroll-loops 
> -fpeel-loops -ftracer -finline-functions  execution test
> g++.dg/torture/pr37922.C   -O3 -g  execution test
> g++.dg/torture/pr37922.C   -Os  execution test
> g++.dg/torture/pr41775.C   -O1  (test for excess errors)
> g++.dg/torture/pr41775.C   -O2  (test for excess errors)
> g++.dg/torture/pr41775.C   -O2 -flto -fno-use-linker-plugin 
> -flto-partition=none  (test for excess errors)
> g++.dg/torture/pr41775.C   -O3 -fomit-frame-pointer -funroll-loops 
> -fpeel-loops -ftracer -finline-functions  (test for excess errors)
> g++.dg/torture/pr41775.C   -O3 -g  (test for excess errors)
> g++.dg/torture/pr41775.C   -Os  (test for excess errors)

I am not aware of any targets except msp430 where the value returned
by GET_MODE_BITSIZE and the types' precision are different, hence
despite these changes being in a target-independent part of the
compiler I wouldn't expect any change in behaviour for other targets.
If this patch is acceptable, I would appreciate if someone could
commit it for me, as I don't have write access to the SVN repository.

Attachment: 0001-Use-GET_MODE_BITSIZE-when-setting-TYPE_SIZE.patch
Description: Binary data

Reply via email to