Skip to content

Commit

Permalink
C backend: Fix gcc warning due to mismatching pointer types in initia…
Browse files Browse the repository at this point in the history
…lizers
  • Loading branch information
dkl committed May 4, 2014
1 parent 3dbafc3 commit dad8fab
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 11 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ Version 0.91.0:
- When passing classes without copy-constructor to a Byval parameter, their Let operator overload was called without initializing/constructing the parameter object first.
- Overload resolution didn't allow up-casting arguments when passing to a CONST parameter (e.g. BYREF AS CONST). This also prevented copy constructors with BYREF AS CONST parameter from being called, when the source object had to be up-casted.
- Copy-constructing or assigning an object from a CONST object didn't work with the implicitly generated copy-constructor or LET overload because they only had BYREF AS MyClass parameters which can't accept CONST objects (instead of calling the copy-constructor or LET overload, a shallow copy was done, which for example caused trouble if the UDT contained dynamic strings requiring a deep copy)
- C backend: A gcc warning was triggered when initializing a global variable with an @addressof expression, taking the address of another global.


Version 0.90.1:
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/ast-node-typeini.bas
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ private function hFlushExprStatic _
if( litsym = NULL ) then
'' offset?
if( astIsOFFSET( expr ) ) then
irEmitVARINIOFS( astGetSymbol( expr ), expr->ofs.ofs )
irEmitVARINIOFS( sym, astGetSymbol( expr ), expr->ofs.ofs )
'' anything else
else
'' different types?
Expand Down
13 changes: 9 additions & 4 deletions src/compiler/ir-hlc.bas
Original file line number Diff line number Diff line change
Expand Up @@ -3187,13 +3187,18 @@ private sub _emitVarIniF( byval sym as FBSYMBOL ptr, byval value as double )
hVarIniSeparator( )
end sub

private sub _emitVarIniOfs( byval sym as FBSYMBOL ptr, byval ofs as longint )
private sub _emitVarIniOfs _
( _
byval sym as FBSYMBOL ptr, _
byval rhs as FBSYMBOL ptr, _
byval ofs as longint _
)

dim as EXPRNODE ptr l = any

l = exprNewOFFSET( sym, ofs )
l = exprNewOFFSET( rhs, ofs )

'' Cast to void* to prevent gcc ptr warnings (FB should handle that)
l = exprNewCAST( typeAddrOf( FB_DATATYPE_VOID ), NULL, l )
l = exprNewCAST( symbGetType( sym ), sym->subtype, l )

ctx.varini += exprFlush( l )
hVarIniSeparator( )
Expand Down
9 changes: 7 additions & 2 deletions src/compiler/ir-llvm.bas
Original file line number Diff line number Diff line change
Expand Up @@ -2063,8 +2063,13 @@ private sub _emitVarIniF( byval sym as FBSYMBOL ptr, byval value as double )
hVarIniSeparator( )
end sub

private sub _emitVarIniOfs( byval sym as FBSYMBOL ptr, byval ofs as longint )
ctx.varini += "TODO offset " + *symbGetMangledName( sym ) + " + " + str( ofs )
private sub _emitVarIniOfs _
( _
byval sym as FBSYMBOL ptr, _
byval rhs as FBSYMBOL ptr, _
byval ofs as longint _
)
ctx.varini += "TODO offset " + *symbGetMangledName( rhs ) + " + " + str( ofs )
hVarIniSeparator( )
end sub

Expand Down
9 changes: 7 additions & 2 deletions src/compiler/ir-tac.bas
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,13 @@ private sub _emitVarIniF( byval sym as FBSYMBOL ptr, byval value as double )
emitVARINIf( symbGetType( sym ), value )
end sub

private sub _emitVarIniOfs( byval sym as FBSYMBOL ptr, byval ofs as longint )
emitVARINIOFS( symbGetMangledName( sym ), ofs )
private sub _emitVarIniOfs _
( _
byval sym as FBSYMBOL ptr, _
byval rhs as FBSYMBOL ptr, _
byval ofs as longint _
)
emitVARINIOFS( symbGetMangledName( rhs ), ofs )
end sub

private sub _emitVarIniStr _
Expand Down
9 changes: 7 additions & 2 deletions src/compiler/ir.bi
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,12 @@ type IR_VTBL
emitVarIniEnd as sub( byval sym as FBSYMBOL ptr )
emitVarIniI as sub( byval sym as FBSYMBOL ptr, byval value as longint )
emitVarIniF as sub( byval sym as FBSYMBOL ptr, byval value as double )
emitVarIniOfs as sub( byval sym as FBSYMBOL ptr, byval ofs as longint )
emitVarIniOfs as sub _
( _
byval sym as FBSYMBOL ptr, _
byval rhs as FBSYMBOL ptr, _
byval ofs as longint _
)

emitVarIniStr as sub _
( _
Expand Down Expand Up @@ -512,7 +517,7 @@ declare function vregDump( byval v as IRVREG ptr ) as string
#define irEmitVARINIEND(sym) ir.vtbl.emitVarIniEnd( sym )
#define irEmitVARINIi(sym, value) ir.vtbl.emitVarIniI( sym, value )
#define irEmitVARINIf(sym, value) ir.vtbl.emitVarIniF( sym, value )
#define irEmitVARINIOFS(sym, ofs) ir.vtbl.emitVarIniOfs( sym, ofs )
#define irEmitVARINIOFS(sym, rhs, ofs) ir.vtbl.emitVarIniOfs( sym, rhs, ofs )
#define irEmitVARINISTR(totlgt, litstr, litlgt) ir.vtbl.emitVarIniStr( totlgt, litstr, litlgt )
#define irEmitVARINIWSTR(totlgt, litstr, litlgt) ir.vtbl.emitVarIniWstr( totlgt, litstr, litlgt )
#define irEmitVARINIPAD(bytes) ir.vtbl.emitVarIniPad( bytes )
Expand Down
18 changes: 18 additions & 0 deletions tests/dim/global-init.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# include "fbcu.bi"

namespace fbc_tests.dim_.global_init

'' -gen gcc regression test: This shouldn't trigger a gcc warning.
dim shared a as integer
dim shared b as integer = @a

sub test cdecl( )
CU_ASSERT( b = @a )
end sub

sub ctor( ) constructor
fbcu.add_suite( "tests/dim/global-init" )
fbcu.add_test( "test", @test )
end sub

end namespace

0 comments on commit dad8fab

Please sign in to comment.