[LLVMdev] initializer does not match global variable type.
Chris Lattner
sabre at nondot.org
Tue Oct 17 11:26:17 PDT 2006
On Mon, 16 Oct 2006, Reid Spencer wrote:
>> Maybe I wasn't
>> clear. The "g++" is ordinary vanilla g++, not llvm-g++. Are there
>> any versioning issues with regular g++ compiling llvm2cpp generated
>> C++ files?
Oh, sorry I was confused about what was failing.
> This could be the weak link. llvm2cpp is a relatively new and fairly
> untested addition to the llvm toolsuite. Its purposes are more for
> instruction and example generation than for use in compiling. It is
> entirely possible that llvm2cpp is not generating *exactly* the
> C++ code necessary to recreate your module. This is especially true
> since your source language is Objective-C and that has never been tried
> with llvm2cpp.
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.
As Reid says, llvm2cpp is at best beta-quality, I don't think anyone has
used it for something serious. That said, if you're working on your own
llvm2foo, it can be a useful starting point. Another similar but
different thing which may be more useful and *is* well tested is the LLVM
C backend (lib/Target/CBackend).
-Chris
--
http://nondot.org/sabre/
http://llvm.org/
More information about the llvm-dev
mailing list