<div>I was reading through TableGen's Record.cpp and found a nasty overly nested `if` situation in resolveTypes. It looks like this:</div><div><br></div><div>if (!T1->typeIsConvertibleTo(T2)) {</div><div>  if (!T2->typeIsConvertibleTo(T1)) {</div>
<div>    // ...</div><div>    // Big long piece of code</div><div>    // ...</div><div>  }</div><div>  return T2;</div><div>}</div><div>return T1;</div><div><br></div><div><br></div><div>Unfortunately, `// Big long piece of code` obscures the fact that these conversion checks actually are returning the wrong values (or so it seems). The goal of resolveTypes is to find a common type that both T1 and T2 convert to. De-nested, the code reads:</div>
<div><br></div><div><br></div><div><div>if (T1->typeIsConvertibleTo(T2))</div><div>  return T1;</div><div>if (T2->typeIsConvertibleTo(T1))</div><div>  return T2;</div></div><div>// ...</div><div>// Big long piece of code</div>
<div>// ...</div><div><br></div><div><br></div><div>which is obviously wrong, since `T1->typeIsConvertibleTo(T2)` means that T1 converts to T2, and hence T2 should be returned. Remarkably, this mix-up has no effect on the generated files or on the tests! I tried to come up with a test that would exercise this, but I couldn't come up with one because AFAIK all of TableGen's conversions are bidirectional, so theoretically we could just perform just one of the if's here.</div>
<div><br></div><div>Anyway, I've attached a patch which un-nests the if's and makes the conversion direction correct (it retains both if's for robustness). There's some ugly duplicated code nearby that I'll take down once I grok it.</div>
<div><br></div><div>--Sean Silva</div>