The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: Dwachs on October 24, 2012, 07:10:26 PM

Title: Compiler warnings
Post by: Dwachs on October 24, 2012, 07:10:26 PM
Quote from: TurfIt on October 23, 2012, 02:08:41 PM
Newer GCCs compile ok, but sure spit out a lot of warnings with Squirrel... dereferencing type-punned pointers?? potential clobbered variables?? constantly stripping const??  Any chance of cleaning this up?
I do not have access to newer gcc, but I tried to fix as much as possible (judging from the compile-log of the nightlies). Can you post any compiler warnings still gerenerated due to squirrel stuff?
Title: Re: Compiler warnings
Post by: TurfIt on October 24, 2012, 07:19:32 PM
Looks like you got most of them. Remaining:


script/api/export_besch.cc: In function 'void begin_besch_class(HSQUIRRELVM, const char*, const void* (*)(const char*))':
script/api/export_besch.cc:49:12: warning: unused variable 'res' [-Wunused-variable]

squirrel/squirrel/sqcompiler.cc: In member function 'void SQCompiler::ParseTableOrClass(SQInteger, SQInteger)':
squirrel/squirrel/sqcompiler.cc:961:14: warning: unused variable 'attrs' [-Wunused-variable]

squirrel/squirrel/sqvm.cc: In member function 'bool SQVM::DeleteSlot(const SQObjectPtr&, const SQObjectPtr&, SQObjectPtr&)':
squirrel/squirrel/sqvm.cc:1522:33: warning: cast from type 'const SQObjectPtr*' to type 'SQObject* {aka tagSQObject*}' casts away qualifiers [-Wcast-qual]

squirrel/sqstdlib/sqstdrex.cc: In function 'SQRex* sqstd_rex_compile(const SQChar*, const SQChar**)':
squirrel/sqstdlib/sqstdrex.cc:525:9: warning: variable 'exp' might be clobbered by 'longjmp' or 'vfork' [-Wclobbered]
Title: Re: Compiler warnings
Post by: Dwachs on October 26, 2012, 07:03:06 PM
I think that I got the const-warning. The unused variables are actually used in an assert. Could you try whether the attached diff fixes the clobbered-warning ?

Title: Re: Compiler warnings
Post by: TurfIt on October 26, 2012, 07:52:31 PM
Compiler pacified.
Title: Re: Compiler warnings
Post by: Dwachs on October 27, 2012, 09:05:31 AM
However, code crashes now. Here is another patch. At least the crash is gone, but I do not know what happens to the compiler warnings. Could you please test again ?
Title: Re: Compiler warnings
Post by: Ters on October 27, 2012, 10:33:29 AM
I still don't see how this is any better. Both as a local variable and as a parameter, exp is on the stack. It is possible that declaring exp as volatile might help, according to some quote from longjmp's man page I found.
Title: Re: Compiler warnings
Post by: Dwachs on October 27, 2012, 12:43:45 PM
I cannot test as I do not get this clobbered compiler warning (gcc 4.6.2).
Title: Re: Compiler warnings
Post by: TurfIt on October 27, 2012, 07:03:19 PM
Patch results in return of the warning, and this is with 4.6.2. Uninitialized warning goes away with 4.7.

squirrel/squirrel/sqvm.cc: In member function 'bool SQVM::Execute(SQObjectPtr&, SQInteger, SQInteger, ObjectPtr&, QBool, SQVM::ExecutionType)':
squirrel/squirrel/sqvm.cc:906:15: warning: 'val.tagSQObject::_type' may be used uninitialized in this function [-Wuninitialized]

squirrel/sqstdlib/sqstdrex.cc: In function 'SQRex* sqstd_rex_compile_intern(SQRex*)':
squirrel/sqstdlib/sqstdrex.cc:546:8: warning: argument 'exp' might be clobbered by 'longjmp' or 'vfork' [-Wclobbered]

Title: Re: Compiler warnings
Post by: Dwachs on October 27, 2012, 07:07:05 PM
How do you manage to get this clobbered warning??? Can you please post your config.default ?

Can you test, whether setting exp at line 524 of squirrel/sqstdlib/sqstdrex.cc to 'volatile' instead of 'static' helps? (No crashes when loading a scenario, no compiler warnings).

Edit: it does not even compile with 'volatile' :P
Title: Re: Compiler warnings
Post by: TurfIt on October 27, 2012, 07:13:58 PM
Attached - probably the optimize.
volatile results in a screen full of errors...
Title: Re: Compiler warnings
Post by: Ters on October 27, 2012, 07:25:02 PM
I don't get any clobber warnings either. It is possible that it's not the compiler version that causes this warning, but the version of the header file that declares setjmp/longjmp. If the function isn't marked with the proper attribute, GCC won't know that it's behaviour is potentially problematic.
Title: Re: Compiler warnings
Post by: TurfIt on October 27, 2012, 07:31:53 PM
I presume then you're both using Linux as opposed to MinGW? Could very well be a MinGW issue... or maybe no issue at all. The real question - is the code that results in the warning valid/correct? difference between might be clobbered and is clobbered!
Title: Re: Compiler warnings
Post by: Ters on October 27, 2012, 09:53:42 PM
I'm using MingW, but my setjmp.h doesn't tag setjmp (_setjmp actually) as returning twice, which apparently is what would trigger this warning. longjmp is however tagged as never returning.
Title: Re: Compiler warnings
Post by: TurfIt on October 27, 2012, 10:01:24 PM
Is your MinGW setjmp.h different from mine?
Which is:

