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;
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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits