Anderson, Todd A
2006-Oct-17 21:50 UTC
[LLVMdev] initializer does not match global variable type.
>Right. This looks like it's just a simple bug in llvm2cpp. >CppWriter.cpp:698 contains: > > if (CA->isString() && CA->getType()->getElementType() == >Type::SByteTy) { > Out << "Constant* " << constName << " = ConstantArray::get(\""; > printEscapedString(CA->getAsString()); > // Determine if we want null termination or not. > if (CA->getType()->getNumElements() <= >CA->getAsString().length()) > Out << "\", false";// No null terminator > else > Out << "\", true"; // Indicate that the null >terminator should be added. > Out << ");"; > } else { > >This doesn't handle null terminated strings right (the "<=" check is >wrong) and could never handle strings (or other arrays) with >nulls in the >middle of them. Try removing that chunk of code and seeing if >the 'else' >block works.Making this change removed the error statements that I was initially receiving. However, I thought that if you compiled the output of llvm2cpp and ran it you should get the same output as if you compiled and ran the objective-c file directly. Instead, I still get the following when I try to run the compiled C++ file. Is there some sort of option or step in the process I'm missing? ; ModuleID = 'bar.bc' target endian = little target pointersize = 32 target triple = "i686-pc-linux-gnu" deplibs = [ "objc", "c", "crtend" ] %struct._objc_module = type { int, int, sbyte*, %struct._objc_symtab* } %struct._objc_selector = type { sbyte*, sbyte* } %struct._objc_symtab = type { int, %struct._objc_selector**, short, short, [2 x sbyte*] } %struct.objc_class = type { %struct.objc_class*, %struct.objc_class*, sbyte*, int, uint, int, %struct.objc_ivar_list*, %struct.objc_method_list*, %struct.sarray*, %struct.objc_class*, %struct.objc_class*, %struct.objc_protocol_list*, sbyte* } %struct.objc_ivar_list = type opaque %struct.objc_method_list = type opaque %struct.objc_object = type { %struct.objc_class* } %struct.objc_protocol_list = type opaque %struct.sarray = type opaque %llvm.global_ctors = appending global [1 x { int, void ()* }] [ { int, void ()* } { int 65535, void ()* %_GLOBAL__I_main } ] ; <[1 x { int, void ()* }]*> [#uses=0] %.str_2 = internal constant [13 x sbyte] c"Hello world\0A\00" ; <[13 x sbyte]*> [#uses=1] %.str_3 = internal constant [9 x sbyte] c"Fraction\00" ; <[9 x sbyte]*> [#uses=1] %.str_4 = internal constant [2 x sbyte] c"\0A\00" ; <[2 x sbyte]*> [#uses=1] %_OBJC_SELECTOR_TABLE = internal global [6 x %struct._objc_selector] zeroinitializer ; <[6 x %struct._objc_selector]*> [#uses=5] %_OBJC_MODULES = internal global %struct._objc_module zeroinitializer ; <%struct._objc_module*> [#uses=1] %__objc_class_name_Fraction = constant uint 0 ; <uint*> [#uses=0] implementation ; Functions: declare int %printf(sbyte*, ...) declare %struct.objc_object* %objc_get_class(sbyte*) int %main(int %argc, sbyte** %argv) { entry: tail call void %__main( ) %tmp.0 = tail call int (sbyte*, ...)* %printf( sbyte* getelementptr ([13 x sbyte]* %.str_2, int 0, int 0) ) ; <int> [#uses=0] %tmp.5 = tail call %struct.objc_object* %objc_get_class( sbyte* getelementptr ([9 x sbyte]* %.str_3, int 0, int 0) ) ; <%struct.objc_object*> [#uses=2] %tmp.3 = tail call %struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)* (%struct.objc_object*, %struct._objc_selector*)* %objc_msg_lookup( %struct.objc_object* %tmp.5, %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* %_OBJC_SELECTOR_TABLE, int 0, int 0) ) ; <%struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)*> [#uses=1] %tmp.10 = tail call %struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)* %tmp.3( %struct.objc_object* %tmp.5, %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* %_OBJC_SELECTOR_TABLE, int 0, int 0) ) ; <%struct.objc_object*> [#uses=2] %tmp.2 = tail call %struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)* (%struct.objc_object*, %struct._objc_selector*)* %objc_msg_lookup( %struct.objc_object* %tmp.10, %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* %_OBJC_SELECTOR_TABLE, int 0, int 1) ) ; <%struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)*> [#uses=1] %tmp.16 = tail call %struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)* %tmp.2( %struct.objc_object* %tmp.10, %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* %_OBJC_SELECTOR_TABLE, int 0, int 1) ) ; <%struct.objc_object*> [#uses=6] %tmp.20 = tail call %struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)* (%struct.objc_object*, %struct._objc_selector*)* %objc_msg_lookup( %struct.objc_object* %tmp.16, %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* %_OBJC_SELECTOR_TABLE, int 0, int 2) ) ; <%struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)*> [#uses=1] tail call %struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)* %tmp.20( %struct.objc_object* %tmp.16, %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* %_OBJC_SELECTOR_TABLE, int 0, int 2), int 1 ) ; <%struct.objc_object*>:0 [#uses=0] %tmp.29 = tail call %struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)* (%struct.objc_object*, %struct._objc_selector*)* %objc_msg_lookup( %struct.objc_object* %tmp.16, %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* %_OBJC_SELECTOR_TABLE, int 0, int 3) ) ; <%struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)*> [#uses=1] tail call %struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)* %tmp.29( %struct.objc_object* %tmp.16, %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* %_OBJC_SELECTOR_TABLE, int 0, int 3), int 3 ) ; <%struct.objc_object*>:1 [#uses=0] %tmp.38 = tail call %struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)* (%struct.objc_object*, %struct._objc_selector*)* %objc_msg_lookup( %struct.objc_object* %tmp.16, %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* %_OBJC_SELECTOR_TABLE, int 0, int 4) ) ; <%struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)*> [#uses=1] tail call %struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)* %tmp.38( %struct.objc_object* %tmp.16, %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* %_OBJC_SELECTOR_TABLE, int 0, int 4) ) ; <%struct.objc_object*>:2 [#uses=0] %tmp.47 = tail call int (sbyte*, ...)* %printf( sbyte* getelementptr ([2 x sbyte]* %.str_4, int 0, int 0) ) ; <int> [#uses=0] ret int 0 } declare void %__main() declare %struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, ...)* %objc_msg_lookup(%struct.objc_object*, %struct._objc_selector*) internal void %_GLOBAL__I_main() { entry: tail call void %__objc_exec_class( sbyte* cast (%struct._objc_module* %_OBJC_MODULES to sbyte*) ) ret void } declare void %__objc_exec_class(sbyte*)
Chris Lattner
2006-Oct-18 00:02 UTC
[LLVMdev] initializer does not match global variable type.
On Tue, 17 Oct 2006, Anderson, Todd A wrote:> Making this change removed the error statements that I was initially > receiving. However, I thought that if you compiled the output of > llvm2cpp > and ran it you should get the same output as if you compiled and > ran the objective-c file directly.No. llvm2cpp turns an llvm module into the C++ code that will produce the module, it doesn't turn it into C++ code that represents the program.> Instead, I still get the following when I try to run the compiled C++ > file. Is there some sort of option or step in the process I'm missing?You want the C backend as I mentioned before. Try: llc -march=c x.bc -o x.c gcc x.c ./a.out That will run x.bc (assuming you don't need any libraries to link against, etc). -chris> ; ModuleID = 'bar.bc' > target endian = little > target pointersize = 32 > target triple = "i686-pc-linux-gnu" > deplibs = [ "objc", "c", "crtend" ] > %struct._objc_module = type { int, int, sbyte*, > %struct._objc_symtab* } > %struct._objc_selector = type { sbyte*, sbyte* } > %struct._objc_symtab = type { int, %struct._objc_selector**, > short, short, [2 x sbyte*] } > %struct.objc_class = type { %struct.objc_class*, > %struct.objc_class*, sbyte*, int, uint, int, %struct.objc_ivar_list*, > %struct.objc_method_list*, %struct.sarray*, %struct.objc_class*, > %struct.objc_class*, %struct.objc_protocol_list*, sbyte* } > %struct.objc_ivar_list = type opaque > %struct.objc_method_list = type opaque > %struct.objc_object = type { %struct.objc_class* } > %struct.objc_protocol_list = type opaque > %struct.sarray = type opaque > %llvm.global_ctors = appending global [1 x { int, void ()* }] [ { int, > void ()* } { int 65535, void ()* %_GLOBAL__I_main } ] ; <[1 x > { int, void ()* }]*> [#uses=0] > %.str_2 = internal constant [13 x sbyte] c"Hello world\0A\00" > ; <[13 x sbyte]*> [#uses=1] > %.str_3 = internal constant [9 x sbyte] c"Fraction\00" ; <[9 x > sbyte]*> [#uses=1] > %.str_4 = internal constant [2 x sbyte] c"\0A\00" ; <[2 x > sbyte]*> [#uses=1] > %_OBJC_SELECTOR_TABLE = internal global [6 x %struct._objc_selector] > zeroinitializer ; <[6 x %struct._objc_selector]*> [#uses=5] > %_OBJC_MODULES = internal global %struct._objc_module zeroinitializer > ; <%struct._objc_module*> [#uses=1] > %__objc_class_name_Fraction = constant uint 0 ; <uint*> > [#uses=0] > > implementation ; Functions: > > declare int %printf(sbyte*, ...) > > declare %struct.objc_object* %objc_get_class(sbyte*) > > int %main(int %argc, sbyte** %argv) { > entry: > tail call void %__main( ) > %tmp.0 = tail call int (sbyte*, ...)* %printf( sbyte* > getelementptr ([13 x sbyte]* %.str_2, int 0, int 0) ) ; <int> > [#uses=0] > %tmp.5 = tail call %struct.objc_object* %objc_get_class( sbyte* > getelementptr ([9 x sbyte]* %.str_3, int 0, int 0) ) ; > <%struct.objc_object*> [#uses=2] > %tmp.3 = tail call %struct.objc_object* (%struct.objc_object*, > %struct._objc_selector*, ...)* (%struct.objc_object*, > %struct._objc_selector*)* %objc_msg_lookup( %struct.objc_object* %tmp.5, > %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* > %_OBJC_SELECTOR_TABLE, int 0, int 0) ) ; <%struct.objc_object* > (%struct.objc_object*, %struct._objc_selector*, ...)*> [#uses=1] > %tmp.10 = tail call %struct.objc_object* (%struct.objc_object*, > %struct._objc_selector*, ...)* %tmp.3( %struct.objc_object* %tmp.5, > %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* > %_OBJC_SELECTOR_TABLE, int 0, int 0) ) ; <%struct.objc_object*> > [#uses=2] > %tmp.2 = tail call %struct.objc_object* (%struct.objc_object*, > %struct._objc_selector*, ...)* (%struct.objc_object*, > %struct._objc_selector*)* %objc_msg_lookup( %struct.objc_object* > %tmp.10, %struct._objc_selector* getelementptr ([6 x > %struct._objc_selector]* %_OBJC_SELECTOR_TABLE, int 0, int 1) ) > ; <%struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, > ...)*> [#uses=1] > %tmp.16 = tail call %struct.objc_object* (%struct.objc_object*, > %struct._objc_selector*, ...)* %tmp.2( %struct.objc_object* %tmp.10, > %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* > %_OBJC_SELECTOR_TABLE, int 0, int 1) ) ; <%struct.objc_object*> > [#uses=6] > %tmp.20 = tail call %struct.objc_object* (%struct.objc_object*, > %struct._objc_selector*, ...)* (%struct.objc_object*, > %struct._objc_selector*)* %objc_msg_lookup( %struct.objc_object* > %tmp.16, %struct._objc_selector* getelementptr ([6 x > %struct._objc_selector]* %_OBJC_SELECTOR_TABLE, int 0, int 2) ) > ; <%struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, > ...)*> [#uses=1] > tail call %struct.objc_object* (%struct.objc_object*, > %struct._objc_selector*, ...)* %tmp.20( %struct.objc_object* %tmp.16, > %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* > %_OBJC_SELECTOR_TABLE, int 0, int 2), int 1 ) ; > <%struct.objc_object*>:0 [#uses=0] > %tmp.29 = tail call %struct.objc_object* (%struct.objc_object*, > %struct._objc_selector*, ...)* (%struct.objc_object*, > %struct._objc_selector*)* %objc_msg_lookup( %struct.objc_object* > %tmp.16, %struct._objc_selector* getelementptr ([6 x > %struct._objc_selector]* %_OBJC_SELECTOR_TABLE, int 0, int 3) ) > ; <%struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, > ...)*> [#uses=1] > tail call %struct.objc_object* (%struct.objc_object*, > %struct._objc_selector*, ...)* %tmp.29( %struct.objc_object* %tmp.16, > %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* > %_OBJC_SELECTOR_TABLE, int 0, int 3), int 3 ) ; > <%struct.objc_object*>:1 [#uses=0] > %tmp.38 = tail call %struct.objc_object* (%struct.objc_object*, > %struct._objc_selector*, ...)* (%struct.objc_object*, > %struct._objc_selector*)* %objc_msg_lookup( %struct.objc_object* > %tmp.16, %struct._objc_selector* getelementptr ([6 x > %struct._objc_selector]* %_OBJC_SELECTOR_TABLE, int 0, int 4) ) > ; <%struct.objc_object* (%struct.objc_object*, %struct._objc_selector*, > ...)*> [#uses=1] > tail call %struct.objc_object* (%struct.objc_object*, > %struct._objc_selector*, ...)* %tmp.38( %struct.objc_object* %tmp.16, > %struct._objc_selector* getelementptr ([6 x %struct._objc_selector]* > %_OBJC_SELECTOR_TABLE, int 0, int 4) ) ; > <%struct.objc_object*>:2 [#uses=0] > %tmp.47 = tail call int (sbyte*, ...)* %printf( sbyte* > getelementptr ([2 x sbyte]* %.str_4, int 0, int 0) ) ; <int> > [#uses=0] > ret int 0 > } > > declare void %__main() > > declare %struct.objc_object* (%struct.objc_object*, > %struct._objc_selector*, ...)* %objc_msg_lookup(%struct.objc_object*, > %struct._objc_selector*) > > internal void %_GLOBAL__I_main() { > entry: > tail call void %__objc_exec_class( sbyte* cast > (%struct._objc_module* %_OBJC_MODULES to sbyte*) ) > ret void > } > > declare void %__objc_exec_class(sbyte*) > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-Chris -- http://nondot.org/sabre/ http://llvm.org/
Seemingly Similar Threads
- [LLVMdev] initializer does not match global variable type.
- [LLVMdev] Collapse OBJC_CLASSLIST_REFERENCES globals in llvm-link?
- objc object file generated for gnustep runtime for ELF target is too big
- gem for snow leopard?
- [LLVMdev] Hash Table Virtual Calls with Conflict Resolution Stubs