News:

The Forum Rules and Guidelines
Our forum has Rules and Guidelines. Please, be kind and read them ;).

Compiler warnings

Started by Dwachs, October 24, 2012, 07:10:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dwachs

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?
Parsley, sage, rosemary, and maggikraut.

TurfIt

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]

Dwachs

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 ?

Parsley, sage, rosemary, and maggikraut.

TurfIt


Dwachs

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 ?
Parsley, sage, rosemary, and maggikraut.

Ters

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.

Dwachs

I cannot test as I do not get this clobbered compiler warning (gcc 4.6.2).
Parsley, sage, rosemary, and maggikraut.

TurfIt

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]


Dwachs

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
Parsley, sage, rosemary, and maggikraut.

TurfIt

Attached - probably the optimize.
volatile results in a screen full of errors...

Ters

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.

TurfIt

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!

Ters

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.

TurfIt

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

Ters

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.

Dwachs

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.
Parsley, sage, rosemary, and maggikraut.

TurfIt

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).

Dwachs

Parsley, sage, rosemary, and maggikraut.

Ters

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.

TurfIt

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]

Dwachs

The array-subscript warning should be gone with r6450. These unused variables are used within assertions.
Parsley, sage, rosemary, and maggikraut.