Search Issue Tracker

Fixed in 2022.1.X

Fixed in 2021.2.X

Votes

0

Found in

Issue ID

1354855

Regression

Yes

IL2CPP fails code conversion for Enum.HasFlag case

IL2CPP

-

IL2CPP fails to convert correct IL code that use an enum cast to an object

C:/UnityProjects/EMERGE_Home_Kopie/Library/Bee/artifacts/Android/il2cppOutput/cpp/ThirdParty.cpp:1:
In file included from C:/Program Files/Unity/Hub/Editor/2021.2.0b4/Editor/Data/il2cpp/libil2cpp/pch\pch-cpp.hpp:6:
In file included from C:/Program Files\Unity\Hub\Editor\2021.2.0b4\Editor\Data\il2cpp\libil2cpp\codegen\il2cpp-codegen.h:10:
C:\Program Files\Unity\Hub\Editor\2021.2.0b4\Editor\Data\il2cpp\libil2cpp\codegen\il2cpp-codegen-il2cpp.h(402,23): error: invalid operands to binary expression ('Enum_t2A1A94B24E3B776EEF4E5E485E290BB9D4D072E2 *' and 'Enum_t2A1A94B24E3B776EEF4E5E485E290BB9D4D072E2 *')
return (enumValue & flag) == flag;
~~~~~~~~~ ^ ~~~~
C:\UnityProjects\EMERGE_Home_Kopie\Library\Bee\artifacts\Android\il2cppOutput\cpp\ThirdParty.cpp(7175,14): note: in instantiation of function template specialization 'il2cpp_codegen_enum_has_flag<Enum_t2A1A94B24E3B776EEF4E5E485E290BB9D4D072E2 *>' requested here
bool L_4 = il2cpp_codegen_enum_has_flag(((Enum_t2A1A94B24E3B776EEF4E5E485E290BB9D4D072E2*)CastclassClass((RuntimeObject*)L_1, Enum_t2A1A94B24E3B776EEF4E5E485E290BB9D4D072E2_il2cpp_TypeInfo_var)), ((Enum_t2A1A94B24E3B776EEF4E5E485E290BB9D4D072E2*)CastclassClass((RuntimeObject*)L_3, Enum_t2A1A94B24E3B776EEF4E5E485E290BB9D4D072E2_il2cpp_TypeInfo_var)));
^
1 error generated.

Comments (3)

  1. Whatever560

    Oct 05, 2023 08:17

    Current workaround : p.SomeFunc() & someTernary != 0

  2. Whatever560

    Oct 05, 2023 08:14

    I'd say we also have something going on that is similar on this linq line :
    .Where(p => p.SomeFunc().HasFlag( someTernary ))a

    System.NullReferenceException: Object reference not set to an instance of an object.
    at Unity.IL2CPP.MethodBodyWriter.Unbox(ResolvedTypeInfo type, StackInfo boxedValue)
    at Unity.IL2CPP.MethodBodyWriter.GetOptimizedEnumArgument(StackInfo arg)
    at Unity.IL2CPP.MethodBodyWriter.WriteCustomEnumHasFlag(ResolvedInstruction ins)
    at Unity.IL2CPP.MethodBodyWriter.ProcessCustomOpCode(Node node, InstructionBlock block, ResolvedInstruction ins)
    at Unity.IL2CPP.MethodBodyWriter.ProcessInstruction(Node node, InstructionBlock block, ResolvedInstruction ins)
    at Unity.IL2CPP.MethodBodyWriter.GenerateCodeRecursive(Node node, ReadOnlyDictionary`2 instructionBlocks)
    at Unity.IL2CPP.MethodBodyWriter.Generate()
    at Unity.IL2CPP.CodeWriters.CodeWriterExtensions.WriteMethodWithMetadataInitialization(IGeneratedMethodCodeWriter writer, String methodSignature, Action`2 writeMethodBody, String uniqueIdentifier, MethodReference methodRef, Boolean writingMethodBody)
    at Unity.IL2CPP.MethodWriter.WriteMethodDefinition(AssemblyWriteContext context, IGeneratedMethodCodeWriter writer, MethodReference method)
    at Unity.IL2CPP.SourceWriter.WriteTypesMethods(SourceWritingContext context, IGeneratedMethodCodeWriter writer, TypeWritingInformation& writingInformation, NPath filePath, Boolean writeMarshalingDefinitions)
    at Unity.IL2CPP.SourceWriters.SourceWriterBase`2.WriteItem(StreamWorkItemData`2 data)
    at Unity.IL2CPP.Contexts.Scheduling.Streams.FileLevelParallelStreamManager`3.WorkerWriteItemsToFile(WorkItemData`2 data)
    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.WorkerLoop(Object data)
    UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

  3. notunusual

    Jul 31, 2023 15:06

    We have a seemingly related issue we're seeing with the use of HasFlag and il2cpp. Using 2021.3.15f1.

    Error: IL2CPP error for method 'System.Boolean Jet.HighlightTypeUIOptions::HasTransitionFor(System.Boolean)' in C:/p4/scr/game/client/Assets/Scripts/Jet/Match/Highlight/HighlightUIOptionsData.cs:62
    System.NullReferenceException: Object reference not set to an instance of an object.
    at Unity.IL2CPP.MethodBodyWriter.Unbox(ResolvedTypeInfo type, StackInfo boxedValue)
    at Unity.IL2CPP.MethodBodyWriter.GetOptimizedEnumArgument(StackInfo arg)
    at Unity.IL2CPP.MethodBodyWriter.WriteCustomEnumHasFlag(ResolvedInstruction ins)
    at Unity.IL2CPP.MethodBodyWriter.ProcessCustomOpCode(Node node, InstructionBlock block, ResolvedInstruction ins)
    at Unity.IL2CPP.MethodBodyWriter.ProcessInstruction(Node node, InstructionBlock block, ResolvedInstruction ins)
    at Unity.IL2CPP.MethodBodyWriter.GenerateCodeRecursive(Node node, ReadOnlyDictionary`2 instructionBlocks)
    at Unity.IL2CPP.MethodBodyWriter.Generate()
    at Unity.IL2CPP.CodeWriters.CodeWriterExtensions.WriteMethodWithMetadataInitialization(IGeneratedMethodCodeWriter writer, String methodSignature, Action`2 writeMethodBody, String uniqueIdentifier, MethodReference methodRef, Boolean writingMethodBody)
    at Unity.IL2CPP.MethodWriter.WriteMethodDefinition(AssemblyWriteContext context, IGeneratedMethodCodeWriter writer, MethodReference method)
    at Unity.IL2CPP.SourceWriter.WriteTypesMethods(SourceWritingContext context, IGeneratedMethodCodeWriter writer, TypeWritingInformation& writingInformation, NPath filePath, Boolean writeMarshalingDefinitions)
    at Unity.IL2CPP.SourceWriters.SourceWriterBase`2.WriteItem(StreamWorkItemData`2 data)
    at Unity.IL2CPP.Contexts.Scheduling.Streams.FileLevelParallelStreamManager`3.WorkerWriteItemsToFile(WorkItemData`2 data)
    at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.WorkerLoop(Object data)

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.