<div class="gmail_quote">On Thu, Nov 3, 2011 at 2:43 AM, Abramo Bagnara <span dir="ltr"><<a href="mailto:abramo.bagnara@gmail.com">abramo.bagnara@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Il 03/11/2011 00:49, Richard Trieu ha scritto:<br>
<div class="im">> On Wed, Nov 2, 2011 at 4:21 PM, Abramo Bagnara <<a href="mailto:abramo.bagnara@gmail.com">abramo.bagnara@gmail.com</a><br>
</div><div class="im">> <mailto:<a href="mailto:abramo.bagnara@gmail.com">abramo.bagnara@gmail.com</a>>> wrote:<br>
><br>
> Il 03/11/2011 00:16, Richard Trieu ha scritto:<br>
> > On Wed, Nov 2, 2011 at 3:51 PM, Abramo Bagnara<br>
> <<a href="mailto:abramo.bagnara@gmail.com">abramo.bagnara@gmail.com</a> <mailto:<a href="mailto:abramo.bagnara@gmail.com">abramo.bagnara@gmail.com</a>><br>
</div>> > <mailto:<a href="mailto:abramo.bagnara@gmail.com">abramo.bagnara@gmail.com</a><br>
<div><div class="h5">> <mailto:<a href="mailto:abramo.bagnara@gmail.com">abramo.bagnara@gmail.com</a>>>> wrote:<br>
> ><br>
> > Il 02/11/2011 03:21, Richard Trieu ha scritto:<br>
> > > On Mon, Oct 24, 2011 at 7:30 AM, Douglas Gregor<br>
> <<a href="mailto:dgregor@apple.com">dgregor@apple.com</a> <mailto:<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>><br>
> > <mailto:<a href="mailto:dgregor@apple.com">dgregor@apple.com</a> <mailto:<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>>><br>
> > > <mailto:<a href="mailto:dgregor@apple.com">dgregor@apple.com</a> <mailto:<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>><br>
> <mailto:<a href="mailto:dgregor@apple.com">dgregor@apple.com</a> <mailto:<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>>>>> wrote:<br>
> > ><br>
> > ><br>
> > > On Oct 20, 2011, at 5:36 PM, Chandler Carruth wrote:<br>
> > ><br>
> > >> On Thu, Oct 20, 2011 at 5:12 PM, Richard Trieu<br>
> > <<a href="mailto:rtrieu@google.com">rtrieu@google.com</a> <mailto:<a href="mailto:rtrieu@google.com">rtrieu@google.com</a>><br>
> <mailto:<a href="mailto:rtrieu@google.com">rtrieu@google.com</a> <mailto:<a href="mailto:rtrieu@google.com">rtrieu@google.com</a>>><br>
> > >> <mailto:<a href="mailto:rtrieu@google.com">rtrieu@google.com</a> <mailto:<a href="mailto:rtrieu@google.com">rtrieu@google.com</a>><br>
> <mailto:<a href="mailto:rtrieu@google.com">rtrieu@google.com</a> <mailto:<a href="mailto:rtrieu@google.com">rtrieu@google.com</a>>>>> wrote:<br>
> > >><br>
> > >> Should Clang be printing suffixes that are accepted<br>
> only with<br>
> > >> certain flags?<br>
> > >><br>
> > >><br>
> > >> I think this is an interesting policy decision. I'd<br>
> love to hear<br>
> > >> Doug's thoughts on it.<br>
> > >><br>
> > >> It seems fine to me for Clang, when running with<br>
> -fms-extensions,<br>
> > >> to suggest fixes even if only valid for<br>
> -fms-extensions. Clearly<br>
> > >> if there is a generic suggestion that could be made, that<br>
> > would be<br>
> > >> a preferred alternative. For example, '__asm__' should be<br>
> > >> suggested before 'asm'.<br>
> > ><br>
> > > I think it's fine for Clang to print suffixes that are only<br>
> > accepted<br>
> > > with certain flags. Presumably, you should never get an<br>
> > > IntegerLiteral of type __int128_t unless you're in a<br>
> dialect that<br>
> > > supports parsing it.<br>
> > ><br>
> > > … except that we cheat when we're building template<br>
> arguments,<br>
> > > because it was convenient. That cheating could be<br>
> eliminated by<br>
> > > encoding integer literal values directly within<br>
> > > SubstNonTypeTemplateParmExpr.<br>
> > ><br>
> > > - Doug<br>
> > ><br>
> > ><br>
> > > New patch. Changes as follows:<br>
> > > Add int128 and uint128 suffixes (i128 and Ui128) to StmtPrinter.<br>
> > short<br>
> > > and unsigned short will get to llvm_unreachable<br>
> > > Add assert to IntergerLiteral to prevent creation with type<br>
> short or<br>
> > > unsigned short<br>
> > > Fix comment in IntegerLiteral to say that int128 and uint128 are<br>
> > > acceptable types<br>
> > > Change BuildExpressFromIntegralTemplateArgument to give a<br>
> proper Expr.<br>
> > > For negative numbers, use UnaryOperator of IntegerLiteral.<br>
> For short<br>
> > > and unsigned short, ImplicitCastExpr from int.<br>
> ><br>
> > Following this path have you considered how to represent an int<br>
> > parameter with value INT_MIN?<br>
> ><br>
> > I think there is no way you can represent it in standard<br>
> conformant way<br>
> > except to use -INT_MAX - 1 (i.e. -<a href="tel:2147483647" value="+12147483647">2147483647</a> <tel:<a href="tel:2147483647" value="+12147483647">2147483647</a>><br>
</div></div>> <tel:<a href="tel:2147483647" value="+12147483647">2147483647</a> <tel:<a href="tel:2147483647" value="+12147483647">2147483647</a>>> - 1 if<br>
<div class="im">> > int has 32 bits).<br>
> ><br>
> > You cannot use -214783648 because no integer literal of type<br>
> int with<br>
> > value 214783648 can exists.<br>
> ><br>
> ><br>
> > Richard Smith brought up a similar point in the code review<br>
> comments. I<br>
> > am putting in an integer type selector which will move up to larger<br>
> > types until a large enough type can be found. For instance, for<br>
> > int_min, use the negation of a long with a cast back to int.<br>
><br>
> What about when you don't have a larger type? (i.e. the minimum negative<br>
> number of larger signed integral type)<br>
><br>
><br>
> I'm thinking of switching to the unsigned version of that signed type.<br>
> And if that is still not large enough, assert, because there's nothing<br>
> left Clang can do.<br>
<br>
</div>This kind of limitation (and complexity) make me think whether is a<br>
better idea the proposal from Douglas to avoid an ordinary expression<br>
child for SubstNonTypeTemplateParmExpr and instead replace it with either<br>
<br>
- an APInt encapsulated in SubstNonTypeTemplateParmExpr<br>
- a special purpose Expr node for non syntactic integer literal<br>
- a flag in IntegerLiteral to mark it as non-syntactic and to represent<br>
its ability to have arbitrary integral type and signed values<br>
<br>
What do you think about this alternative?</blockquote><div><br></div><div>Sorry, I talked extensively with one Richard about this, and apparently the other (hehe) didn't hear me (my bad). I strongly agree with Doug here. I intensely dislike the abuse of IntegerLiteral here. In particular, I think that these (and other similar constructs) really need dedicated AST types in order to correctly capture their semantics and how they are spelled in the code. Consider, with this we could actually tell the user what expression in the source code was used when (initially) deducing a particular value.</div>
<div><br></div><div>Richard Smith and I sketched out a pretty rough set of AST nodes that would make a lot of sense here. It would also begin making the AST for constant expressions generally more useful and reasonable by making them clearly set off from your average "expression".</div>
<div><br></div><div>Maybe both Richards and Doug can get a game-plan together for such a solution?</div></div>