[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
Wed Apr 12 08:00:37 PDT 2023
mstorsjo created this revision.
mstorsjo added reviewers: phosek, alvinhochun, vitalybuka.
Herald added subscribers: Enna1, pengfei, dberris.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.
In mingw mode on x86, long doubles are 80 bit - while MSVC mode uses
long doubles that are equal to regular doubles (on all architectures).
In the case of this formatting function, we're calling a MS CRT
provided printf function which interprets long doubles as 64 bit.
Since the long doubles are equal to regular doubles on all MSVC
platforms, just use regular double formatting. For MSVC environments
there's no difference, but for mingw environments, this avoids the
ambiguity.
Repository:
rG LLVM Github Monorepo
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.512835.patch
Type: text/x-patch
Size: 936 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230412/f5f43a80/attachment.bin>
More information about the llvm-commits
mailing list