diff options
| author | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2010-08-31 08:35:31 +0900 |
|---|---|---|
| committer | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2010-08-31 08:35:31 +0900 |
| commit | c31dc7aa0c36e19e15cf41a0d2728e89ad339660 (patch) | |
| tree | bf52fce67702cc761a07472a63264429f2f1a433 | |
| parent | 9d347f87426aebabe4eb52207b2f9ea8d2274809 (diff) | |
| download | tinycc-c31dc7aa0c36e19e15cf41a0d2728e89ad339660.tar.gz tinycc-c31dc7aa0c36e19e15cf41a0d2728e89ad339660.tar.bz2 | |
Fix casts from 32bit integer types to 64bit integer types.
This bug was reported in
http://lists.gnu.org/archive/html/tinycc-devel/2010-08/msg00050.html
In this case, we should not emit any code when we cast from VT_FUNC to VT_PTR.
| -rw-r--r-- | tccgen.c | 12 | ||||
| -rw-r--r-- | tests/tcctest.c | 8 |
2 files changed, 15 insertions, 5 deletions
@@ -1883,12 +1883,14 @@ static void gen_cast(CType *type) } #else } else if ((dbt & VT_BTYPE) == VT_LLONG || - (dbt & VT_BTYPE) == VT_PTR) { - /* XXX: not sure if this is perfect... need more tests */ - if ((sbt & VT_BTYPE) != VT_LLONG) { + (dbt & VT_BTYPE) == VT_PTR || + (dbt & VT_BTYPE) == VT_FUNC) { + if ((sbt & VT_BTYPE) != VT_LLONG && + (sbt & VT_BTYPE) != VT_PTR && + (sbt & VT_BTYPE) != VT_FUNC) { + /* need to convert from 32bit to 64bit */ int r = gv(RC_INT); - if (sbt != (VT_INT | VT_UNSIGNED) && - sbt != VT_PTR && sbt != VT_FUNC) { + if (sbt != (VT_INT | VT_UNSIGNED)) { /* x86_64 specific: movslq */ o(0x6348); o(0xc0 + (REG_VALUE(r) << 3) + REG_VALUE(r)); diff --git a/tests/tcctest.c b/tests/tcctest.c index 7236971..916db09 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -1094,6 +1094,14 @@ void struct_assign_test(void) printf("before call: %d %d\n", lsta2.f1, lsta2.f2); lsta2 = struct_assign_test2(lsta2, 4); printf("after call: %d %d\n", lsta2.f1, lsta2.f2); + + static struct { + void (*elem)(); + } t[] = { + /* XXX: we should allow this even without braces */ + { struct_assign_test } + }; + printf("%d\n", struct_assign_test == t[0].elem); } /* casts to short/char */ |
