Bug 18282 - PR c/17384 patch causes regression from 3.4.2
Summary: PR c/17384 patch causes regression from 3.4.2
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: 3.4.4
Assignee: Richard Henderson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-02 21:46 UTC by Jakub Jelinek
Modified: 2004-12-10 19:24 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.2 4.0.0
Known to fail: 3.4.3
Last reconfirmed: 2004-11-02 21:52:03


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2004-11-02 21:46:11 UTC
typedef enum { B1 = 1 } B;

B __attribute__ ((mode (QI))) b;

doesn't compile since 2004-10-13 on gcc-3_4-branch, while it is accepted
by GCC 3.3.x, 3.4.2 and current CVS HEAD.
enum with mode attribute is used e.g. by DHCP, so it would be bad if
3.4.3 was released with this.
Comment 1 Andrew Pinski 2004-11-02 21:52:02 UTC
Confirmed.
Comment 2 Richard Henderson 2004-11-02 23:14:07 UTC
NOT a regression.  The mode argument was IGNORED, silently, by previous versions.
See http://gcc.gnu.org/ml/gcc/2004-10/msg00715.html
Comment 3 Mark Mitchell 2004-11-02 23:18:19 UTC
Subject: Re:  PR c/17384 patch causes regression from 3.4.2

Jakub --

Since Richard says this is not a regression, but rather a case where the 
compiler is now correctly diagnosing code that previously did not work 
as intended, please do not commit the patch.  Instead, however, it would 
be nice to have a note for changes.html on this topic.

Comment 4 Jakub Jelinek 2004-11-03 07:45:38 UTC
Seems the attribute worked before (and with the patch I posted on gcc-3_4-branch
as well) when used on a decl with enum type, but not when used on enum's typedef.

On the other side, current trunk works when it is used on the typedef, but not
when it is used on the decl:

typedef enum { B1 = 1, B2 = 2, B4 = 4, B8 = 8, B16 = 16 } B;
typedef enum { C1 = 1, C2 = 2, C4 = 4, C8 = 8, C16 = 16 } __attribute__ ((mode
(QI))) C;
typedef enum { D1 = 1, D2 = 2, D4 = 4, D8 = 8, D16 = 16 } __attribute__ ((mode
(word))) D;

B __attribute__ ((mode (QI))) bqi;
B __attribute__ ((mode (word))) bword;
int sqi[sizeof (bqi) == sizeof (int __attribute__((mode (QI)))) ? 1 : -1];
int sword[sizeof (bword) == sizeof (int __attribute__((mode (word)))) ? 1 : -1];
int sc[sizeof (C) == sizeof (int __attribute__((mode (QI)))) ? 1 : -1];
int sd[sizeof (D) == sizeof (int __attribute__((mode (word)))) ? 1 : -1];

GCC 3.3, 3.4.2, 3_4-branch + my patch:
I.c:10: error: size of array `sc' is negative
I.c:11: error: size of array `sd' is negative
GCC HEAD:
I.c:8: error: size of array 'sqi' is negative
I.c:9: error: size of array 'sword' is negative

If sizeof (bqi) == sizeof (int __attribute__((mode (QI)))) is supposed to be
1, then not applying the patch would mean there is a regression on 3_4-branch
and that is exactly the case DHCP is using, where apparently the mode was
not ignored.
Comment 5 Mark Mitchell 2004-11-05 04:07:51 UTC
I'm not going to hold up 3.4.3 for this issue.

Richard's change makes this an error, so it's at most a rejects-valid. There's
also a good workaround: declare the enum __attribute__((packed)).  That's
probably a better choice anyhow.  I'll let you and Richard sort out what the
right semantics ought to be.  (FWIW, I think my sentiment is that this ought to
be like structures: you don't get to pick the mode, but you can say "packed" if
you want.)
Comment 6 GCC Commits 2004-11-24 22:18:27 UTC
Subject: Bug 18282

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-rhl-branch
Changes by:	jakub@gcc.gnu.org	2004-11-24 22:18:16

Modified files:
	gcc            : ChangeLog c-common.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/compile: 20041102-1.c 

Log message:
	PR c/18282
	* c-common.c (handle_mode_attribute): Allow mode attribute
	on enums when the mode is integral.
	
	* gcc.c-torture/compile/20041102-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-rhl-branch&r1=2.2326.2.399.2.55&r2=2.2326.2.399.2.56
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-rhl-branch&r1=1.476.4.6.2.7&r2=1.476.4.6.2.8
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-rhl-branch&r1=1.3389.2.170.2.28&r2=1.3389.2.170.2.29
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/compile/20041102-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-rhl-branch&r1=NONE&r2=1.1.2.1

Comment 7 GCC Commits 2004-12-09 22:55:47 UTC
Subject: Bug 18282

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rth@gcc.gnu.org	2004-12-09 22:55:43

Modified files:
	gcc            : ChangeLog attribs.c c-common.c 

Log message:
	PR c/18282
	* attribs.c (decl_attributes): Use relayout_decl.
	* c-common.c (handle_mode_attribute): Copy all relevant type
	parameters from the new underlying integral type.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6763&r2=2.6764
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/attribs.c.diff?cvsroot=gcc&r1=1.34&r2=1.35
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.c.diff?cvsroot=gcc&r1=1.592&r2=1.593

Comment 8 GCC Commits 2004-12-09 22:57:21 UTC
Subject: Bug 18282

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rth@gcc.gnu.org	2004-12-09 22:56:58

Added files:
	gcc/testsuite/gcc.dg: attr-mode-2.c 

Log message:
	Testcase for PR c/18282.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/attr-mode-2.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 9 GCC Commits 2004-12-10 19:23:34 UTC
Subject: Bug 18282

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	rth@gcc.gnu.org	2004-12-10 19:23:25

Modified files:
	gcc            : ChangeLog attribs.c c-common.c 
Added files:
	gcc/testsuite/gcc.dg: attr-mode-2.c 

Log message:
	PR c/18282
	* attribs.c (decl_attributes): Clear DECL_ALIGN when relaying out decl.
	* c-common.c (handle_mode_attribute): Handle enumeral types.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.726&r2=2.2326.2.727
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/attribs.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.28&r2=1.28.10.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.476.4.10&r2=1.476.4.11
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/attr-mode-2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 10 Richard Henderson 2004-12-10 19:24:11 UTC
Fixed.
Comment 11 GCC Commits 2004-12-23 23:51:04 UTC
Subject: Bug 18282

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	rth@gcc.gnu.org	2004-12-23 23:50:56

Modified files:
	gcc            : ChangeLog c-decl.c 

Log message:
	PR c/18282
	* c-decl.c (finish_enum): Retain precision acquired from an attribute.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.752&r2=2.2326.2.753
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.470.4.17&r2=1.470.4.18