4.6.3 IL2CPP Xcode build errors

Hello, I just upgraded to 4.6.3 (from 4.6.2) and when I build my project in Xcode I’m greeted with about 20 of the same error:

“error: cast from pointer to smaller type ‘il2cpp_array_size_t’ (aka ‘int’) loses information”

What gives? I had zero issues in 4.6.2. Many thanks.

Any ideas?

I would like to know an answer to this also, we’re seeing this error too. Seems like a bug, I’ve created a fresh Xcode project from Unity and it still happens. IL2CPP but to just a 32-bit build does compile (not that we can submit to Apple with that … but can at least play the game), it’s the 64 bit pointer conversion that’s breaking here.

I’d log a bug with Unity, but getting a repro case of my project down to a reasonable size is not an easy task …

Is this a yellow warning error or red, cannot build Xcode error?

Red.

For example in Bulk_BouncyCastle.Crypto_12.cpp, the parts below highlighted in red give red exclamation marks in Xcode (legitimately, as far as I can see):

{

ByteU5BU5D_t12* L_0 = V_0;

V_3 = L_0;

int32_t L_1 = ((int32_t)(V_1/8));

V_4.___m_value = (void*)L_1;

NullCheck(V_3);

IL2CPP_ARRAY_BOUNDS_CHECK(V_3, (il2cpp_array_size_t)V_4.___m_value);

NullCheck(L_0);

IL2CPP_ARRAY_BOUNDS_CHECK(L_0, L_1);

((uint8_t)(uint8_t*)SZArrayLdElema(L_0, L_1)) = (uint8_t)(((uint8_t)((int32_t)(((uint8_t)(uint8_t*)SZArrayLdElema(V_3, (uint32_t)V_4.___m_value))|(((uint8_t)((int32_t)(1<<((int32_t)(((int32_t)(7-((int32_t)(V_1%8))))&((int32_t)31)))))))))));

}

Yes, these are major errors, not warnings. Xcode won’t build.

Twistplay, just to verify, which version of Unity are you using? This is happening to me on 4.6.3, but it worked perfectly fine in 4.6.2.

Definitely 4.6.3

I’ve tracked down the cause of this problem, and I have corrected it internally. I’ve missed the cut-off for our 4.6.3p1 release, but this fix should land in the 4.6.3p2 release.

In the meantime, you could try to work around the problem by modifying the generated C++ code. Unfortunately, each time you build the project in Unity, these problems will come back. Still to work around the issue, you can try this:

Change:

IL2CPP_ARRAY_BOUNDS_CHECK(V_3, (il2cpp_array_size_t)V_4.___m_value);

to:

IL2CPP_ARRAY_BOUNDS_CHECK(V_3, (il2cpp_array_size_t)(intptr_t)V_4.___m_value);

And change:

(uint32_t)V_4.___m_value)

to:

(uint32_t)(intptr_t)V_4.___m_value)

There will likely be a number of occurrences of this problem though, so maybe some regulart expressions like this might help:

