Skip to content

Commit 0b98721

Browse files
committed
varargs: cast cva_list pointer types in comparison expressions to quiet gcc warning "comparison of distinct pointer types lacks a cast"
1 parent b2625a1 commit 0b98721

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

0 commit comments

Comments
 (0)