<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jun 10, 2013, at 10:48 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">On Sun, Jun 9, 2013 at 7:54 AM, Andrey Tarasevich<br><<a href="mailto:tarasevich.andrey@gmail.com">tarasevich.andrey@gmail.com</a>> wrote:<br><blockquote type="cite">Hi,<br><br>It is indeed only reachable if I try to print a literal. The following code<br>within a ASTConsumer class triggers the error<br><br>bool TestAstConsumer::HandleTopLevelDecl(clang::DeclGroupRef D)<br>{<br>clang::QualType type = _context->UnsignedCharTy;<br>clang::VarDecl* vd = clang::VarDecl::Create(*_context,<br><br>_context->getTranslationUnitDecl(),<br>                                              clang::SourceLocation(),<br>                                              clang::SourceLocation(),<br>                                              &_context->Idents.get("var"),<br>                                              type,<br>                                              0,<br>                                              clang::SC_None);<br>llvm::APInt* val = new llvm::APInt(_context->getIntWidth(type), 10);<br>clang::Expr* init = clang::IntegerLiteral::Create(*_context,<br>                                                  *val,<br>                                                  type,<br>                                                  clang::SourceLocation());<br>vd->setInit(init);<br>clang::DeclGroupRef *dgr = new (_context) clang::DeclGroupRef(vd);<br>clang::DeclStmt *dst = new (_context) clang::DeclStmt(*dgr,<br>clang::SourceLocation(), clang::SourceLocation());<br>dst->printPretty(llvm::outs(), 0, _context->getPrintingPolicy());<br>}<br><br>and this is the error message I get<br><br>unsigned char var = 10Unexpected type for integer literal!<br>UNREACHABLE executed at<br><path_to_llvm_source>/llvm/tools/clang/lib/AST/StmtPrinter.cpp:730!<br></blockquote><br>You have built a malformed AST; there are no IntegerLiterals of<br>character types. Maybe build a CharacterLiteral instead<br></blockquote><div><br></div><div>Sorry. I found the problem in my code. </div><div>I tried to printPretty following code and it worked fine. </div><div><div><br></div><div>int main()</div><div>{</div><div>    unsigned char a = 10;</div><div>}</div></div><div><br></div><div>Eventually clang treats the '10' literal as a IntegerLiteral and not as a CharacterLiteral and prints it as <span style="font-family: Monaco; font-size: 11px; ">BuiltinType</span><span style="font-family: Monaco; font-size: 11px; ">::</span><span style="font-family: Monaco; font-size: 11px; ">Int. </span></div><div>It means, that I'm using the IntegerLiteral as a correct class in this case, but the type of the IntegerLiteral is wrong. In my example I should use _context->IntTy and not _context-> <br>UnsignedCharTy when I create the IntegerLiteral itself. Then everything works. </div><div><br></div><blockquote type="cite"><blockquote type="cite">On Jun 8, 2013, at 12:32 AM, Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br><br>On Fri, Jun 7, 2013 at 6:39 AM, Andrey Tarasevich<br><<a href="mailto:tarasevich.andrey@gmail.com">tarasevich.andrey@gmail.com</a>> wrote:<br><br>Hello,<br><br>When I'm trying to pretty print statement with type signed or unsigned char<br>I'm getting an error from the StmtPrinter - "Unexpected type for integer<br>literal!". Is this a bug? If yes, then following small patch fixes it. At<br>least in my case it works just fine and statements are printed correctly.<br><br><br>Please provide a test case. This should only be reachable if you try<br>to print a *literal* with type SChar or UChar. How are you building<br>such a literal?<br><br>Cheers,<br>Andrey Tarasevich<br><br>--- StmtPrinter.cpp 2013-06-07 15:17:31.000000000 +0200<br>+++ StmtPrinter.cpp   2013-06-07 15:24:43.000000000 +0200<br>@@ -731,6 +731,8 @@<br>  // FIXME: The Short and UShort cases are to handle cases where a short<br>  // integeral literal is formed during template instantiation.  They should<br>  // be removed when template instantiation no longer needs integer<br>literals.<br>+  case BuiltinType::UChar:<br>+  case BuiltinType::SChar:<br>  case BuiltinType::Short:<br>  case BuiltinType::UShort:<br>  case BuiltinType::Int:       break; // no suffix.<br>_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev<br><br><br></blockquote></blockquote></div><br></body></html>