<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi, everyone. I've run into a strange problem generating code that contains the `dispatch_object_t` type. <div><br></div><div>The problem happens when a program does these steps (all with the global LLVMContext): </div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>1. Loads a module (otherModule) that uses `dispatch_object_t`. </div><div><span class="Apple-tab-span" style="white-space:pre"> </span>2. Generates code that calls `dispatch_release`, which takes a `dispatch_object_t` argument, into a module (mainModule). </div><div><span class="Apple-tab-span" style="white-space:pre"> </span>3. Links otherModule into mainModule. </div><div><span class="Apple-tab-span" style="white-space:pre"> </span>4. Generates more code that calls `dispatch_release`. </div><div><br></div><div>In Step 4, the following failure occurs on the `CallInst::Create` call for `dispatch_release`: </div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>Assertion failed: ((i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"), function init, file Instructions.cpp, line 274.</div></div></blockquote><div><br></div><div>This happens because the StructType returned by `mod->getTypeByName("union.dispatch_object_t")` is different between Step 2 and Step 4. According to `Type::dump()`, it is: </div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Step 2: <span class="Apple-tab-span" style="white-space:pre"> </span>%union.dispatch_object_t = type { %struct.dispatch_object_s* }</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Step 4: <span class="Apple-tab-span" style="white-space:pre"> %union.dispatch_object_t = type { %struct.dispatch_object_s.1* }</span></div><div><br></div><div>Code that reproduces the problem is at <a href="http://pastebin.com/pxveBUJa">http://pastebin.com/pxveBUJa</a> and <a href="http://pastebin.com/GDb9n9xA">http://pastebin.com/GDb9n9xA</a>. </div><div><br></div><div>A workaround is to call `StructType::create(mod->getContext(), "union.dispatch_object_t")` before doing Step 1. </div><div><br></div><div>This sounds like what Chris was talking about in his <a href="http://blog.llvm.org/2011/11/llvm-30-type-system-rewrite.html">blog post on the LLVM 3.0 type system</a>, "The Linker 'links' types and retypes IR objects". Except that I would have expected the Linker to recognize that the `dispatch_object_t` type in the loaded module and the generated code are the same. Am I doing something wrong, or is this a bug in LLVM? (I have LLVM 3.1, Mac OS X 10.6.) </div><div><br></div><div>Thanks for your time. </div><div><br></div><div>---</div><div><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Jaymie Strecker</div><div><a href="mailto:jstrecker@kosada.com">jstrecker@kosada.com</a></div><div><br></div></div></span></div></span></span></div></body></html>