-
Notifications
You must be signed in to change notification settings - Fork 103
LLVMModuleFlagBehavior enum values are all off by 1 #178
Description
enums in C# start by assigning 0 by default, but the enum within LLVM native is defined as starting at 1. In the documentation for native LLVM, 1 maps to error, 2 maps to warning, etc. Also, in the native LLVM source code, the exposed enum LLVMModuleFlagBehavior is defined using the internal enum ModFlagBehavior which is defined using 1 as error, 2 as warning, etc. So, all of the values in LLVMSharp's LLVMModuleFlagBehavior enum are off by 1. This isn't caught by existing tests because the tests don't actually test the behavior of linking modules with conflictin flags. They just check that the behavior passed into LLVM native is the same as the one returned (and the off by 1 translation happens in both directions, so they do in fact match).
PR #179 fixes the error and also adds a unit test to make sure that the enums aren't off by 1 by checking that LLVM.ModuleFlagBehaviorWarning doesn't cause an Error (which does happen in the existing version of LLVMSharp). There is a comment at the bottom of the unit test describing a way to improve the test if someone else knows how to implement this.