Possible fix for codegen bug with cond ? func1 : func2

Potential patch attached.

Testcase (currently crashes with clang -emit-llvm):
int a();
int b(int);
int c() {return 1 ? a : b;}

Anyone have any better suggestions for how to fix this?

-Eli

tttt.txt (814 Bytes)

I encountered a very similar bug caused by the same bit of code. In my case the issue was the LHS and RHS having different Objective-C pointer types (e.g. id and NSString*) which AST is treating as equivalent but LLVM regards as incompatible. Your solution seems cleaner than mine (which only handled mismatched pointer types correctly), so I'll revert mine before I send updated versions of the diff to this list (hopefully soon...).

David

Your patch looks good. Pl. apply.
Thanks!

Applied.

-Eli

Should sema be inserting an implicit cast to the common type?

-Chris

I suppose that's a possibility; which way are users outside of codegen
likely to prefer?

-Eli

It would be a nice invariant for the LHS/RHS of ?: to have the same type as the result of the ?:

-Chris

An implicit cast is preferable to other clients (the static analyzer being one of them). It puts the logic of such type munging into a single place, and makes the invariants of the ASTs more logically consistent.

Okay, then I'll back out my codegen patch and re-fix this in Sema.

-Eli