Skip to content

Commit 14d663e

Browse files
committed
cast-conv-ptr: add -w funcptr option
- '-w funcptr' check function pointer casts inside CAST()/CPTR() - '-w constness' implies '-w funcptr' - AST_CONVOPT_DONTWARNFUNCPTR conversion option
1 parent dc958cb commit 14d663e

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

src/compiler/ast-node-conv.bas

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -492,22 +492,36 @@ function astNewCONV _
492492

493493
n->cast.convconst = ( symbCheckConstAssign( to_dtype, ldtype, to_subtype, l->subtype, , , wrnmsg ) = FALSE )
494494

495+
'' -w funcptr -w constness
496+
'' no no don't warn anything
497+
'' yes yes warn everything
498+
'' yes no warn if wrnmsg<>0
499+
'' no yes warn everything (-w constness implies -w funcptr)
500+
495501
'' else check if const conversion
496502
if( n->cast.convconst ) then
497-
if( (options and AST_CONVOPT_DONTWARNCONST) = 0 ) then
498-
if( fbPdCheckIsSet( FB_PDCHECK_CONSTNESS ) ) then
499-
'' specific warning message takes priority over const warning
500-
if( wrnmsg = 0 ) then
501-
wrnmsg = FB_WARNINGMSG_CONSTQUALIFIERDISCARDED
503+
504+
'' wrnmsg is <> 0 only if funcptr check failed
505+
'' specific warning message takes priority over const warning
506+
if( wrnmsg <> 0 ) then
507+
if( (options and AST_CONVOPT_DONTWARNFUNCPTR) = 0 ) then
508+
errReportWarn( wrnmsg )
509+
end if
510+
511+
'' else, must be const warning
512+
else
513+
514+
if( (options and AST_CONVOPT_DONTWARNCONST) = 0 ) then
515+
if( fbPdCheckIsSet( FB_PDCHECK_CONSTNESS ) ) then
516+
errReportWarn( FB_WARNINGMSG_CONSTQUALIFIERDISCARDED )
502517
end if
503518
end if
519+
504520
end if
521+
505522
end if
506523

507-
'' warning? show it now
508-
if( wrnmsg <> 0 ) then
509-
errReportWarn( wrnmsg )
510-
end if
524+
511525
end if
512526

513527
if( env.clopt.backend = FB_BACKEND_GAS ) then

src/compiler/ast.bi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ enum AST_CONVOPT
531531
AST_CONVOPT_PTRONLY = &h4
532532
AST_CONVOPT_DONTCHKPTR = &h8
533533
AST_CONVOPT_DONTWARNCONST = &h10
534+
AST_CONVOPT_DONTWARNFUNCPTR = &h20
534535
end enum
535536

536537
declare function astNewCONV _

src/compiler/fb.bi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,12 @@ enum FB_PDCHECK
106106
FB_PDCHECK_NEXTVAR = &h00000008
107107
FB_PDCHECK_CASTTONONPTR = &h00000010
108108
FB_PDCHECK_SIGNEDNESS = &h00000020
109-
FB_PDCHECK_CONSTNESS = &h00000040
109+
FB_PDCHECK_CASTFUNCPTR = &h00000040
110+
FB_PDCHECK_CONSTNESS = &h00000080
110111

111112
FB_PDCHECK_ALL = &hffffffff
112113

113-
FB_PDCHECK_DEFAULT = FB_PDCHECK_ALL xor ( FB_PDCHECK_NEXTVAR or FB_PDCHECK_SIGNEDNESS or FB_PDCHECK_CONSTNESS )
114+
FB_PDCHECK_DEFAULT = FB_PDCHECK_ALL xor ( FB_PDCHECK_NEXTVAR or FB_PDCHECK_SIGNEDNESS or FB_PDCHECK_CASTFUNCPTR or FB_PDCHECK_CONSTNESS )
114115
end enum
115116

116117
'' cpu types

src/compiler/fbc.bas

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,10 @@ private sub handleOpt(byval optid as integer, byref arg as string)
18421842
fbSetOption( FB_COMPOPT_PEDANTICCHK, _
18431843
fbGetOption( FB_COMPOPT_PEDANTICCHK ) or FB_PDCHECK_CONSTNESS )
18441844

1845+
case "funcptr"
1846+
fbSetOption( FB_COMPOPT_PEDANTICCHK, _
1847+
fbGetOption( FB_COMPOPT_PEDANTICCHK ) or FB_PDCHECK_CASTFUNCPTR )
1848+
18451849
case "pedantic"
18461850
fbSetOption( FB_COMPOPT_PEDANTICCHK, FB_PDCHECK_DEFAULT )
18471851
value = -1

src/compiler/parser-expr-unary.bas

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ private function hCast( byval options as AST_CONVOPT ) as ASTNODE ptr
362362
end if
363363

364364
options or= AST_CONVOPT_CHECKSTR
365+
366+
'' -w constness implies -w funcptr
367+
if( (fbPdCheckIsSet( FB_PDCHECK_CASTFUNCPTR ) = FALSE) _
368+
and (fbPdCheckIsSet( FB_PDCHECK_CONSTNESS ) = FALSE) ) then
369+
options or= AST_CONVOPT_DONTWARNFUNCPTR
370+
end if
371+
365372
expr = astNewCONV( dtype, subtype, expr, options, @errmsg )
366373
if( expr = NULL ) then
367374
if( errmsg = FB_ERRMSG_OK ) then

src/compiler/symb.bas

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,8 +2086,6 @@ function symbCheckConstAssign _
20862086

20872087
dim ret as integer = any
20882088

2089-
wrnmsg = 0 '' FB_WARNINGMSG
2090-
20912089
'' check top-level const
20922090
ret = symbCheckConstAssignTopLevel( ldtype, rdtype, lsubtype, rsubtype, mode, matches )
20932091

0 commit comments

Comments
 (0)