Skip to content

Commit f35c501

Browse files
authored
Merge pull request #134 from jayrm/varargs
Bug fixes for CVA_LIST PTR types
2 parents 7f241ca + 0b98721 commit f35c501

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

src/compiler/ast-node-check.bas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ function astLoadPTRCHK _
177177
end if
178178

179179
'' assign to a temp, can't reuse the same vreg or registers could
180-
'' be spilled as IR can't handle inter-blocks
181-
t = astNewASSIGN( astNewVAR( n->sym ), l, AST_OPOPT_ISINI )
180+
'' be spilled as IR can't handle inter-blocks.
181+
'' And don't generate pointer warnings for this internal assignment; as
182+
'' in the case where datatypes differ by mangle modifier only.
183+
t = astNewASSIGN( astNewVAR( n->sym ), l, AST_OPOPT_ISINI or AST_OPOPT_DONTCHKPTR )
182184
astLoad( t )
183185
astDelNode( t )
184186

src/compiler/ir-hlc.bas

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,22 @@ private function exprNewBOP _
19571957
'' and on pointers only after casting to ubyte* first,
19581958
'' so no subtype needs to be preserved here.
19591959

1960+
'' if both are pointers, and either has a mangle modifier, then
1961+
'' cast both sides to ubyte*, otherwise, gcc may warn about comparing
1962+
'' distinct pointer types without a cast. For example with pointers
1963+
'' to __builtin_va_list types. AST should have already rejected
1964+
'' invalid comparisons or warned on suspicious comparisons.
1965+
select case as const( op )
1966+
case AST_OP_EQ, AST_OP_NE, AST_OP_GT, AST_OP_LT, AST_OP_GE, AST_OP_LE
1967+
if( typeIsPtr( l->dtype ) and typeIsPtr( r->dtype ) ) then
1968+
if( (typeGetMangleDt( l->dtype ) = FB_DATATYPE_VA_LIST) or _
1969+
(typeGetMangleDt( r->dtype ) = FB_DATATYPE_VA_LIST) ) then
1970+
l = exprNewCAST( typeAddrOf( FB_DATATYPE_UBYTE ), NULL, l )
1971+
r = exprNewCAST( typeAddrOf( FB_DATATYPE_UBYTE ), NULL, r )
1972+
end if
1973+
end if
1974+
end select
1975+
19601976
n = exprNew( EXPRCLASS_BOP, dtype, NULL )
19611977
n->l = l
19621978
n->r = r

src/compiler/parser-decl-var.bas

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ sub hSymbolType _
6565
lgt = typeGetSize( dtype )
6666
end if
6767

68+
'' ANY alias "modifier" but no pointer level?
69+
if( typeHasMangleDt( dtype ) and (typeGetDtAndPtrOnly( dtype ) = FB_DATATYPE_VOID) ) then
70+
errReport( FB_ERRMSG_INVALIDDATATYPES )
71+
'' error recovery: fake a type
72+
dtype = typeAddrOf( dtype )
73+
subtype = NULL
74+
lgt = typeGetSize( dtype )
75+
end if
76+
6877
end sub
6978

7079
function hCheckScope() as integer

tests/dim/dim-bad-datatype-1.bas

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
' TEST_MODE : COMPILE_ONLY_FAIL
2+
3+
dim x as any alias "char"

tests/functions/va_cva_api.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ SUITE( fbc_tests.functions.va_cva_api )
9494

9595
next
9696

97-
cva_end( x1 )
98-
cva_end( x2 )
97+
cva_end( y1 )
98+
cva_end( y2 )
9999

100100
end sub
101101

0 commit comments

Comments
 (0)