Skip to content

Commit fcb253f

Browse files
authored
Merge pull request #94 from jayrm/cast-conv-ptr
cast-conv-ptr: do not show new function pointer warnings by default - make default warnings same/similar quantity as fb 1.05. New warnings should only be shown when '-w funcptr' or '-w constness' given. - '-w funcptr' will check function pointer casts inside CAST()/CPTR() - '-w funcptr' implies '-w all' - '-w constness' implies '-w funcptr' & '-w all' - new internal AST_CONVOPT_DONTWARNFUNCPTR conversion option to be used from hCast() - the new messages for '-w funcptr' checks are bumped down one level so that they are not generated by default (even though looks a little weird that the warning level is output as (-1), this is correct for now)
2 parents dc958cb + 4dff145 commit fcb253f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+16271
-16235
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, , , strptr(" in function pointer") )
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/error.bas

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ declare function hMakeParamDesc _
8282
( 1, @"" ), _ '' FB_WARNINGMSG_AMBIGIOUSLENSIZEOF
8383
( 0, @"Suspicious logic operation, mixed boolean and non-boolean operands" ), _
8484
( 0, @"Redefinition of intrinsic" ), _
85-
( 0, @"CONST qualifier discarded" ), _
86-
( 0, @"Return type mismatch" ), _
87-
( 0, @"Calling convention mismatch" ), _
88-
( 0, @"Argument count mismatch" ) _
85+
(-1, @"CONST qualifier discarded" ), _
86+
(-1, @"Return type mismatch" ), _
87+
(-1, @"Calling convention mismatch" ), _
88+
(-1, @"Argument count mismatch" ) _
8989
}
9090

9191
dim shared errorMsgs( 1 to FB_ERRMSGS-1 ) as const zstring ptr => _

src/compiler/error.bi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ enum FB_WARNINGMSG
380380
FB_WARNINGMSGS
381381
end enum
382382

383+
const FB_WARNINGMSGS_LOWEST_LEVEL = -1
384+
const FB_WARNINGMSGS_DEFAULT_LEVEL = 0
385+
const FB_WARNINGMSGS_HIGHEST_LEVEL = 2
386+
383387
enum FB_ERRMSGOPT
384388
FB_ERRMSGOPT_NONE = &h00000000
385389
FB_ERRMSGOPT_ADDCOMMA = &h00000001

src/compiler/fb.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ sub fbGlobalInit()
466466
env.clopt.resumeerr = FALSE
467467
env.clopt.profile = FALSE
468468

469-
env.clopt.warninglevel = 0
469+
env.clopt.warninglevel = FB_WARNINGMSGS_DEFAULT_LEVEL
470470
env.clopt.showerror = TRUE
471471
env.clopt.maxerrors = FB_DEFAULT_MAXERRORS
472472
env.clopt.pdcheckopt = FB_PDCHECK_NONE

src/compiler/fb.bi

Lines changed: 4 additions & 3 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
@@ -249,7 +250,7 @@ type FBCMMLINEOPT
249250
profile as integer '' build profiling code (default = false)
250251

251252
'' error/warning reporting behaviour
252-
warninglevel as integer '' (default = 0)
253+
warninglevel as integer '' (default = FB_WARNINGMSGS_DEFAULT_LEVEL)
253254
showerror as integer '' show line giving error (default = true)
254255
maxerrors as integer '' max number errors the parser will show
255256
pdcheckopt as FB_PDCHECK '' pedantic checks

src/compiler/fbc.bas

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,11 +1816,14 @@ private sub handleOpt(byval optid as integer, byref arg as string)
18161816
fbc.showversion = TRUE
18171817

18181818
case OPT_W
1819-
dim as integer value = -2
1819+
dim as integer value = FB_WARNINGMSGS_LOWEST_LEVEL - 1
18201820

18211821
select case (arg)
18221822
case "all"
1823-
value = -1
1823+
value = FB_WARNINGMSGS_LOWEST_LEVEL
1824+
1825+
case "none"
1826+
value = FB_WARNINGMSGS_HIGHEST_LEVEL + 1
18241827

18251828
case "param"
18261829
fbSetOption( FB_COMPOPT_PEDANTICCHK, _
@@ -1841,16 +1844,24 @@ private sub handleOpt(byval optid as integer, byref arg as string)
18411844
case "constness"
18421845
fbSetOption( FB_COMPOPT_PEDANTICCHK, _
18431846
fbGetOption( FB_COMPOPT_PEDANTICCHK ) or FB_PDCHECK_CONSTNESS )
1847+
value = FB_WARNINGMSGS_LOWEST_LEVEL
1848+
1849+
case "funcptr"
1850+
fbSetOption( FB_COMPOPT_PEDANTICCHK, _
1851+
fbGetOption( FB_COMPOPT_PEDANTICCHK ) or FB_PDCHECK_CASTFUNCPTR )
1852+
value = FB_WARNINGMSGS_LOWEST_LEVEL
18441853

18451854
case "pedantic"
18461855
fbSetOption( FB_COMPOPT_PEDANTICCHK, FB_PDCHECK_DEFAULT )
1847-
value = -1
1856+
if( value > FB_WARNINGMSGS_DEFAULT_LEVEL ) then
1857+
value = FB_WARNINGMSGS_DEFAULT_LEVEL
1858+
end if
18481859

18491860
case else
18501861
value = clng( arg )
18511862
end select
18521863

1853-
if( value >= -1 ) then
1864+
if( value >= FB_WARNINGMSGS_LOWEST_LEVEL ) then
18541865
fbSetOption( FB_COMPOPT_WARNINGLEVEL, value )
18551866
end if
18561867

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
no warnings:
22
2 warnings:
33
Suspicious pointer assignment
4-
Calling convention mismatch
4+
Calling convention mismatch in function pointer
55
2 warnings:
66
Suspicious pointer assignment
7-
Calling convention mismatch
7+
Calling convention mismatch in function pointer
88
2 warnings:
99
Suspicious pointer assignment
10-
Calling convention mismatch
10+
Calling convention mismatch in function pointer
1111
2 warnings:
1212
Suspicious pointer assignment
13-
Calling convention mismatch
13+
Calling convention mismatch in function pointer
1414
2 warnings:
1515
Suspicious pointer assignment
16-
Calling convention mismatch
16+
Calling convention mismatch in function pointer
1717
2 warnings:
1818
Suspicious pointer assignment
19-
Calling convention mismatch
19+
Calling convention mismatch in function pointer
2020
2 warnings:
2121
Suspicious pointer assignment
22-
Calling convention mismatch
22+
Calling convention mismatch in function pointer
2323
2 warnings:
2424
Suspicious pointer assignment
25-
Calling convention mismatch
25+
Calling convention mismatch in function pointer
2626
2 warnings:
2727
Suspicious pointer assignment
28-
Calling convention mismatch
28+
Calling convention mismatch in function pointer
2929
2 warnings:
3030
Suspicious pointer assignment
31-
Calling convention mismatch
31+
Calling convention mismatch in function pointer

0 commit comments

Comments
 (0)