[llvm] r290896 - [ADT] APFloatBase: Prevent collapsing semPPCDoubleDouble and semBogus

Michal Gorny via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 3 08:33:50 PST 2017


Author: mgorny
Date: Tue Jan  3 10:33:50 2017
New Revision: 290896

URL: http://llvm.org/viewvc/llvm-project?rev=290896&view=rev
Log:
[ADT] APFloatBase: Prevent collapsing semPPCDoubleDouble and semBogus

Provide a distinct contents for semBogus and semPPCDoubleDouble in order
to prevent compilers from collapsing them to a single memory address,
while we heavily rely on every semantic having distinct address.

This happens if insecure optimization collapsing identical values is
enabled. As a result, APFloats of semBogus are indistinguishable from
semPPCDoubleDouble -- and whenever the move constructor is used, the old
value beings being incorrectly recognized as a semPPCDoubleDouble.

Since the values in semPPCDoubleDouble are not used anywhere,
we can easily solve this issue via altering the value of one of the
fields and therefore ensuring that the collapse can not occur.

Differential Revision: https://reviews.llvm.org/D28112

Modified:
    llvm/trunk/lib/Support/APFloat.cpp

Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=290896&r1=290895&r2=290896&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Tue Jan  3 10:33:50 2017
@@ -76,8 +76,12 @@ namespace llvm {
      compile-time arithmetic on PPC double-double numbers, it is not able
      to represent all possible values held by a PPC double-double number,
      for example: (long double) 1.0 + (long double) 0x1p-106
-     Should this be replaced by a full emulation of PPC double-double?  */
-  static const fltSemantics semPPCDoubleDouble = {0, 0, 0, 0};
+     Should this be replaced by a full emulation of PPC double-double?
+
+     Note: we need to make the value different from semBogus as otherwise
+     an unsafe optimization may collapse both values to a single address,
+     and we heavily rely on them having distinct addresses.             */
+  static const fltSemantics semPPCDoubleDouble = {-1, 0, 0, 0};
 
   /* There are temporary semantics for the real PPCDoubleDouble implementation.
      Currently, APFloat of PPCDoubleDouble holds one PPCDoubleDoubleImpl as the




More information about the llvm-commits mailing list