This is an archive of the discontinued LLVM Phabricator instance.

Define a portable macro for specifying packed struct
ClosedPublic

Authored by davidxl on Nov 4 2015, 9:00 AM.

Details

Summary

With the defined the macro, to specify a packed struct in LLVM, one should do

LLVM_PACKED (struct A {

   ...
};)

Diff Detail

Repository
rL LLVM

Event Timeline

davidxl updated this revision to Diff 39213.Nov 4 2015, 9:00 AM
davidxl retitled this revision from to Define a portable macro for specifying packed struct.
davidxl updated this object.
davidxl added a reviewer: rnk.
davidxl added a subscriber: llvm-commits.
rnk accepted this revision.Nov 4 2015, 10:13 AM
rnk edited edge metadata.

lgtm

This revision is now accepted and ready to land.Nov 4 2015, 10:13 AM
davidxl updated this revision to Diff 39244.Nov 4 2015, 12:58 PM
davidxl edited edge metadata.

Updated the patch with two more macros.

The first macro can not be used when we need to include a header file in the struct body (e.g, for common definitions). The START/END pair style can be used instead.

PTAL.

rnk requested changes to this revision.Nov 4 2015, 3:23 PM
rnk edited edge metadata.

GCC and Clang also support packing pragmas, right? I think I'd rather use those so that this code doesn't behave differently:

LLVM_PACKED_START
struct A { ... };
struct B { ... }; // packed in msvc, not gcc/clang
LLVM_PACKED_END
This revision now requires changes to proceed.Nov 4 2015, 3:23 PM
davidxl updated this revision to Diff 39275.Nov 4 2015, 3:34 PM
davidxl edited edge metadata.

Good point about the potential style difference in using the scope based macros.

Updated the patch according to the comment -- using _Pragma keyword for clang and gcc.

rnk accepted this revision.Nov 4 2015, 3:40 PM
rnk edited edge metadata.

lgtm

This revision is now accepted and ready to land.Nov 4 2015, 3:40 PM
This revision was automatically updated to reflect the committed changes.