[PATCH] D34873: Fix miscompiled 32bit binaries by mingw

Ivan Donchevskii via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 28 03:41:14 PDT 2017


yvvan updated this revision to Diff 108620.
yvvan added a comment.

Provide a workaround without regression


https://reviews.llvm.org/D34873

Files:
  lib/AST/ExprConstant.cpp


Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -537,7 +537,7 @@
   /// rules.  For example, the RHS of (0 && foo()) is not evaluated.  We can
   /// evaluate the expression regardless of what the RHS is, but C only allows
   /// certain things in certain situations.
-  struct LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) EvalInfo {
+  struct EvalInfo {
     ASTContext &Ctx;
 
     /// EvalStatus - Contains information about the evaluation.
@@ -575,7 +575,13 @@
 
     /// The current array initialization index, if we're performing array
     /// initialization.
-    uint64_t ArrayInitIndex = -1;
+    /// uint64_t value is split into two uint32_t values as a workaround
+    /// to deal with mingw 32-bit miscompilation
+    uint32_t ArrayInitIndex[2] = {static_cast<uint32_t>(-1), static_cast<uint32_t>(-1)};
+
+    uint64_t& GetArrayInitIndex() {
+        return reinterpret_cast<uint64_t&>(ArrayInitIndex[0]);
+    }
 
     /// HasActiveDiagnostic - Was the previous diagnostic stored? If so, further
     /// notes attached to it will also be stored, otherwise they will not be.
@@ -923,12 +929,12 @@
 
     public:
       ArrayInitLoopIndex(EvalInfo &Info)
-          : Info(Info), OuterIndex(Info.ArrayInitIndex) {
-        Info.ArrayInitIndex = 0;
+          : Info(Info), OuterIndex{Info.GetArrayInitIndex()} {
+        Info.GetArrayInitIndex() = 0;
       }
-      ~ArrayInitLoopIndex() { Info.ArrayInitIndex = OuterIndex; }
+      ~ArrayInitLoopIndex() { Info.GetArrayInitIndex() = OuterIndex; }
 
-      operator uint64_t&() { return Info.ArrayInitIndex; }
+      operator uint64_t&() { return Info.GetArrayInitIndex(); }
     };
   };
 
@@ -6973,13 +6979,13 @@
   }
 
   bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E) {
-    if (Info.ArrayInitIndex == uint64_t(-1)) {
+    if (Info.GetArrayInitIndex() == uint64_t(-1)) {
       // We were asked to evaluate this subexpression independent of the
       // enclosing ArrayInitLoopExpr. We can't do that.
       Info.FFDiag(E);
       return false;
     }
-    return Success(Info.ArrayInitIndex, E);
+    return Success(Info.GetArrayInitIndex(), E);
   }
     
   // Note, GNU defines __null as an integer, not a pointer.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34873.108620.patch
Type: text/x-patch
Size: 2305 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170728/b1bf1874/attachment.bin>


More information about the cfe-commits mailing list