Compiler warning in cpHastySpace.c

Discuss any Chipmunk bugs here.
Post Reply
pfg2009
Posts: 13
Joined: Fri Aug 13, 2010 12:31 pm
Contact:

Compiler warning in cpHastySpace.c

Post by pfg2009 »

I'm compiling Objective Chipmunk Pro 6.1.1 into a stand-alone library used within an ARC-enabled project in Xcode 4.5.1 with base iOS SDK 6.0. All works well, except the compiler throws a warning about the following piece of code in cpHastySpace.c:

Code: Select all

static inline float32x2_t
v_make(float32_t x, float32_t y)
{
	float32x2_t v;
	v = vset_lane_f32(x, v, 0);  <-- Variable 'v' is uninitialized when used here
	v = vset_lane_f32(y, v, 1);
	
	return v;
}
As far as I can tell, vset_lane_f32 actually initializes portion of the 'v' variable, so the warning seems misplaced. However, it's still annoying and I can't figure out how to fake-initialize type "float32x2_t" to some form of 0 in order to make the warning go away. Any ideas?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Compiler warning in cpHastySpace.c

Post by slembcke »

Hmm. So that function exists because there isn't a direct way to initialize a NEON vector from it's two components. You either have to load it from an integer register (slow), load it from RAM (meaning you need to write it there and read it back, also slow) or make an empty vector and set the components. So it's being initialized fully, but the compiler obviously doesn't know how the intrinsic function works.

I guess you could change the declaration to:
float32x2_t v = {};

Vector initializers like that aren't strictly portable though apparently. It works in GCC and Clang... Which realistically are the only compilers that will touch the code. VisualStudio probably does in case Windows RT ever becomes a real thing. Also, you might want to run the benchmarks. Without looking through the assembly output, I'm not sure if that's going to make it do an extra redundant initialization though (I doubt the compiler knows about that sort of thing given the warning).

Did you enable a new warning that makes that show up? It doesn't show up in my project.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
pfg2009
Posts: 13
Joined: Fri Aug 13, 2010 12:31 pm
Contact:

Re: Compiler warning in cpHastySpace.c

Post by pfg2009 »

I've updated to the latest greatest Chipmunk (6.1.1) and the error started showing up - mostly because this code was new from what I was using before (6.0.3, I think). I'm using the latest Xcode with all the default warnings enabled. I tend not to mess with those settings too much.

Adding the empty initialization made the warning go away. I'm not sure how to check whether the compiler emits a redundant initialization instruction as a result, though. I'll remove that initialization before I ship the binary just to be safe (and live with the warning in the final build).

Thanks for the help!
calin
Posts: 30
Joined: Sat Feb 18, 2012 7:58 am
Contact:

Re: Compiler warning in cpHastySpace.c

Post by calin »

Hi Scott,

Yes there is a new warning enabled called "Uninitialized Variables". I think this defaults to Yes in newer Xcode versions, because you're right, the warning didn't show up before.

Indeed, using float32x2_t v = {}; makes the warning go away, however I don't know if this does an extra redundant initialization or not. Also the same problem exists on line #88 in the same file:

Code: Select all

float32x2_t jtOld; jtOld = vset_lane_f32(con->jtAcc, jtOld, 0); // Variable 'jtOld' is uninitialized when used here
When you get a chance can you please take a look into this and if assigning empty brackets is the solution without any drawbacks, can you please commit these 2 changes?
Thanks! Calin
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Compiler warning in cpHastySpace.c

Post by slembcke »

So I double checked the assembly output for this and it's identical. So the compiler is smart enough to deal with it. I don't think initializing a vector with {} is portable exactly... but it should work on Clang and GCC. That probably covers everybody using Chipmunk Pro anyway.

The fix will be part of the next release.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
calin
Posts: 30
Joined: Sat Feb 18, 2012 7:58 am
Contact:

Re: Compiler warning in cpHastySpace.c

Post by calin »

Thanks Scott!
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests