Skip to content

Commit 8e8801b

Browse files
committed
cast const ptr: remove some unneeded code
- remove some unneeded paramaters - tidy up changelog.txt This commit is the end point in a series of changes since revision 145c13f. This series of commits relates to errors and warnings on usafe CONST usage with respect to CONST qualifiers, assignments, argument passing, conversions, casting, and overloaded functions (both user and built-in) In general: 1) some unsafe CONST usages are now errors 2) many unsage CONST usages are reported when using '-w constness' compiler warning option #642 Pointer casting allows constness dropping Unsafe statements not reporting any warning or error. The fix probably occurred over several revisions due to several related bugs. Revision numbers below are approximate. In revision approx 7185995, a warning is generated for this unsafe usage but only when '-w constness' warning is specified. Internal implementation was modified in the source revisions following. ``` #pragma constness=true dim as const integer a = 256 *cast( integer ptr, @A ) = 257 '' unsafe, warning with -w constness poke integer, @A, 257 '' unsafe, warning with -w constness ``` In revision 2960949 for bug fix #727, adds CONST qualifiers to prototypes for fb rtlib built-in functions. We get an error due the incompatible and unsafe CONSTs. ``` dim as const integer a = 256 clear a, 0, sizeof(integer) '' unsafe, error print a '' 0 ``` Consider this bug report fixed. Promoting warnings to errors, specifically with CAST, CPTR, STRPTR, etc should be considered a different issue and a new bug ticket. #886 Inconsistent error with BYREF and CAST on CONST variables Fixed approx revision 612162a and on going implementation changes in the following revisions. Fixed by preserving the conversions, even CONST only conversions in the AST tree. For some expressions, there is no symbol associated, so AST needs to preserve the CONSTness of an expression so that it can be correctly type checked later. #801 parser allows more constructs under -exx than without it Fixed at revision 391527e. Requires bug fix #886, and adds and additional code to solve out null pointer where not needed. #880 Overload binary operators do not support covariant arguments Fixed at revision 208fad4. Maybe "changed" is better descriptor. Needs more testing. #727 RTL functions not checking Constness unless marked RTL_CONST All built-in RTL functions now have CONST added, where CONST is applicable. Even though 'BYVAL' and 'BYVAL as CONST' are identical, and the compiler disregards any difference between the two, BYVAL parameters also carry the CONST attribute. The reason is that BYVAL/BYREF conveys one kind of information and CONST/non-CONST conveys another, and there is no harm (that I know of) to be more explicit.
1 parent 64d32f5 commit 8e8801b

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

