Skip to content

Commit

Permalink
varargs: cast __builtin_va_list to (char*); __builtin_memset can't ha…
Browse files Browse the repository at this point in the history
…ndle uninitialized __builtin_va_list directly
  • Loading branch information
jayrm committed Mar 10, 2019
1 parent 4b6e01b commit 5f2cfe4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/compiler/ast-misc.bas
Expand Up @@ -1281,3 +1281,27 @@ function astIsRelationalBop( byval n as ASTNODE ptr ) as integer
function = astOpIsRelational( n->op.op )
end if
end function

function astIsBuiltinValistCarray( byval n as ASTNODE ptr ) as integer
function = FALSE

assert( n <> NULL )

var subtype = astGetSubtype( n )

'' !!! TODO !!!
'' replace this with a faster check

if( subtype ) then
select case typeGetDtOnly( symbGetFullType( subtype ) )
case FB_DATATYPE_STRUCT
if( subtype->id.alias ) then
select case *subtype->id.alias
case "__va_list", "__va_list_tag"
function = TRUE
end select
end if
end select
end if

end function
13 changes: 11 additions & 2 deletions src/compiler/ast-node-mem.bas
Expand Up @@ -35,10 +35,19 @@ function astNewMEM _
'' the adress-of and let emit() do the rest, or if blkmaxlen = 0,
'' then emit() always handles it, even when lgt=0
if( (lgt > blkmaxlen) or (blkmaxlen = 0) ) then
l = astNewADDROF( l )

if( astIsBuiltinValistCarray( l ) ) then
l = astNewDEREF( astNewCONV( typeMultAddrOf( FB_DATATYPE_UBYTE, 2 ), NULL, astNewAddrof( l ) ) )
else
l = astNewADDROF( l )
end if

if( op = AST_OP_MEMMOVE ) then
r = astNewADDROF( r )
if( astIsBuiltinValistCarray( r ) ) then
r = astNewDEREF( astNewCONV( typeMultAddrOf( FB_DATATYPE_UBYTE, 2 ), NULL, astNewAddrof( r ) ) )
else
r = astNewADDROF( r )
end if
end if
end if

Expand Down
1 change: 1 addition & 0 deletions src/compiler/ast.bi
Expand Up @@ -1332,6 +1332,7 @@ declare sub astSetType _
declare function astSizeOf( byval n as ASTNODE ptr, byref is_fixlenstr as integer = FALSE ) as longint
declare function astIsAccessToLocal( byval expr as ASTNODE ptr ) as integer
declare function astIsRelationalBop( byval n as ASTNODE ptr ) as integer
declare function astIsBuiltinValistCarray( byval n as ASTNODE ptr ) as integer

declare function astGetOFFSETChildOfs( byval l as ASTNODE ptr ) as longint

Expand Down

0 comments on commit 5f2cfe4

Please sign in to comment.