Codegen for Character Literals and Conditional Operator

Both in one patch, and the test case that Chris didn't commit last
time is in there too...

I'll split the patch up if somebody wants it split.


CharacterLiteralsAndConditionalOperator.diff (5.57 KB)

Splitting it up is good in that it lets us apply patches independently. I applied the patch, but here are some comments for follow-up:

@@ -291,8 +292,14 @@

  void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
- // FIXME: print value.
- OS << "x";
+ unsigned value = Node->getValue();
+ if (isprint(value)) {
+ OS << "'" << (char)value << "'";
+ } else {
+ // FIXME something to indicate this is a character literal?
+ OS << std::hex << std::setiosflags(std::ios_base::showbase) << value
+ << std::dec << std::resetiosflags(std::ios_base::showbase);
+ }

This should only print the 'x' syntax if the type is 'char'. If it is something else, it should print L'x'.

For the fixme, you could print it as charliteral(0x1235) or something.

Also, your ?: code won't work correctly for structs. That's ok, because structs are completely unimplemented, but please add a fixme.


Attached are patches to fix character literal printing (though there's
still a slightly-less-than-desirable case that maybe should use a \u
escape?) and assert when you try to ?: with an aggregate type, as


CharacterLiteralPrinting.diff (2.75 KB)

ConditionalAggregateAssert.diff (541 Bytes)

Thanks, I applied the first one:

The second one isn't quite right. "Scalar" types in C include complex numbers, which are "aggregate" types according to LLVM (and to the LLVM lowering stuff). The correct predicate would be RValue::isScalar() (which checks to see whether it's an LLVM scalar type).

However, getVal() already checks this, so this is already checked. I don't think it's worth adding another explicit check. I did add this fixme though:

Thanks for the patches!