changelog.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Version 1.06.0
55
- test-suite uses libfbcunit for unit testing framework
66
- SELECT CASE AS CONST respects data type and will show overflow warnings on out-of-range constants
77
- boolean: don't allow NEG unary op '-' on boolean data types
8+
- All fb RTL functions are checked for CONSTness, CONST qualifiers added to fb rtlib built-in prototypes (sf.net #727)
9+
- WSTRING can be a return type, but only for prototypes (DECLARE) and function pointers, this allows getting PROCPTR() of all fb built-in run time functions
810

911
[added]
1012
- -noobjinfo option to disable the writing/reading of compile-time library and other linking options from/to .o and .a files. This also disables the use of fbextra.x (the supplemental linker script) for discarding the .fbctinf sections, which is useful when using the gold linker that doesn't support this kind of linker script.
@@ -15,7 +17,8 @@ Version 1.06.0
1517
- Updated bindings: SDL2 2.0.6, SDL2_image 2.0.1, SDL2_mixer 2.0.1, SDL2_net 2.0.1, SDL2_ttf 2.0.14
1618
- allow overload operator SQR()
1719
- allow [static] shared byref variables to be initialized with byref variable
18-
- warning '-w constness' to enable 'CONST qualifier discarded' warning
20+
- warning '-w constness' to enable 'CONST qualifier discarded' warning on command line
21+
- #pragma constness to enable/disable 'CONST qualifier discarded' warning in source code
1922

2023
[fixed]
2124
- win/d3dx9.bi no longer has a hard-coded #inclib "d3dx9d". d3dx9d.dll is apparently not a generally valid choice. In practice programs have to be linked against d3dx9_33.dll or d3dx9_39.dll, etc.
@@ -68,6 +71,7 @@ Version 1.06.0
6871
- #884: FORMATing dates can deadlock under Unix
6972
- #642, #886: CASTs involving CONST qualifiers solved out too early allowing invalid statements to be compiled
7073
- #801: *@(expr) solved to (expr) did not cleanly remove null ptr checks allowing invalid datatype assignment with -exx. *PTRCHK(@expr) solves to (expr).
74+
- #880: Overload binary operators now support covariant arguments, overloaded procedure resolution changed especially with respect to CONST and non-CONST parameters
7175

7276

7377
Version 1.05.0

src/compiler/ast-node-conv.bas

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -488,22 +488,10 @@ function astNewCONV _
488488
'' Discarding/changing const qualifier bits ?
489489
if( typeIsPtr( ldtype ) and typeIsPtr( to_dtype ) ) then
490490

491-
errmsg = 0
492491
wrnmsg = 0
493492

494-
n->cast.convconst = ( symbCheckConstAssign( to_dtype, ldtype, to_subtype, l->subtype, , , errmsg, wrnmsg ) = FALSE )
493+
n->cast.convconst = ( symbCheckConstAssign( to_dtype, ldtype, to_subtype, l->subtype, , , wrnmsg ) = FALSE )
495494

496-
'' error message takes priority over warning messages
497-
if( (options and AST_CONVOPT_DONTCHKPTR) = 0 ) then
498-
if( errmsg <> FB_ERRMSG_OK ) then
499-
if( perrmsg ) then
500-
*perrmsg = errmsg
501-
end if
502-
astDelTree( n )
503-
exit function
504-
end if
505-
end if
506-
507495
'' else check if const conversion
508496
if( n->cast.convconst ) then
509497
if( (options and AST_CONVOPT_DONTWARNCONST) = 0 ) then

src/compiler/symb.bas

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,9 +1877,7 @@ function symbCheckConstAssignTopLevel _
18771877
byval lsubtype as FBSYMBOL ptr, _
18781878
byval rsubtype as FBSYMBOL ptr, _
18791879
byval mode as FB_PARAMMODE = 0, _
1880-
byref matches as integer = 0, _
1881-
byref errmsg as FB_ERRMSG = 0, _
1882-
byref wrnmsg as FB_WARNINGMSG = 0 _
1880+
byref matches as integer = 0 _
18831881
) as integer
18841882

18851883
dim as integer i = any, lcount = any, rcount = any, rmatches = any
@@ -1979,15 +1977,14 @@ function symbCheckConstAssignTopLevel _
19791977
function = TRUE
19801978
end function
19811979

1982-
function hSymbCheckConstAssignFuncPtr _
1980+
private function hSymbCheckConstAssignFuncPtr _
19831981
( _
19841982
byval ldtype as FB_DATATYPE, _
19851983
byval rdtype as FB_DATATYPE, _
19861984
byval lsubtype as FBSYMBOL ptr, _
19871985
byval rsubtype as FBSYMBOL ptr, _
19881986
byval mode as FB_PARAMMODE = 0, _
19891987
byref matches as integer = 0, _
1990-
byref errmsg as FB_ERRMSG = 0, _
19911988
byref wrnmsg as FB_WARNINGMSG = 0 _
19921989
) as integer
19931990

@@ -1997,6 +1994,10 @@ function hSymbCheckConstAssignFuncPtr _
19971994

19981995
function = FALSE
19991996

1997+
'' TODO
1998+
'' 1) consider also combining (in some way) with symbCalcProcMatch()
1999+
'' 2) the structure of the call is very similar
2000+
'' 3) possibly leading towards a generic type compatibility check
20002001

