[PATCH] D43908: [RecordLayout] Only assert that fundamental type sizes are power of two on MSVC

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 28 13:56:40 PST 2018


mstorsjo created this revision.
mstorsjo added reviewers: efriedma, compnerd.

This fixes using the ms_struct attribute together with long double on e.g. x86-32 linux.


Repository:
  rC Clang

https://reviews.llvm.org/D43908

Files:
  lib/AST/RecordLayoutBuilder.cpp
  test/CodeGen/ms_struct-long-double.c


Index: test/CodeGen/ms_struct-long-double.c
===================================================================
--- /dev/null
+++ test/CodeGen/ms_struct-long-double.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -emit-llvm-only -triple i686-windows-gnu -fdump-record-layouts %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm-only -triple i686-linux -fdump-record-layouts %s | FileCheck %s
+
+struct ldb_struct {
+  char c;
+  long double ldb;
+} __attribute__((__ms_struct__));
+
+struct ldb_struct a;
+
+// CHECK:             0 | struct ldb_struct
+// CHECK-NEXT:        0 |   char c
+// CHECK-NEXT:        4 |   long double ldb
+// CHECK-NEXT:          | [sizeof=16, align=4]
Index: lib/AST/RecordLayoutBuilder.cpp
===================================================================
--- lib/AST/RecordLayoutBuilder.cpp
+++ lib/AST/RecordLayoutBuilder.cpp
@@ -1754,8 +1754,8 @@
         CharUnits TypeSize = Context.getTypeSizeInChars(BTy);
         assert(
             (llvm::isPowerOf2_64(TypeSize.getQuantity()) ||
-             Context.getTargetInfo().getTriple().isWindowsGNUEnvironment()) &&
-            "Non PowerOf2 size outside of GNU mode");
+             !Context.getTargetInfo().getTriple().isWindowsMSVCEnvironment()) &&
+            "Non PowerOf2 size in MSVC mode");
         if (TypeSize > FieldAlign &&
             llvm::isPowerOf2_64(TypeSize.getQuantity()))
           FieldAlign = TypeSize;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43908.136392.patch
Type: text/x-patch
Size: 1406 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180228/25eb0c2a/attachment.bin>


More information about the cfe-commits mailing list