[LLVMbugs] [Bug 14038] New: Floating point literals not pretty printed correctly

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Oct 7 07:59:40 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=14038

             Bug #: 14038
           Summary: Floating point literals not pretty printed correctly
           Product: clang
           Version: 3.1
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: grzejabl at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Floating point literals are not pretty-printed correctly - they have no
appropriate suffix and if they have no fractional parts, they are printed as
integers. I propose the following fix for that:

--- StmtPrinter.cpp.org 2012-10-07 16:32:27.230756541 +0200
+++ StmtPrinter.cpp     2012-10-07 16:44:05.038769708 +0200
@@ -726,6 +726,12 @@
   SmallString<16> Str;
   Node->getValue().toString(Str);
   OS << Str;
+  if(Str.find('.') == llvm::StringRef::npos)
+    OS<<".0";
+  if(Node->getType()->getAs<BuiltinType>()->getKind() == BuiltinType::Float)
+    OS<<"f";
+  if(Node->getType()->getAs<BuiltinType>()->getKind() ==
BuiltinType::LongDouble)
+    OS<<"l";
 }

 void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) {

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list