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.
Unified · Split
| @@ -1883,12 +1883,14 @@ static void gen_cast(CType *type) · 1882 unmodified lines | |||
| 1883 | } | 1883 | } |
| 1884 | #else | 1884 | #else |
| 1885 | } else if ((dbt & VT_BTYPE) == VT_LLONG || | 1885 | } else if ((dbt & VT_BTYPE) == VT_LLONG || |
| 1886 | (dbt & VT_BTYPE) == VT_PTR) { | 1886 | (dbt & VT_BTYPE) == VT_PTR || |
| 1887 | /* XXX: not sure if this is perfect... need more tests */ | 1887 | (dbt & VT_BTYPE) == VT_FUNC) { |
| 1888 | if ((sbt & VT_BTYPE) != VT_LLONG) { | 1888 | if ((sbt & VT_BTYPE) != VT_LLONG && |
| 1889 | (sbt & VT_BTYPE) != VT_PTR && | ||
| 1890 | (sbt & VT_BTYPE) != VT_FUNC) { | ||
| 1891 | /* need to convert from 32bit to 64bit */ | ||
| 1889 | int r = gv(RC_INT); | 1892 | int r = gv(RC_INT); |
| 1890 | if (sbt != (VT_INT | VT_UNSIGNED) && | 1893 | if (sbt != (VT_INT | VT_UNSIGNED)) { |
| 1891 | sbt != VT_PTR && sbt != VT_FUNC) { | ||
| 1892 | /* x86_64 specific: movslq */ | 1894 | /* x86_64 specific: movslq */ |
| 1893 | o(0x6348); | 1895 | o(0x6348); |
| 1894 | o(0xc0 + (REG_VALUE(r) << 3) + REG_VALUE(r)); | 1896 | o(0xc0 + (REG_VALUE(r) << 3) + REG_VALUE(r)); |
| @@ -1094,6 +1094,14 @@ void struct_assign_test(void) · 1093 unmodified lines | |||
| 1094 | printf("before call: %d %d\n", lsta2.f1, lsta2.f2); | 1094 | printf("before call: %d %d\n", lsta2.f1, lsta2.f2); |
| 1095 | lsta2 = struct_assign_test2(lsta2, 4); | 1095 | lsta2 = struct_assign_test2(lsta2, 4); |
| 1096 | printf("after call: %d %d\n", lsta2.f1, lsta2.f2); | 1096 | printf("after call: %d %d\n", lsta2.f1, lsta2.f2); |
| 1097 | |||
| 1098 | static struct { | ||
| 1099 | void (*elem)(); | ||
| 1100 | } t[] = { | ||
| 1101 | /* XXX: we should allow this even without braces */ | ||
| 1102 | { struct_assign_test } | ||
| 1103 | }; | ||
| 1104 | printf("%d\n", struct_assign_test == t[0].elem); | ||
| 1097 | } | 1105 | } |
| 1098 | 1106 | ||
| 1099 | /* casts to short/char */ | 1107 | /* casts to short/char */ |