Generate valid code for "dereferencing" pointers to void.

This covers code like the following, which is very dubious but does not seem to be clearly prohibited by the standards:

int main(void) {
        void *vp;
        *vp;
}

Previously, this would do an indirect load of a four-byte value at the location, but then treat it as void. This could lead to the four-byte value being left on the stack, eventually causing a crash. Now we just evaluate the pointer expression (in case it has side effects), but effectively cast it to void without dereferencing it.
This commit is contained in:
Stephen Heumann 2022-07-12 18:34:58 -05:00
parent 417fd1ad9c
commit 63d33b47bf
1 changed files with 1 additions and 1 deletions

View File

@ -4564,7 +4564,7 @@ case tree^.token.kind of
isVolatile := tqVolatile in lType^.qualifiers;
if lType^.kind = scalarType then
if lType^.baseType = cgVoid then
Gen2t(pc_ind, ord(isVolatile), 0, cgULong)
Gen2(pc_cnv, cgULong, cgVoid)
else
Gen2t(pc_ind, ord(isVolatile), 0, lType^.baseType)
else if lType^.kind = pointerType then