[PATCH] D148133: [compiler-rt] [ubsan] Fix printing of floats in mingw mode

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 13 02:06:32 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGfb012c1eeb50: [compiler-rt] [ubsan] Fix printing of floats in mingw mode (authored by mstorsjo).

Changed prior to commit:
  https://reviews.llvm.org/D148133?vs=512835&id=513112#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148133/new/

https://reviews.llvm.org/D148133

Files:
  compiler-rt/lib/ubsan/ubsan_diag.cpp


Index: compiler-rt/lib/ubsan/ubsan_diag.cpp
===================================================================
--- compiler-rt/lib/ubsan/ubsan_diag.cpp
+++ compiler-rt/lib/ubsan/ubsan_diag.cpp
@@ -214,7 +214,12 @@
       //        printf, and stop using snprintf here.
       char FloatBuffer[32];
 #if SANITIZER_WINDOWS
-      sprintf_s(FloatBuffer, sizeof(FloatBuffer), "%Lg", (long double)A.Float);
+      // On MSVC platforms, long doubles are equal to regular doubles.
+      // In MinGW environments on x86, long doubles are 80 bit, but here,
+      // we're calling an MS CRT provided printf function which considers
+      // long doubles to be 64 bit. Just cast the float value to a regular
+      // double to avoid the potential ambiguity in MinGW mode.
+      sprintf_s(FloatBuffer, sizeof(FloatBuffer), "%g", (double)A.Float);
 #else
       snprintf(FloatBuffer, sizeof(FloatBuffer), "%Lg", (long double)A.Float);
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148133.513112.patch
Type: text/x-patch
Size: 936 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230413/d1aa70af/attachment.bin>


More information about the llvm-commits mailing list