History

Tidy unary() a bit

factor code a bit for transforming tokens into SValues. This revealed a bug in TOK_GET (see testcase), which happened to be harmless before. So fix that as well.

Michael Matz committed 9 years ago

Commit 8ca98e21 parent 21b12ea3 files · +43 −30Browse files

Unified · Split

3 files
  1. tccgen.c +18 −27
  2. tccpp.c +4 −1
  3. tests/tcctest.c +21 −2
tccgen.c+18−27
@@ -4297,14 +4297,6 @@ static void parse_type(CType *type) · 4296 unmodified lines
42974297 type_decl(type, &ad, &n, TYPE_ABSTRACT);
42984298 }
42994299
4300−static void vpush_tokc(int t)
4301−{
4302− CType type;
4303− type.t = t;
4304− type.ref = 0;
4305− vsetc(&type, VT_CONST, &tokc);
4306−}
4307−
43084300 static void parse_builtin_params(int nc, const char *args)
43094301 {
43104302 char c, sep = '(';
@@ -4345,33 +4337,32 @@ ST_FUNC void unary(void) · 34 unmodified lines
43454337 case TOK_CINT:
43464338 case TOK_CCHAR:
43474339 case TOK_LCHAR:
4348− vpushi(tokc.i);
4340+ t = VT_INT;
4341+ push_tokc:
4342+ type.t = t;
4343+ type.ref = 0;
4344+ vsetc(&type, VT_CONST, &tokc);
43494345 next();
43504346 break;
43514347 case TOK_CUINT:
4352− vpush_tokc(VT_INT | VT_UNSIGNED);
4353− next();
4354− break;
4348+ t = VT_INT | VT_UNSIGNED;
4349+ goto push_tokc;
43554350 case TOK_CLLONG:
4356− vpush_tokc(VT_LLONG);
4357− next();
4358− break;
4351+ t = VT_LLONG;
4352+ goto push_tokc;
43594353 case TOK_CULLONG:
4360− vpush_tokc(VT_LLONG | VT_UNSIGNED);
4361− next();
4362− break;
4354+ t =VT_LLONG | VT_UNSIGNED;
4355+ goto push_tokc;
43634356 case TOK_CFLOAT:
4364− vpush_tokc(VT_FLOAT);
4365− next();
4366− break;
4357+ t = VT_FLOAT;
4358+ goto push_tokc;
43674359 case TOK_CDOUBLE:
4368− vpush_tokc(VT_DOUBLE);
4369− next();
4370− break;
4360+ t = VT_DOUBLE;
4361+ goto push_tokc;
43714362 case TOK_CLDOUBLE:
4372− vpush_tokc(VT_LDOUBLE);
4373− next();
4374− break;
4363+ t = VT_LDOUBLE;
4364+ goto push_tokc;
4365+
43754366 case TOK___FUNCTION__:
43764367 if (!gnu_ext)
43774368 goto tok_identifier;
tccpp.c+4−1
@@ -1230,10 +1230,13 @@ static inline void TOK_GET(int *t, const int **pp, CValue *cv) · 1229 unmodified lines
12301230 case TOK_CUINT:
12311231 case TOK_CCHAR:
12321232 case TOK_LCHAR:
1233− case TOK_CFLOAT:
12341233 case TOK_LINENUM:
12351234 tab[0] = *p++;
1235+ cv->i = (*t == TOK_CUINT) ? (unsigned)cv->i : (int)cv->i;
12361236 break;
1237+ case TOK_CFLOAT:
1238+ tab[0] = *p++;
1239+ break;
12371240 case TOK_STR:
12381241 case TOK_LSTR:
12391242 case TOK_PPNUM:
tests/tcctest.c+21−2
@@ -3720,8 +3720,6 @@ typedef struct __attribute__((__packed__)) { · 3719 unmodified lines
37203720 int c;
37213721 } Spacked2;
37223722 Spacked2 spacked2;
3723−/* This doesn't work for now. Requires adjusting field offsets/sizes
3724− after parsing the struct members. */
37253723 typedef struct Spacked3_s {
37263724 char a;
37273725 short b;
@@ -3754,3 +3752,24 @@ void * __attribute__((__unused__)) get_void_ptr (void *a) · 26 unmodified lines
37543752 {
37553753 return a;
37563754 }
3755+
3756+/* This part checks for a bug in TOK_GET (used for inline expansion),
3757+ where the large long long constant left the the high bits set for
3758+ the integer constant token. */
3759+static inline
3760+int __get_order(unsigned long long size)
3761+{
3762+ int order;
3763+ size -= 0xffff880000000000ULL; // this const left high bits set in the token
3764+ {
3765+ struct S { int i : 1; } s; // constructed for this '1'
3766+ }
3767+ order = size;
3768+ return order;
3769+}
3770+
3771+/* This just forces the above inline function to be actually emitted. */
3772+int force_get_order(unsigned long s)
3773+{
3774+ return __get_order(s);
3775+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t