20012002
assert( typeGetDtOnly( ldType ) = FB_DATATYPE_FUNCTION )
20022003
assert( typeGetDtOnly( rdType ) = FB_DATATYPE_FUNCTION )
@@ -2053,7 +2054,7 @@ function hSymbCheckConstAssignFuncPtr _
20532054
var ls = symbGetSubType( rparam )
20542055
var m = symbGetParamMode( lparam )
20552056

2056-
if( symbCheckConstAssign( l, r, ls, rs, m, , errmsg, wrnmsg ) = FALSE ) then
2057+
if( symbCheckConstAssign( l, r, ls, rs, m, , wrnmsg ) = FALSE ) then
20572058
exit function
20582059
end if
20592060

@@ -2072,22 +2073,28 @@ function symbCheckConstAssign _
20722073
byval rsubtype as FBSYMBOL ptr, _
20732074
byval mode as FB_PARAMMODE = 0, _
20742075
byref matches as integer = 0, _
2075-
byref errmsg as FB_ERRMSG = 0, _
20762076
byref wrnmsg as FB_WARNINGMSG = 0 _
20772077
) as integer
20782078

2079+
'' TODO:
2080+
'' 1) consider combining
2081+
'' - symbCheckConstAssign()
2082+
'' - hSymbCheckConstAssignFuncPtr()
2083+
'' - symbCheckConstAssignTopLevel()
2084+
'' 2) callers of symbCheckConstAssignTopLevel() need to respond to errors
2085+
'' and warnings if calling symbCheckConstAssign() instead
2086+
20792087
dim ret as integer = any
20802088

2081-
errmsg = FB_ERRMSG_OK '' FB_ERRMSG
20822089
wrnmsg = 0 '' FB_WARNINGMSG
20832090

20842091
'' check top-level const
2085-
ret = symbCheckConstAssignTopLevel( ldtype, rdtype, lsubtype, rsubtype, mode, matches, errmsg, wrnmsg )
2092+
ret = symbCheckConstAssignTopLevel( ldtype, rdtype, lsubtype, rsubtype, mode, matches )
20862093

20872094
if( ret ) then
20882095
'' both types function pointer?
20892096
if( ( typeGetDtOnly( ldType ) = FB_DATATYPE_FUNCTION ) and ( typeGetDtOnly( rdType ) = FB_DATATYPE_FUNCTION ) ) then
2090-
ret and= hSymbCheckConstAssignFuncPtr( ldtype, rdtype, lsubtype, rsubtype, mode, matches, errmsg, wrnmsg )
2097+
ret and= hSymbCheckConstAssignFuncPtr( ldtype, rdtype, lsubtype, rsubtype, mode, matches, wrnmsg )
20912098
end if
20922099
end if
20932100

src/compiler/symb.bi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,9 +1878,7 @@ declare function symbCheckConstAssignTopLevel _
18781878
byval lsubtype as FBSYMBOL ptr, _
18791879
byval rsubtype as FBSYMBOL ptr, _
18801880
byval mode as FB_PARAMMODE = 0, _
1881-
byref matches as integer = 0, _
1882-
byref errmsg as FB_ERRMSG = 0, _
1883-
byref wrnmsg as FB_WARNINGMSG = 0 _
1881+
byref matches as integer = 0 _
18841882
) as integer
18851883

18861884
declare function symbCheckConstAssign _
@@ -1891,7 +1889,6 @@ declare function symbCheckConstAssign _
18911889
byval rsubtype as FBSYMBOL ptr, _
18921890
byval mode as FB_PARAMMODE = 0, _
18931891
byref matches as integer = 0, _
1894-
byref errmsg as FB_ERRMSG = 0, _
18951892
byref wrnmsg as FB_WARNINGMSG = 0 _
18961893
) as integer
18971894

0 commit comments

Comments
 (0)