History

x86-64: Fix cast from integers to pointers.

Now, ./tcc -run -DTCC_TARGET_X86_64 tcc.c -run tcctest.c works!

Shinichiro Hamaji committed 17 years ago

Commit 39a4b851 parent 51a7f162 files · +13 −3Browse files

Unified · Split

2 files
  1. tcc.c +9 −3
  2. tcctest.c +4 −0
tcc.c+9−3
@@ -6208,10 +6208,10 @@ static void gen_cast(CType *type) · 6207 unmodified lines
62086208 gen_cast(type);
62096209 }
62106210 }
6211+#ifndef TCC_TARGET_X86_64
62116212 } else if ((dbt & VT_BTYPE) == VT_LLONG) {
62126213 if ((sbt & VT_BTYPE) != VT_LLONG) {
62136214 /* scalar to long long */
6214−#ifndef TCC_TARGET_X86_64
62156215 /* machine independent conversion */
62166216 gv(RC_INT);
62176217 /* generate high word */
@@ -6231,15 +6231,21 @@ static void gen_cast(CType *type) · 13 unmodified lines
62316231 /* patch second register */
62326232 vtop[-1].r2 = vtop->r;
62336233 vpop();
6234+ }
62346235 #else
6236+ } else if ((dbt & VT_BTYPE) == VT_LLONG ||
6237+ (dbt & VT_BTYPE) == VT_PTR) {
6238+ /* XXX: not sure if this is perfect... need more tests */
6239+ if ((sbt & VT_BTYPE) != VT_LLONG) {
62356240 int r = gv(RC_INT);
6236− if (sbt != (VT_INT | VT_UNSIGNED) && sbt != VT_PTR) {
6241+ if (sbt != (VT_INT | VT_UNSIGNED) &&
6242+ sbt != VT_PTR && sbt != VT_FUNC) {
62376243 /* x86_64 specific: movslq */
62386244 o(0x6348);
62396245 o(0xc0 + (REG_VALUE(r) << 3) + REG_VALUE(r));
62406246 }
6241−#endif
62426247 }
6248+#endif
62436249 } else if (dbt == VT_BOOL) {
62446250 /* scalar to bool */
62456251 vpushi(0);
tcctest.c+4−0
@@ -1158,6 +1158,10 @@ void cast_test() · 1157 unmodified lines
11581158 (int)p, (unsigned int)p,
11591159 (long)p, (unsigned long)p,
11601160 (long long)p, (unsigned long long)p);
1161+
1162+ /* from integers to pointers */
1163+ printf("%p %p %p %p\n",
1164+ (void *)a, (void *)b, (void *)c, (void *)d);
11611165 }
11621166
11631167 /* initializers tests */

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