diff options
| author | Michael Matz <matz@suse.de> | 2012-04-16 01:13:25 +0200 |
|---|---|---|
| committer | Michael Matz <matz@suse.de> | 2012-04-18 20:57:14 +0200 |
| commit | 718fd591fa93ff254a9ca68a0ad2ff8a55756489 (patch) | |
| tree | 69ef5bb9cdfa3673317df44c8ba402526e758ef8 /tccgen.c | |
| parent | b068e29df753192bdcec5b1e41401bdc21812136 (diff) | |
| download | tinycc-718fd591fa93ff254a9ca68a0ad2ff8a55756489.tar.gz tinycc-718fd591fa93ff254a9ca68a0ad2ff8a55756489.tar.bz2 | |
Make sizeof() be of type size_t
This matters when sizeof is directly used in arithmetic,
ala "uintptr_t t; t &= -sizeof(long)" (for alignment). When sizeof
isn't size_t (as it's specified to be) this masking will truncate
the high bits of the uintptr_t object (if uintptr_t is larger than
uint).
Diffstat (limited to 'tccgen.c')
| -rw-r--r-- | tccgen.c | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -64,7 +64,7 @@ ST_DATA int func_vc; ST_DATA int last_line_num, last_ind, func_ind; /* debug last line number and pc */ ST_DATA char *funcname; -ST_DATA CType char_pointer_type, func_old_type, int_type; +ST_DATA CType char_pointer_type, func_old_type, int_type, size_type; /* ------------------------------------------------------------------------- */ static void gen_cast(CType *type); @@ -325,6 +325,17 @@ ST_FUNC void vpushi(int v) vsetc(&int_type, VT_CONST, &cval); } +/* push a pointer sized constant */ +static void vpushs(long long v) +{ + CValue cval; + if (PTR_SIZE == 4) + cval.i = (int)v; + else + cval.ull = v; + vsetc(&size_type, VT_CONST, &cval); +} + /* push long long constant */ static void vpushll(long long v) { @@ -3575,12 +3586,12 @@ ST_FUNC void unary(void) if (!(type.t & VT_VLA)) { if (size < 0) tcc_error("sizeof applied to an incomplete type"); - vpushi(size); + vpushs(size); } else { vla_runtime_type_size(&type, &align); } } else { - vpushi(align); + vpushs(align); } vtop->type.t |= VT_UNSIGNED; break; |