__MINGW32_VERSION           3.20
__MINGW32_MAJOR_VERSION     3
__MINGW32_MINOR_VERSION     20
__MINGW32_PATCHLEVEL        0
Title: Re: Compiler warnings
Post by: Ters on October 27, 2012, 10:57:41 PM
They look the same. Yours doesn't tag setjmp either, so I don't see why GCC would emit those warnings. I've never seen it pay attention to function name alone.

But I checked setjmp.h in my rarely used mingw64 installation. There setjmp is tagged with returns_twice.
Title: Re: Compiler warnings
Post by: Dwachs on November 04, 2012, 07:43:12 PM
I reverted the change in r6009, so we are back at the start with respect to this clobbered warning. In my eyes, the code is correct as the variable, the compiler warns about, is not changed after assignment. I must confess that I do not understand this clobbered/setjmo business.
Title: Re: Compiler warnings
Post by: TurfIt on November 04, 2012, 07:52:08 PM
Actually not back at the start. You added 'const' when reverting, which also shuts the compiler up. I never would of thought to try that! Squirrel warnings all gone (except the unused debugging stuff).
Title: Re: Compiler warnings
Post by: Dwachs on November 04, 2012, 08:19:05 PM
:)
Title: Re: Compiler warnings
Post by: Ters on November 04, 2012, 08:44:44 PM
I find it a bit disappointing that the compiler couldn't tell that itself. It's a local variable, so no one else can mess with it.
Title: Re: Compiler warnings
Post by: TurfIt on April 13, 2013, 05:11:13 AM
Squirrel's being naughty again...


script/api/api_map_objects.cc: In instantiation of 'void begin_ding_class(HSQUIRRELVM, const char*, const char*) [with D = baum_t; HSQUIRRELVM = SQVM*]':
script/api/api_map_objects.cc:188:55:   required from here
script/api/api_map_objects.cc:141:12: warning: unused variable 'res' [-Wunused-variable]
script/api/api_map_objects.cc: In instantiation of 'void begin_ding_class(HSQUIRRELVM, const char*, const char*) [with D = gebaeude_t; HSQUIRRELVM = SQVM*]':
script/api/api_map_objects.cc:201:63:   required from here
script/api/api_map_objects.cc:141:12: warning: unused variable 'res' [-Wunused-variable]
script/api/api_map_objects.cc: In instantiation of 'void begin_ding_class(HSQUIRRELVM, const char*, const char*) [with D = weg_t; HSQUIRRELVM = SQVM*]':
script/api/api_map_objects.cc:241:53:   required from here
script/api/api_map_objects.cc:141:12: warning: unused variable 'res' [-Wunused-variable]
script/api/api_map_objects.cc: In function 'SQInteger script_api::generic_squirrel_callback(HSQUIRRELVM) [with F  stadt_t* (gebaeude_t::*)()const; SQInteger =int; HSQUIRRELVM = SQVM*]':
script/api/api_map_objects.cc:36:3: warning: array subscript is above array bounds [-Warray-bounds]
script/api/api_map_objects.cc: In function 'SQInteger script_api::generic_squirrel_callback(HSQUIRRELVM) [with F  bool (weg_t::*)()const; SQInteger = int; HSQUIRRELVM = SQVM*]':
script/api/api_map_objects.cc:36:3: warning: array subscript is above array bounds [-Warray-bounds]
script/api/api_map_objects.cc: In function 'SQInteger script_api::generic_squirrel_callback(HSQUIRRELVM) [with F  int (gebaeude_t::*)()const; SQInteger = int;HSQUIRRELVM = SQVM*]':
script/api/api_map_objects.cc:36:3: warning: array subscript is above array bounds [-Warray-bounds]
script/api/api_map_objects.cc: In function 'SQInteger script_api::generic_squirrel_callback(HSQUIRRELVM) [with F = fabrik_t* (gebaeude_t::*)()const; SQInteger = int; HSQUIRRELVM = SQVM*]':
script/api/api_map_objects.cc:36:3: warning: array subscript is above array bounds [-Warray-bounds]
script/api/api_map_objects.cc: In function 'SQInteger script_api::generic_squirrel_callback(HSQUIRRELVM) [with F  bool (gebaeude_t::*)()const; SQInteger = int; HSQUIRRELVM = SQVM*]':
script/api/api_map_objects.cc:36:3: warning: array subscript is above array bounds [-Warray-bounds]
script/api/api_map_objects.cc: In static member function 'static gebaeude_t* script_api::param<gebaeude_t*>::get(HSQUIRRELVM, SQInteger)':
script/api/api_map_objects.cc:36:3: warning: array subscript is above array bounds [-Warray-bounds]
script/api/api_map_objects.cc: In static member function 'static weg_t* script_api::param<weg_t*>::get(HSQUIRRELVM, SQInteger)':
script/api/api_map_objects.cc:36:3: warning: array subscript is above array bounds [-Warray-bounds]
script/api/api_map_objects.cc: In function 'void export_map_objects(HSQUIRRELVM)':
script/api/api_map_objects.cc:144:2: warning: array subscript is above array bounds [-Warray-bounds]
Title: Re: Compiler warnings
Post by: Dwachs on April 13, 2013, 08:21:13 AM
The array-subscript warning should be gone with r6450. These unused variables are used within assertions.