x86_64 bound checking failure

The code:
void mul(double *p)
{
    *p *= 2.0;
}

failed on x86_64 because register was not loaded after
bound checking call.
Also printed size when pointer indir failes.
This commit is contained in:
herman ten brugge 2025-08-10 21:55:48 +02:00
parent fa9795406d
commit 087cf2e579
5 changed files with 15 additions and 3 deletions

View File

@ -588,8 +588,9 @@ void * __bound_ptr_indir ## dsize (void *p, size_t offset) \
if (addr <= tree->size) { \
if (tree->is_invalid || addr + offset + dsize > tree->size) { \
POST_SEM (); \
bound_warning("%p is outside of the region (0x%lx..0x%lx)", \
p + offset, (long)tree->start, \
bound_warning("%p (size %d) is outside of the region " \
"(0x%lx..0x%lx)", \
p + offset, dsize, (long)tree->start, \
(long)(tree->start + tree->size - 1)); \
if (never_fatal <= 0) \
return INVALID_POINTER; /* return an invalid pointer */ \

View File

@ -1,2 +1,2 @@
126_bound_global.c:11: at main: BCHECK: ........ is outside of the region (..................)
126_bound_global.c:11: at main: BCHECK: ........ (size 4) is outside of the region (..................)
126_bound_global.c:11: at main: RUNTIME ERROR: invalid memory access

View File

@ -21,9 +21,17 @@ double scale(double d)
return x.d;
}
void mul(double *p)
{
*p *= 2.0;
}
int
main(void)
{
double d = 4.0;
printf("%g\n", scale(42));
mul(&d);
printf("%g\n", d);
return 0;
}

View File

@ -1 +1,2 @@
42000
8

View File

@ -120,6 +120,7 @@ ST_FUNC void gen_struct_copy(int size);
ST_DATA const char * const target_machine_defs =
"__x86_64__\0"
"__x86_64\0"
"__amd64__\0"
;
@ -2020,6 +2021,7 @@ void gen_opf(int op)
gv(RC_FLOAT);
vswap();
fc = vtop->c.i; /* bcheck may have saved previous vtop[-1] */
r = vtop->r;
}
if ((ft & VT_BTYPE) == VT_DOUBLE) {