History

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.

Shinichiro Hamaji committed 16 years ago

Commit c31dc7a1 parent 9d347f82 files · +15 −5Browse files

Unified · Split

2 files
  1. tccgen.c +7 −5
  2. tests/tcctest.c +8 −0
tccgen.c+7−5
@@ -1883,12 +1883,14 @@ static void gen_cast(CType *type) · 1882 unmodified lines
18831883 }
18841884 #else
18851885 } else if ((dbt & VT_BTYPE) == VT_LLONG ||
1886− (dbt & VT_BTYPE) == VT_PTR) {
1887− /* XXX: not sure if this is perfect... need more tests */
1888− if ((sbt & VT_BTYPE) != VT_LLONG) {
1886+ (dbt & VT_BTYPE) == VT_PTR ||
1887+ (dbt & VT_BTYPE) == VT_FUNC) {
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 */
18891892 int r = gv(RC_INT);
1890− if (sbt != (VT_INT | VT_UNSIGNED) &&
1891− sbt != VT_PTR && sbt != VT_FUNC) {
1893+ if (sbt != (VT_INT | VT_UNSIGNED)) {
18921894 /* x86_64 specific: movslq */
18931895 o(0x6348);
18941896 o(0xc0 + (REG_VALUE(r) << 3) + REG_VALUE(r));
tests/tcctest.c+8−0
@@ -1094,6 +1094,14 @@ void struct_assign_test(void) · 1093 unmodified lines
10941094 printf("before call: %d %d\n", lsta2.f1, lsta2.f2);
10951095 lsta2 = struct_assign_test2(lsta2, 4);
10961096 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);
10971105 }
10981106
10991107 /* casts to short/char */

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