s/**(il2cpp_array_size_t)(.*).___m_value/(il2cpp_array_size_t)(intptr_t)\1.___m_value
s/
(uint32_t)(.*).___m_value/(**uint32_t)(intptr_t)\1.___m_value

The problem here is that clang is pretty strict during a 64-bit compile, not allowing any casts from a pointer (64-bits wide) to a narrower integer type (like a 32-bit int32_t). The fix first casts to a pointer-sized integer type (intptr_t), then casts down to a 32-bit integer.

On the C# side, the code here is using an IntPtr to index into an array (the IntPtr is V_4, in this case). IL2CPP uses a void* (the ___m_value field) to store the value of the IntPtr. Obviously we could be losing something if the IntPtr used to index into the array actually has a value larger than the maximum value for a 32-bit integer. I think that case is pretty unlikely though, so this looks like a good fix.

1 Like

Thanks for the reply. Glad it’s sorted out. There’s a patch release roughly every week, right?

Yes, we’re shipping weekly patch releases. The schedule can and sometimes does slip, but I would expect this fix near the end of next week.

Hi Josh,

This unfortunately does not fix all cases in 4.6.3p2 (but I can confirm the il2cpp_array_size_t errors seem to have gone in that patch)

For example:

uint8_t L_17 = GenArrayGet2(V_24, (int32_t)V_23.___m_value_0, 0, uint8_t);;

Gives the error “Cast from pointer to smaller type ‘int32_t’ (aka ‘int’) loses information”

I’m down to about 5 such errors in our project now …

For reference, the entire generated function looked like this:
IL_0174:

{

ByteU5B0___U2C0___U5D_t2520* L_15 = V_4;

V_24 = L_15;

int32_t L_16 = V_11;

V_23.___m_value_0 = (void*)L_16;

NullCheck(V_24);

uint8_t L_17 = GenArrayGet2(V_24, (int32_t)V_23.___m_value_0, 0, uint8_t);;

IL2CPP_RUNTIME_CLASS_INIT(InitializedTypeInfo(&RijndaelEngine_t2508_il2cpp_TypeInfo));

NullCheck(V_4);

uint8_t L_18 = GenArrayGet2(V_4, ((int32_t)(((int32_t)(V_11+1))%4)), ((int32_t)(V_0-1)), uint8_t);;

NullCheck((((RijndaelEngine_t2508_StaticFields*)InitializedTypeInfo(&RijndaelEngine_t2508_il2cpp_TypeInfo)->static_fields)->___S_4));

IL2CPP_ARRAY_BOUNDS_CHECK((((RijndaelEngine_t2508_StaticFields*)InitializedTypeInfo(&RijndaelEngine_t2508_il2cpp_TypeInfo)->static_fields)->___S_4), ((int32_t)((int32_t)L_18&(int32_t)((int32_t)255))));

int32_t L_19 = ((int32_t)((int32_t)L_18&(int32_t)((int32_t)255)));

NullCheck(L_15);

GenArraySet2(L_15, L_16, 0, (((uint8_t)((int32_t)((int32_t)L_17^(int32_t)((uint8_t)(uint8_t*)SZArrayLdElema((((RijndaelEngine_t2508_StaticFields*)InitializedTypeInfo(&RijndaelEngine_t2508_il2cpp_TypeInfo)->static_fields)->___S_4), L_19)))))), uint8_t);;

V_11 = ((int32_t)(V_11+1));

}

In Bulk_BouncyCastle.Crypto_7.cpp

Adrian

I see the cases that I originally missed now, sorry. Is it possible for you to submit a bug with an example project? I would like to be able to make sure that we don’t miss any other cases with the next fix. Thanks.

Hello Josh,

I have upgraded to 4.6.6p4 (from 4.6.2) and when I build my project in Xcode I’m getting similar issues.
“Member reference base type ‘intptr_t’ (aka ‘long’) is not a structure or union”

32bit build is working fine here.

I attaching the screenshot of the error.

What is the work around for this issue?
Thanks

I am stuck on this issues from last two weeks. latest 4.6.7 is also giving me the same error. anyone can help me on this?

@kingofasgard

Can you submit a bug report on this issue? If you submitted one previously, please let me know the bug report number, and I’ll check on its status. Something here in the IL code is causing IL2CPP to generate bad C++ code, which we need to correct.

I have not reported this issue. I am reporting it now. Thank you.

Hello Josh,
I have reported the bug report number:-
“(Case 709995) We have created 32 bit using Unity 4.6.2 and to now we want to 64bit iOS build. We are getting this issue while compiling in it.”

Many Thanks.

Hello Josh,

Did you got time to look into this?

@kingofasgard

Thanks for submitting this bug. We’ve not yet had a chance to process it, but I’ll ping our QA team to have a look.