<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
>The type you pass to GlobalVariable's constructor for that variable
<div>should be "[10 x %struct.dlist]" because that's what you want storage</div>
<div>for. Then the GlobalVariable itself will be a Constant of type "[10 x</div>
<div>%struct.dlist]*".</div>
<div><br>
</div>
<div>Yes, I verified that this is the case.</div>
<div><br>
</div>
<div>I enabled assertions and the error seems to occur while creating <i>GlobalVariable</i> for both struct dhash and struct dlist.
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>Here is a simpler version of the code causing error:</div>
<div><br>
</div>
<div>//struct dhash</div>
<div>typedef struct dhash{</div>
<div>char* filenm;</div>
<div>int n;</div>
<div>}dhash;</div>
<div><br>
</div>
<div>//create global variable to hold filename string</div>
<div>Constant *filenmInit = ConstantDataArray::getString(M.getContext(), "myfile.txt");</div>
<div>Constant *filenmConst = new GlobalVariable(M, filenmInit->getType(), false,</div>
<div>                                     GlobalVariable::ExternalLinkage, filenmInit, ".filenm");</div>
<div><br>
</div>
<div>//create global variable for int</div>
<div>Constant* intInit = ConstantInt::get(Type::getInt32Ty(M.getContext()), 10);</div>
<div>Constant* intConst = new GlobalVariable(M, intInit->getType(), false,</div>
<div>                                           GlobalVariable::ExternalLinkage, intInit, ".int");</div>
<div><br>
</div>
<div>//create ConstantStruct for each hashtable entry</div>
<div>Constant *dhashInit[] = {filenmConst, intConst};</div>
<div>Constant *dhashConst = ConstantStruct::get(dhashTy, dhashInit);</div>
<div><br>
</div>
<div>Constant* htabInitArr[2];</div>
<div>htabInitArr[0] = dhashConst;</div>
<div>htabInitArr[1] = dhashConst;</div>
<div><br>
</div>
<div>    ArrayType *htabTy = ArrayType::get(dhashTy, 2);</div>
<div>    Constant *htabInit = ConstantArray::get(htabTy, makeArrayRef(htabInitArr,2));</div>
<div>    GlobalVariable *htabConst = new GlobalVariable(M, htabInit->getType(), false,</div>
<div>                                            GlobalVariable::ExternalLinkage, htabInit, "htab");</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>Here is the error message:</div>
<div><br>
</div>
<div>opt: /home/chaitra/llvm-5-src/lib/IR/Constants.cpp:879: llvm::ConstantAggregate::ConstantAggregate(llvm::CompositeType*, llvm::Value::ValueTy, llvm::ArrayRef<llvm::Constant*>): Assertion `V[I]->getType() == T->getTypeAtIndex(I) && "Initializer for composite
 element doesn't match!"' failed.</div>
<div>#0 0x0000000001e558fa (opt+0x1e558fa)</div>
<div>#1 0x0000000001e5366e (opt+0x1e5366e)</div>
<div>#2 0x0000000001e537e2 (opt+0x1e537e2)</div>
<div>#3 0x00007f8a98a55390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)</div>
<div>#4 0x00007f8a977c7438 gsignal /build/glibc-e6zv40/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0</div>
<div>#5 0x00007f8a977c903a abort /build/glibc-e6zv40/glibc-2.23/stdlib/abort.c:91:0</div>
<div>#6 0x00007f8a977bfbe7 __assert_fail_base /build/glibc-e6zv40/glibc-2.23/assert/assert.c:92:0</div>
<div>#7 0x00007f8a977bfc92 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc92)</div>
<div>#8 0x000000000189c982 (opt+0x189c982)</div>
<div>#9 0x000000000189cc7c (opt+0x189cc7c)</div>
<div>#10 0x00000000018a93e0 (opt+0x18a93e0)</div>
<div>#11 0x00000000018a95f3 (opt+0x18a95f3)</div>
<div>#12 0x00007f8a9758e59a iospecns::storage_bitcode::runOnModule(llvm::Module&) (/home/chaitra/Desktop/iospec_test/test/build/proj/libstorage_bitcode.so+0x459a)</div>
<div>#13 0x00000000019473ad (opt+0x19473ad)</div>
<div>#14 0x00000000006db61c (opt+0x6db61c)</div>
<div>#15 0x00007f8a977b2840 __libc_start_main /build/glibc-e6zv40/glibc-2.23/csu/../csu/libc-start.c:325:0</div>
<div>#16 0x0000000000747519 (opt+0x747519)</div>
<div>Stack dump:</div>
<div>0. Program arguments: opt -load /home/chaitra/Desktop/iospec_test/test/build/proj/libstorage_bitcode.so -storage_bitcode</div>
<div>1. Running pass 'storage_bitcode' on module '<stdin>'.</div>
<div>Aborted (core dumped)</div>
<div><br>
</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Chaitra</div>
<br>
<div></div>
</body>
</html>