[PATCH] D43734: [RecordLayout] Don't align to non-power-of-2 sizes when using -mms-bitfields

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 26 22:29:17 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL326173: [RecordLayout] Don't align to non-power-of-2 sizes when using -mms-bitfields (authored by mstorsjo, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D43734?vs=135813&id=136037#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43734

Files:
  cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
  cfe/trunk/test/CodeGen/mingw-long-double.c


Index: cfe/trunk/test/CodeGen/mingw-long-double.c
===================================================================
--- cfe/trunk/test/CodeGen/mingw-long-double.c
+++ cfe/trunk/test/CodeGen/mingw-long-double.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -triple i686-windows-gnu -emit-llvm -o - %s \
 // RUN:    | FileCheck %s --check-prefix=GNU32
+// RUN: %clang_cc1 -triple i686-windows-gnu -emit-llvm -o - %s -mms-bitfields \
+// RUN:    | FileCheck %s --check-prefix=GNU32
 // RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm -o - %s \
 // RUN:    | FileCheck %s --check-prefix=GNU64
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -o - %s \
Index: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
===================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
@@ -1752,7 +1752,12 @@
       QualType T = Context.getBaseElementType(D->getType());
       if (const BuiltinType *BTy = T->getAs<BuiltinType>()) {
         CharUnits TypeSize = Context.getTypeSizeInChars(BTy);
-        if (TypeSize > FieldAlign)
+        assert(
+            (llvm::isPowerOf2_64(TypeSize.getQuantity()) ||
+             Context.getTargetInfo().getTriple().isWindowsGNUEnvironment()) &&
+            "Non PowerOf2 size outside of GNU mode");
+        if (TypeSize > FieldAlign &&
+            llvm::isPowerOf2_64(TypeSize.getQuantity()))
           FieldAlign = TypeSize;
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43734.136037.patch
Type: text/x-patch
Size: 1471 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180227/5b50bcbf/attachment.bin>


More information about the cfe-commits mailing list