x86-64: Fix cast from integers to pointers.
Now, ./tcc -run -DTCC_TARGET_X86_64 tcc.c -run tcctest.c works!
This commit is contained in:
		
							parent
							
								
									51a7f163ad
								
							
						
					
					
						commit
						39a4b859d4
					
				
					 2 changed files with 13 additions and 3 deletions
				
			
		
							
								
								
									
										12
									
								
								tcc.c
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								tcc.c
									
										
									
									
									
								
							| 
						 | 
					@ -6208,10 +6208,10 @@ static void gen_cast(CType *type)
 | 
				
			||||||
                        gen_cast(type);
 | 
					                        gen_cast(type);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					#ifndef TCC_TARGET_X86_64
 | 
				
			||||||
            } else if ((dbt & VT_BTYPE) == VT_LLONG) {
 | 
					            } else if ((dbt & VT_BTYPE) == VT_LLONG) {
 | 
				
			||||||
                if ((sbt & VT_BTYPE) != VT_LLONG) {
 | 
					                if ((sbt & VT_BTYPE) != VT_LLONG) {
 | 
				
			||||||
                    /* scalar to long long */
 | 
					                    /* scalar to long long */
 | 
				
			||||||
#ifndef TCC_TARGET_X86_64
 | 
					 | 
				
			||||||
                    /* machine independent conversion */
 | 
					                    /* machine independent conversion */
 | 
				
			||||||
                    gv(RC_INT);
 | 
					                    gv(RC_INT);
 | 
				
			||||||
                    /* generate high word */
 | 
					                    /* generate high word */
 | 
				
			||||||
| 
						 | 
					@ -6231,15 +6231,21 @@ static void gen_cast(CType *type)
 | 
				
			||||||
                    /* patch second register */
 | 
					                    /* patch second register */
 | 
				
			||||||
                    vtop[-1].r2 = vtop->r;
 | 
					                    vtop[-1].r2 = vtop->r;
 | 
				
			||||||
                    vpop();
 | 
					                    vpop();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
#else
 | 
					#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) {
 | 
				
			||||||
                    int r = gv(RC_INT);
 | 
					                    int r = gv(RC_INT);
 | 
				
			||||||
                    if (sbt != (VT_INT | VT_UNSIGNED) && sbt != VT_PTR) {
 | 
					                    if (sbt != (VT_INT | VT_UNSIGNED) &&
 | 
				
			||||||
 | 
					                        sbt != VT_PTR && sbt != VT_FUNC) {
 | 
				
			||||||
                        /* x86_64 specific: movslq */
 | 
					                        /* x86_64 specific: movslq */
 | 
				
			||||||
                        o(0x6348);
 | 
					                        o(0x6348);
 | 
				
			||||||
                        o(0xc0 + (REG_VALUE(r) << 3) + REG_VALUE(r));
 | 
					                        o(0xc0 + (REG_VALUE(r) << 3) + REG_VALUE(r));
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
            } else if (dbt == VT_BOOL) {
 | 
					            } else if (dbt == VT_BOOL) {
 | 
				
			||||||
                /* scalar to bool */
 | 
					                /* scalar to bool */
 | 
				
			||||||
                vpushi(0);
 | 
					                vpushi(0);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1158,6 +1158,10 @@ void cast_test()
 | 
				
			||||||
           (int)p, (unsigned int)p,
 | 
					           (int)p, (unsigned int)p,
 | 
				
			||||||
           (long)p, (unsigned long)p,
 | 
					           (long)p, (unsigned long)p,
 | 
				
			||||||
           (long long)p, (unsigned long long)p);
 | 
					           (long long)p, (unsigned long long)p);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* from integers to pointers */
 | 
				
			||||||
 | 
					    printf("%p %p %p %p\n",
 | 
				
			||||||
 | 
					           (void *)a, (void *)b, (void *)c, (void *)d);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* initializers tests */
 | 
					/* initializers tests */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue