1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 07:29:33 +00:00

Fix ICE for bit-fields with typedef

Fixes #1267

Avoid ICE, but treat plain int bit-fields declared via typedef as
signed rather than unsigned.  It is more efficient to treat them
as unsigned, but this requires distinguishing int from signed int,
and this is curently not done.
This commit is contained in:
Jesse Rosenstock 2020-09-26 14:56:28 +02:00 committed by Oliver Schmidt
parent 4acdc9ced9
commit b931e65811
4 changed files with 88 additions and 6 deletions

View File

@ -1468,6 +1468,15 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers,
/* It's a typedef */
NextToken ();
TypeCopy (D->Type, Entry->Type);
/* If it's a typedef, we should actually use whether the signedness was
** specified on the typedef, but that information has been lost. Treat the
** signedness as being specified to work around the ICE in #1267.
** Unforunately, this will cause plain int bit-fields defined via typedefs
** to be treated as signed rather than unsigned.
*/
if (SignednessSpecified) {
*SignednessSpecified = 1;
}
break;
}
} else {

View File

@ -100,12 +100,6 @@ $(WORKDIR)/bug1263.$1.$2.prg: bug1263.c | $(WORKDIR)
$(if $(QUIET),echo misc/bug1263.$1.$2.prg)
$(NOT) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLERR)
# should compile, but gives an error
$(WORKDIR)/bug1094.$1.$2.prg: bug1094.c | $(WORKDIR)
@echo "FIXME: " $$@ "currently does not compile."
$(if $(QUIET),echo misc/bug1094.$1.$2.prg)
$(NOT) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLERR)
# this one requires --std=c89, it fails with --std=c99
# it fails currently at runtime
$(WORKDIR)/bug1265.$1.$2.prg: bug1265.c | $(WORKDIR)

79
test/val/bug1267.c Normal file
View File

@ -0,0 +1,79 @@
/*
Copyright 2020 The cc65 Authors
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
Tests of bit-field signedness with typedefs; see https://github.com/cc65/cc65/issues/1267
*/
#include <stdio.h>
static unsigned char failures = 0;
typedef int i16;
typedef unsigned int u16;
typedef signed int s16;
static struct ints {
i16 i : 4;
u16 u : 4;
s16 s : 4;
} si = {1, 2, 3};
static void test_bitfield_typedefs (void)
{
if (si.i != 1) {
/* Note that this is another bug that i is signed. */
printf ("Got si.a = %d, expected 1.\n", si.i);
failures++;
}
if (si.u != 2) {
printf ("Got si.u = %u, expected 2.\n", si.u);
failures++;
}
if (si.s != 3) {
printf ("Got si.s = %d, expected 3.\n", si.s);
failures++;
}
si.i = -1;
si.u = -2;
si.s = -3;
/* Note that this is another bug that i is signed. */
if (si.i != -1) {
printf ("Got si.a = %d, expected -1.\n", si.i);
failures++;
}
if (si.u != 14) {
printf ("Got si.u = %u, expected 14.\n", si.u);
failures++;
}
if (si.s != -3) {
printf ("Got si.s = %d, expected -3.\n", si.s);
failures++;
}
}
int main (void)
{
test_bitfield_typedefs ();
printf ("failures: %u\n", failures);
return failures;
}