summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclAttr.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2008-10-16 02:34:03 +0000
committerDaniel Dunbar <daniel@zuster.org>2008-10-16 02:34:03 +0000
commit4290d46bd4b1adf33d5891ef94c00ded0a78f56f (patch)
treeea85d5fb38357175e582e89195420c135c003f2e /clang/lib/Sema/SemaDeclAttr.cpp
parent33332bce173c6eb9c8cdbbabb274836aaea3c3da (diff)
downloadbcm5719-llvm-4290d46bd4b1adf33d5891ef94c00ded0a78f56f.tar.gz
bcm5719-llvm-4290d46bd4b1adf33d5891ef94c00ded0a78f56f.zip
Implement #pragma pack use in structure packing. The general approach
is to encode the state of the #pragma pack stack as an attribute when the structure is declared. - Extend PackedAttr to take an alignment (in bits), and reuse for both __attribute__((packed)) (which takes no argument, instead packing tightly (to "minimize the memory required") and for #pragma pack (which allows specification of the maximum alignment in bytes). __attribute__((packed)) is just encoded as Alignment=1. This conflates two related but different mechanisms, but it didn't seem worth another attribute. - I have attempted to follow the MSVC semantics as opposed to the gcc ones, since if I understand correctly #pragma pack originated with MSVC. The semantics are generally equivalent except when the stack is altered during the definition of a structure; its not clear if anyone does this in practice. See testcase if curious. llvm-svn: 57623
Diffstat (limited to 'clang/lib/Sema/SemaDeclAttr.cpp')
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 3ab0c91cb9c..5c04bf0b922 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -256,7 +256,7 @@ static void HandlePackedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
}
if (TagDecl *TD = dyn_cast<TagDecl>(d))
- TD->addAttr(new PackedAttr());
+ TD->addAttr(new PackedAttr(1));
else if (FieldDecl *FD = dyn_cast<FieldDecl>(d)) {
// If the alignment is less than or equal to 8 bits, the packed attribute
// has no effect.
@@ -266,7 +266,7 @@ static void HandlePackedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
diag::warn_attribute_ignored_for_field_of_type,
Attr.getName()->getName(), FD->getType().getAsString());
else
- FD->addAttr(new PackedAttr());
+ FD->addAttr(new PackedAttr(1));
} else
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored,
Attr.getName()->getName());
OpenPOWER on IntegriCloud