Here is a patch to push
I hope to help you.
jiang
commit 512947a3cc497cee5e4f5c0aa3f17f81fa2bb18b
Author: jiang <[email protected]>
Date: Mon Jun 16 16:43:40 2014 +0800
#define bug fixes
bug:
#define hexCh(c (c >= 10 ? 'a' + c - 10 : '0' + c)
hexCh(c);
diff --git a/tccpp.c b/tccpp.c
index 053fd57..dfbc857 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -1253,16 +1253,15 @@ ST_FUNC void parse_define(void)
next_nomacro();
}
if (varg < TOK_IDENT)
- tcc_error("badly punctuated parameter list");
+ tcc_error("may not appear in macro parameter list: \"%s\"",
get_tok_str(varg, NULL));
s = sym_push2(&define_stack, varg | SYM_FIELD, is_vaargs, 0);
*ps = s;
ps = &s->next;
if (tok != ',')
- break;
+ continue;
next_nomacro();
}
- if (tok == ')')
- next_nomacro_spc();
+ next_nomacro_spc();
t = MACRO_FUNC;
}
tok_str_new(&str);
commit 588794e66871c1042ab96a644b0da19681268e78
Author: jiang <[email protected]>
Date: Sun Jun 22 15:28:34 2014 +0800
Add warning
diff --git a/libtcc.c b/libtcc.c
index d761582..0f8477c 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1404,8 +1404,9 @@ static const FlagDef warning_defs[] = {
{ offsetof(TCCState, warn_unsupported), 0, "unsupported" },
{ offsetof(TCCState, warn_write_strings), 0, "write-strings" },
{ offsetof(TCCState, warn_error), 0, "error" },
- { offsetof(TCCState, warn_implicit_function_declaration), WD_ALL,
- "implicit-function-declaration" },
+ { offsetof(TCCState, warn_implicit_function_declaration), WD_ALL,
"implicit-function-declaration" },
+ { offsetof(TCCState, warn_return_type), WD_ALL, "return-type" },
+ { offsetof(TCCState, warn_char_subscripts), WD_ALL, "char-subscripts" },
};
ST_FUNC int set_flag(TCCState *s, const FlagDef *flags, int nb_flags,
diff --git a/tcc.h b/tcc.h
index d0859d3..5cf639f 100644
--- a/tcc.h
+++ b/tcc.h
@@ -601,6 +601,8 @@ struct TCCState {
int warn_error;
int warn_none;
int warn_implicit_function_declaration;
+ int warn_return_type;
+ int warn_char_subscripts;
/* compile with debug symbol (and use them if error during execution) */
int do_debug;
diff --git a/tccgen.c b/tccgen.c
index b2a7717..f134586 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -2927,13 +2927,12 @@ static void struct_decl(CType *type, int u, int tdef)
if (tok != ':') {
type_decl(&type1, &ad, &v, TYPE_DIRECT |
TYPE_ABSTRACT);
if (v == 0 && (type1.t & VT_BTYPE) != VT_STRUCT)
- expect("identifier");
+ expect("specifier-qualifier-list at end of input");
if (type_size(&type1, &align) < 0) {
- if ((a == TOK_STRUCT) && (type1.t & VT_ARRAY))
- flexible = 1;
- else
- tcc_error("field '%s' has incomplete type",
- get_tok_str(v, NULL));
+ if ((a == TOK_STRUCT) && (type1.t & VT_ARRAY))
+ flexible = 1;
+ else
+ tcc_error("field '%s' has incomplete type",
get_tok_str(v, NULL));
}
if ((type1.t & VT_BTYPE) == VT_FUNC ||
(type1.t & (VT_TYPEDEF | VT_STATIC | VT_EXTERN |
VT_INLINE)))
@@ -2945,13 +2944,14 @@ static void struct_decl(CType *type, int u, int tdef)
bit_size = expr_const();
/* XXX: handle v = 0 case for messages */
if (bit_size < 0)
- tcc_error("negative width in bit-field '%s'",
- get_tok_str(v, NULL));
+ tcc_error("negative width in bit-field '%s'",
get_tok_str(v, NULL));
if (v && bit_size == 0)
- tcc_error("zero width for bit-field '%s'",
- get_tok_str(v, NULL));
+ tcc_error("zero width for bit-field '%s'",
get_tok_str(v, NULL));
}
- size = type_size(&type1, &align);
+ if(type1.t & VT_VLA)
+ size = 0, align = 1;
+ else
+ size = type_size(&type1, &align);
if (ad.a.aligned) {
if (align < ad.a.aligned)
align = ad.a.aligned;
@@ -3041,13 +3041,18 @@ static void struct_decl(CType *type, int u, int tdef)
*ps = ss;
ps = &ss->next;
}
- if (tok == ';' || tok == TOK_EOF)
+ if (tok == ';' || tok == '}')
break;
- skip(',');
+ if(tok == ',')
+ next();
}
- skip(';');
+ if(tok == '}'){
+ tcc_warning("no ';' at end of struct or union");
+ break;
+ }else
+ skip(';');
}
- skip('}');
+ next();
if (!c && flexible)
tcc_error("flexible array member '%s' in otherwise empty
struct", get_tok_str(v, NULL));
/* store size and alignment */
@@ -4061,6 +4066,8 @@ ST_FUNC void unary(void)
} else if (tok == '[') {
next();
gexpr();
+ if(tcc_state->warn_char_subscripts && (vtop->type.t &
(VT_BTYPE|VT_UNSIGNED)) == VT_BYTE)
+ tcc_warning("array subscript has type 'char'");
gen_op('+');
indir();
skip(']');
@@ -5542,6 +5549,8 @@ static void decl_initializer_alloc(CType *type,
AttributeDef *ad, int r,
flexible_array = NULL;
is_putz = 0;
+ if (has_init && (type->t & VT_VLA))
+ tcc_error("Variable length array cannot be initialized");
if ((type->t & VT_BTYPE) == VT_STRUCT) {
Sym *field = type->ref->next;
if (field) {
@@ -5969,10 +5978,15 @@ static int decl0(int l, int is_for_loop_init)
break;
btype.t = VT_INT;
}
- if (((btype.t & VT_BTYPE) == VT_ENUM ||
- (btype.t & VT_BTYPE) == VT_STRUCT) &&
- tok == ';') {
+ if (tok == ';') {
+ int bt = btype.t & VT_BTYPE;
/* we accept no variable after */
+ if(btype.t & (VT_CONSTANT|VT_VOLATILE))
+ tcc_warning("useless type qualifier in empty
declaration.'%s'before", get_tok_str(tok, NULL));
+ if(bt != VT_STRUCT && bt != VT_ENUM)
+ tcc_warning("useless type name in empty declaration '%s'",
get_tok_str(tok, NULL));
+ if((bt == VT_STRUCT) && ((btype.ref->v & ~SYM_STRUCT) >=
SYM_FIRST_ANOM))
+ tcc_warning("unnamed struct/union that defines no instances");
next();
continue;
}
@@ -6143,8 +6157,6 @@ static int decl0(int l, int is_for_loop_init)
r |= lvalue_type(type.t);
}
has_init = (tok == '=');
- if (has_init && (type.t & VT_VLA))
- tcc_error("Variable length array cannot be
initialized");
if ((btype.t & VT_EXTERN) || ((type.t & VT_BTYPE) ==
VT_FUNC) ||
((type.t & VT_ARRAY) && (type.t & VT_STATIC) &&
!has_init && l == VT_CONST && type.ref->c < 0)) {
commit 498bcc6f4a07514d28d7867e27c94a1f642fe2bc
Author: jiang <[email protected]>
Date: Sun Jun 22 15:24:18 2014 +0800
bug:
struct { unsigned a:9, b:7, c:5; } s;
s.a = s.b = s.c = 3;
printf("%d / %d / %d\n", s.a, s.b, s.c);
out:
0 / 0 / 3
and:
struct {
unsigned a:9, b:5, c:7;
} _s, *s = &_s;
int n = 250;
s->a = s->b = s->c = n + 4;
printf("--> %d / %d / %d\n", s->a, s->b, s->c);
out:
-> 0 / 0 / 126
diff --git a/tccgen.c b/tccgen.c
index f134586..83a7752 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -2549,6 +2549,15 @@ ST_FUNC void vstore(void)
/* bitfield store handling */
bit_pos = (ft >> VT_STRUCT_SHIFT) & 0x3f;
bit_size = (ft >> (VT_STRUCT_SHIFT + 6)) & 0x3f;
+
+ vpushv(&vtop[0]);
+ if(((vtop->r & (VT_VALMASK | VT_LVAL)) < VT_CONST) && (vtop > (vstack
+ 2))){
+ int r = get_reg(RC_INT);
+ load(r, vtop);
+ vtop->r = r;
+ }
+ vrott(3);
+
/* remove bit field info to avoid loops */
vtop[-1].type.t = ft & ~(VT_BITFIELD | (-1 << VT_STRUCT_SHIFT));
@@ -2583,6 +2592,7 @@ ST_FUNC void vstore(void)
gen_op('|');
/* store result */
vstore();
+ vtop--;
} else {
#ifdef CONFIG_TCC_BCHECK
/* bound check case */
@@ -4066,7 +4076,7 @@ ST_FUNC void unary(void)
} else if (tok == '[') {
next();
gexpr();
- if(tcc_state->warn_char_subscripts && (vtop->type.t &
(VT_BTYPE|VT_UNSIGNED)) == VT_BYTE)
+ if(tcc_state->warn_char_subscripts && (vtop->type.t &
(VT_BTYPE|VT_DEFSIGN|VT_UNSIGNED)) == VT_BYTE)
tcc_warning("array subscript has type 'char'");
gen_op('+');
indir();
diff --git a/tests/tests2/03_struct.c b/tests/tests2/03_struct.c
index c5d48c5..070c8d2 100644
--- a/tests/tests2/03_struct.c
+++ b/tests/tests2/03_struct.c
@@ -27,5 +27,35 @@ int main()
printf("%d\n", jones[1].boris);
printf("%d\n", jones[1].natasha);
+ struct sbf1 {
+ int f1 : 3;
+ int : 2;
+ int f2 : 1;
+ int : 0;
+ int f3 : 5;
+ int f4 : 7;
+ unsigned int f5 : 7;
+ } st1;
+ st1.f1 = st1.f2 = st1.f3 = st1.f4 = st1.f5 = 3;
+ printf("%d %d %d %d %d\n",
+ st1.f1, st1.f2, st1.f3, st1.f4, st1.f5);
+
+ struct { unsigned a:9, b:7, c:5; } s1;
+ s1.a = s1.b = s1.c = 3;
+ printf("%d / %d / %d\n", s1.a, s1.b, s1.c);
+
+ struct {
+ unsigned a:9, b:5, c:7;
+ } s2, *ps = &s2;
+ int n = 250;
+
+ ps->a = ps->b = ps->c = n + 4;
+ printf("%d / %d / %d\n", ps->a, ps->b, ps->c);
+
+ ps->a = n + 4;
+ ps->b = n + 4;
+ ps->c = n + 4;
+ printf("%d / %d / %d\n", ps->a, ps->b, ps->c);
+
return 0;
}
diff --git a/tests/tests2/03_struct.expect b/tests/tests2/03_struct.expect
index ecbf589..ac7d10d 100644
--- a/tests/tests2/03_struct.expect
+++ b/tests/tests2/03_struct.expect
@@ -4,3 +4,7 @@
34
56
78
+3 -1 3 3 3
+3 / 3 / 3
+254 / 30 / 126
+254 / 30 / 126
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel