[LLVMdev] Global variable initializer type does not match global variable type

Peter Zotov whitequark at whitequark.org
Wed Jan 9 07:59:06 PST 2013


Hello.

I've managed to create a bitcode file (attached; also available at [1]) 
which produces
a series of identical errors when verified:

| Global variable initializer type does not match global variable type!
| %i.NilClass* @nil

When ran through llvm-dis and recompiled, through, it verifies 
successfully. If I
disassemble it one more time, the result is identical to the first 
disassembly. The
recompiled bitcode file is slightly smaller.

I suspect that the problem is with aggregate type uniqueing. I use 
ruby-llvm bindings,
LLVM 3.2 to generate the file; the following code demonstrates what I 
deem the incorrect
behavior:

    # llvm_ty is an LLVM struct type with 2 elements.
    a, b = llvm_ty.element_types
    # Here, I decompose the type and verify that the types of elements
    # match my expectations:
    p a == @types[Monotype.of(VI::Class)] # true
    p b == emit_class_body_type(klass)    # true

    # I attempt to reconstruct the type using the elements
    # and check if it's still the same.
    p llvm_ty == LLVM::Type.struct([
         @types[Monotype.of(VI::Class)],
         emit_class_body_type(klass)
      ], false)                           # false. Why?

Ruby-LLVM bindings compare underlying LLVM pointers when the Type 
objects are compared
with ==.

The problem manifests itself when the following code contains the 
initializer assignment:

     datum = @llvm.globals.add llvm_ty, name
     datum.initializer = LLVM::ConstantStruct.const([
         emit_object(klass, klass_name).bitcast_to(
             @types[Monotype.of(VI::Class)]),
         LLVM::Constant.null(emit_class_body_type(klass))
     ])

LLVM::ConstantStruct.const eventually calls the LLVMConstStruct method 
with the
appropriate arguments; LLVM::Constant.null corresponds to 
LLVMConstNull.

Any hints are greatly appreciated.

-- 
   WBR, Peter Zotov.

   [1]: http://fehu.whitequark.org/files/gvar-init.bc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.bc
Type: application/octet-stream
Size: 752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130109/7dfa89a9/attachment.obj>


More information about the llvm-dev mailing list