[LLVMdev] Is append in APFloat broken?

Olaf Krzikalla Olaf.Krzikalla at tu-dresden.de
Tue Jul 24 03:06:26 PDT 2012


Hi @llvm,

I stumbled over a strange behavior if a float containing a NaN is 
printed (e.g. in the clang rewriter). The local template method "append" 
in APFloat.cpp deduces the size from the char array, which for "NaN" is 
4 (including the trailing zero). If APFloat::toString is called with a 
SmallString and then SmallString::str() is called, it returns "NaN\0". I 
guess that this is not intended. Maybe it can be fixed by the simple 
patch attached.

Best regards
Olaf Krzikalla
-------------- next part --------------
Index: lib/Support/APFloat.cpp
===================================================================
--- lib/Support/APFloat.cpp	(revision 160546)
+++ lib/Support/APFloat.cpp	(working copy)
@@ -3278,16 +3278,10 @@
 }
 
 namespace {
-  static void append(SmallVectorImpl<char> &Buffer,
-                     unsigned N, const char *Str) {
-    unsigned Start = Buffer.size();
-    Buffer.set_size(Start + N);
-    memcpy(&Buffer[Start], Str, N);
-  }
 
   template <unsigned N>
   void append(SmallVectorImpl<char> &Buffer, const char (&Str)[N]) {
-    append(Buffer, N, Str);
+    Buffer.append(Str, Str + N - 1);
   }
 
   /// Removes data from the given significand until it is no more


More information about the llvm-dev mailing list