<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Nov 12, 2014 at 4:10 PM, Anton Korobeynikov <span dir="ltr"><<a href="mailto:anton@korobeynikov.info" target="_blank">anton@korobeynikov.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ok, the reason for objc tests to fail is that we're loosing typedefs when using the type from UsualArithmeticConversions().<br>
<br>
Consider the following code:<br>
<br>
```<br>
typedef long NSInteger;<br>
<br>
int printf(const char * restrict, ...);<br>
<br>
void foo(void) {<br>
NSInteger i = 0;<br>
printf("%s", i ? i : i);<br>
}<br>
```<br>
<br>
AST before was:<br>
<br>
```<br>
`-ConditionalOperator 0x7f9d1086e978 <col:16, col:24> 'NSInteger':'long'<br>
|-ImplicitCastExpr 0x7f9d1086e930 <col:16> 'NSInteger':'long' <LValueToRValue><br>
| `-DeclRefExpr 0x7f9d1086e8b8 <col:16> 'NSInteger':'long' lvalue Var 0x7f9d1086e780 'i' 'NSInteger':'long'<br>
|-ImplicitCastExpr 0x7f9d1086e948 <col:20> 'NSInteger':'long' <LValueToRValue><br>
| `-DeclRefExpr 0x7f9d1086e8e0 <col:20> 'NSInteger':'long' lvalue Var 0x7f9d1086e780 'i' 'NSInteger':'long'<br>
`-ImplicitCastExpr 0x7f9d1086e960 <col:24> 'NSInteger':'long' <LValueToRValue><br>
`-DeclRefExpr 0x7f9d1086e908 <col:24> 'NSInteger':'long' lvalue Var 0x7f9d1086e780 'i' 'NSInteger':'long'<br>
```<br>
<br>
AST now is:<br>
<br>
```<br>
`-ConditionalOperator 0x7ff93a01c178 <col:16, col:24> 'long'<br>
|-ImplicitCastExpr 0x7ff93a01c130 <col:16> 'NSInteger':'long' <LValueToRValue><br>
| `-DeclRefExpr 0x7ff93a01c0b8 <col:16> 'NSInteger':'long' lvalue Var 0x7ff93a01bf80 'i' 'NSInteger':'long'<br>
|-ImplicitCastExpr 0x7ff93a01c148 <col:20> 'NSInteger':'long' <LValueToRValue><br>
| `-DeclRefExpr 0x7ff93a01c0e0 <col:20> 'NSInteger':'long' lvalue Var 0x7ff93a01bf80 'i' 'NSInteger':'long'<br>
`-ImplicitCastExpr 0x7ff93a01c160 <col:24> 'NSInteger':'long' <LValueToRValue><br>
`-DeclRefExpr 0x7ff93a01c108 <col:24> 'NSInteger':'long' lvalue Var 0x7ff93a01bf80 'i' 'NSInteger':'long'<br>
```<br>
<br>
Note that the type of ConditionalOperator changed. Is this expected?</blockquote><div><br></div><div>It's not especially surprising, but not ideal. If the two inputs had the same type sugar, we should probably preserve that sugar. If we had</div><div><br></div><div> NSInteger a; long b;</div><div> auto x = cond ? a : b;</div><div><br></div><div>... it's less clear that we should preserve the sugar. (We used to preserve the sugar from the LHS, which is rather broken.)</div><div><br></div><div>I think it'd be better if CheckPrintfHandler walked into the operands of a ?: to check if they're both NSInteger, if it really wants to care about type sugar.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The special (darwin) case which looks for typedef is inside CheckPrintfHandler::checkFormatExpr()<br>
<br>
<a href="http://reviews.llvm.org/D6217" target="_blank">http://reviews.llvm.org/D6217</a><br>
<br>
<br>
</blockquote></div><br></div></div>