public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] [MSP430] [STAGE 1] Fix PR78849: ICE on initialization of global struct containing __int20 array
@ 2017-04-24 11:32 Jozef Lawrynowicz
  2017-04-24 11:40 ` Jozef Lawrynowicz
  0 siblings, 1 reply; 2+ messages in thread
From: Jozef Lawrynowicz @ 2017-04-24 11:32 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2956 bytes --]

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 #2: 0001-Use-GET_MODE_BITSIZE-when-setting-TYPE_SIZE.patch --]
[-- Type: application/octet-stream, Size: 4402 bytes --]

From 81ee936dcdde4f4a7d4036479dbbff77da1e72bb Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@somniumtech.com>
Date: Wed, 12 Apr 2017 14:45:45 +0000
Subject: [PATCH] Use GET_MODE_BITSIZE when setting TYPE_SIZE

2017-04-XX	Jozef Lawrynowicz	<jozef.l@somniumtech.com>

	gcc/
	PR target/78849
	* stor-layout.c (initialize_sizetypes): Use GET_MODE_BITSIZE when setting TYPE_SIZE.
	* tree.c (build_common_tree_nodes): Likewise.

	gcc/testsuite
	PR target/78849
	* gcc.target/msp430/pr78849.c: New test.
	* gcc.target/msp430/msp430.exp: Remove -pedantic-errors option from DEFAULT_CFLAGS.
---
 gcc/stor-layout.c                          |  5 +++--
 gcc/testsuite/gcc.target/msp430/msp430.exp | 13 +++++++++----
 gcc/testsuite/gcc.target/msp430/pr78849.c  | 21 +++++++++++++++++++++
 gcc/tree.c                                 |  6 ++++--
 4 files changed, 37 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/msp430/pr78849.c

diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 10e9a32..1dbaba0 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -2602,13 +2602,14 @@ initialize_sizetypes (void)
   /* Now layout both types manually.  */
   SET_TYPE_MODE (sizetype, smallest_mode_for_size (precision, MODE_INT));
   SET_TYPE_ALIGN (sizetype, GET_MODE_ALIGNMENT (TYPE_MODE (sizetype)));
-  TYPE_SIZE (sizetype) = bitsize_int (precision);
+  TYPE_SIZE (sizetype) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (sizetype)));
   TYPE_SIZE_UNIT (sizetype) = size_int (GET_MODE_SIZE (TYPE_MODE (sizetype)));
   set_min_and_max_values_for_integral_type (sizetype, precision, UNSIGNED);
 
   SET_TYPE_MODE (bitsizetype, smallest_mode_for_size (bprecision, MODE_INT));
   SET_TYPE_ALIGN (bitsizetype, GET_MODE_ALIGNMENT (TYPE_MODE (bitsizetype)));
-  TYPE_SIZE (bitsizetype) = bitsize_int (bprecision);
+  TYPE_SIZE (bitsizetype)
+    = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (bitsizetype)));
   TYPE_SIZE_UNIT (bitsizetype)
     = size_int (GET_MODE_SIZE (TYPE_MODE (bitsizetype)));
   set_min_and_max_values_for_integral_type (bitsizetype, bprecision, UNSIGNED);
diff --git a/gcc/testsuite/gcc.target/msp430/msp430.exp b/gcc/testsuite/gcc.target/msp430/msp430.exp
index e54d531..ce5c3dc 100644
--- a/gcc/testsuite/gcc.target/msp430/msp430.exp
+++ b/gcc/testsuite/gcc.target/msp430/msp430.exp
@@ -24,10 +24,15 @@ if { ![istarget msp430-*-*] } then {
 # Load support procs.
 load_lib gcc-dg.exp
 
-# If a testcase doesn't have special options, use these.
+# The '-pedantic-errors' option in the global variable DEFAULT_CFLAGS that is
+# set by other drivers causes an error when the __int20 type is used, so remove
+# this option from DEFAULT_CFLAGS for the msp430 tests.
 global DEFAULT_CFLAGS
-if ![info exists DEFAULT_CFLAGS] then {
-    set DEFAULT_CFLAGS ""
+if [info exists DEFAULT_CFLAGS] then {
+    set MSP430_DEFAULT_CFLAGS \
+      [ string map { "-pedantic-errors" "" } $DEFAULT_CFLAGS ]
+} else {
+    set MSP430_DEFAULT_CFLAGS ""
 }
 
 # Initialize `dg'.
@@ -35,7 +40,7 @@ dg-init
 
 # Main loop.
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cCS\]]] \
-	"" $DEFAULT_CFLAGS
+	"" $MSP430_DEFAULT_CFLAGS
 
 # All done.
 dg-finish
diff --git a/gcc/testsuite/gcc.target/msp430/pr78849.c b/gcc/testsuite/gcc.target/msp430/pr78849.c
new file mode 100644
index 0000000..97792e9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/msp430/pr78849.c
@@ -0,0 +1,21 @@
+/* { dg-do link } */
+
+struct s_1
+{
+  __int20 array[2];
+  char elem;
+};
+
+struct s_1 instance =
+{
+    {
+      0,
+      1,
+    },
+    2
+};
+
+int main (void)
+{
+  return 0;
+}
diff --git a/gcc/tree.c b/gcc/tree.c
index 72dbba4..12f2635 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -10285,8 +10285,10 @@ build_common_tree_nodes (bool signed_char)
     {
       int_n_trees[i].signed_type = make_signed_type (int_n_data[i].bitsize);
       int_n_trees[i].unsigned_type = make_unsigned_type (int_n_data[i].bitsize);
-      TYPE_SIZE (int_n_trees[i].signed_type) = bitsize_int (int_n_data[i].bitsize);
-      TYPE_SIZE (int_n_trees[i].unsigned_type) = bitsize_int (int_n_data[i].bitsize);
+      TYPE_SIZE (int_n_trees[i].signed_type)
+	= bitsize_int (GET_MODE_BITSIZE (int_n_data[i].m));
+      TYPE_SIZE (int_n_trees[i].unsigned_type)
+	= bitsize_int (GET_MODE_BITSIZE (int_n_data[i].m));
 
       if (int_n_data[i].bitsize > LONG_LONG_TYPE_SIZE
 	  && int_n_enabled_p[i])
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] [MSP430] [STAGE 1] Fix PR78849: ICE on initialization of global struct containing __int20 array
  2017-04-24 11:32 [PATCH] [MSP430] [STAGE 1] Fix PR78849: ICE on initialization of global struct containing __int20 array Jozef Lawrynowicz
@ 2017-04-24 11:40 ` Jozef Lawrynowicz
  0 siblings, 0 replies; 2+ messages in thread
From: Jozef Lawrynowicz @ 2017-04-24 11:40 UTC (permalink / raw)
  To: gcc-patches

On 24 April 2017 at 12:02, Jozef Lawrynowicz <jozef.l@somniumtech.com> wrote:
> 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:

Building and testing GCC for msp430-elf was done on the gcc-6-branch,
since trunk doesn't build with C++ enabled for msp430-elf.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-04-24 11:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-24 11:32 [PATCH] [MSP430] [STAGE 1] Fix PR78849: ICE on initialization of global struct containing __int20 array Jozef Lawrynowicz
2017-04-24 11:40 ` Jozef Lawrynowicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).