[cfe-commits] r78483 - in /cfe/trunk: include/clang/AST/Attr.h lib/AST/RecordLayoutBuilder.cpp lib/CodeGen/CGRecordLayoutBuilder.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriter.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclAttr.cpp
Anders Carlsson
andersca at mac.com
Sat Aug 8 11:23:56 PDT 2009
Author: andersca
Date: Sat Aug 8 13:23:56 2009
New Revision: 78483
URL: http://llvm.org/viewvc/llvm-project?rev=78483&view=rev
Log:
Introduce a new PragmaPack attribute, and use it for #pragma pack. The PackedAttr now only represents __attribute__((packed)).
This is necessary because #pragma pack and __attribute__((packed)) have different semantics. No functionality change yet, but this lays the groundwork for fixing a record layout bug.
Modified:
cfe/trunk/include/clang/AST/Attr.h
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
cfe/trunk/lib/Frontend/PCHWriter.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=78483&r1=78482&r2=78483&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Sat Aug 8 13:23:56 2009
@@ -70,6 +70,7 @@
NSReturnsRetained, // Clang/Checker-specific.
Overloadable, // Clang-specific
Packed,
+ PragmaPack,
Pure,
Regparm,
ReqdWorkGroupSize, // OpenCL-specific
@@ -146,24 +147,26 @@
static bool classof(const ATTR##Attr *A) { return true; } \
}
-class PackedAttr : public Attr {
+DEF_SIMPLE_ATTR(Packed);
+
+class PragmaPackAttr : public Attr {
unsigned Alignment;
public:
- PackedAttr(unsigned alignment) : Attr(Packed), Alignment(alignment) {}
+ PragmaPackAttr(unsigned alignment) : Attr(PragmaPack), Alignment(alignment) {}
/// getAlignment - The specified alignment in bits.
unsigned getAlignment() const { return Alignment; }
virtual Attr* clone(ASTContext &C) const {
- return ::new (C) PackedAttr(Alignment);
+ return ::new (C) PragmaPackAttr(Alignment);
}
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
- return A->getKind() == Packed;
+ return A->getKind() == PragmaPack;
}
- static bool classof(const PackedAttr *A) { return true; }
+ static bool classof(const PragmaPackAttr *A) { return true; }
};
class AlignedAttr : public Attr {
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=78483&r1=78482&r2=78483&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Sat Aug 8 13:23:56 2009
@@ -197,9 +197,11 @@
void ASTRecordLayoutBuilder::Layout(const RecordDecl *D) {
IsUnion = D->isUnion();
-
- if (const PackedAttr* PA = D->getAttr<PackedAttr>())
- StructPacking = PA->getAlignment();
+
+ if (D->hasAttr<PackedAttr>())
+ StructPacking = 1;
+ if (const PragmaPackAttr *PPA = D->getAttr<PragmaPackAttr>())
+ StructPacking = PPA->getAlignment();
if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
UpdateAlignment(AA->getAlignment());
@@ -240,8 +242,8 @@
NextOffset = Size;
}
- if (const PackedAttr *PA = D->getAttr<PackedAttr>())
- StructPacking = PA->getAlignment();
+ if (D->hasAttr<PackedAttr>())
+ StructPacking = 1;
if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
UpdateAlignment(AA->getAlignment());
@@ -273,8 +275,8 @@
// FIXME: Should this override struct packing? Probably we want to
// take the minimum?
- if (const PackedAttr *PA = D->getAttr<PackedAttr>())
- FieldPacking = PA->getAlignment();
+ if (D->hasAttr<PackedAttr>())
+ FieldPacking = 1;
if (const Expr *BitWidthExpr = D->getBitWidth()) {
// TODO: Need to check this algorithm on other targets!
Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=78483&r1=78482&r2=78483&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Sat Aug 8 13:23:56 2009
@@ -31,9 +31,8 @@
LayoutUnion(D);
return;
}
-
- if (const PackedAttr* PA = D->getAttr<PackedAttr>())
- Packed = PA->getAlignment();
+
+ Packed = D->hasAttr<PackedAttr>();
if (LayoutFields(D))
return;
@@ -96,15 +95,8 @@
bool CGRecordLayoutBuilder::LayoutField(const FieldDecl *D,
uint64_t FieldOffset) {
- bool FieldPacked = Packed;
-
- // FIXME: Should this override struct packing? Probably we want to
- // take the minimum?
- if (const PackedAttr *PA = D->getAttr<PackedAttr>())
- FieldPacked = PA->getAlignment();
-
// If the field is packed, then we need a packed struct.
- if (!Packed && FieldPacked)
+ if (!Packed && D->hasAttr<PackedAttr>())
return false;
if (D->isBitField()) {
Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=78483&r1=78482&r2=78483&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Sat Aug 8 13:23:56 2009
@@ -507,7 +507,8 @@
SIMPLE_ATTR(CFReturnsRetained);
SIMPLE_ATTR(NSReturnsRetained);
SIMPLE_ATTR(Overloadable);
- UNSIGNED_ATTR(Packed);
+ SIMPLE_ATTR(Packed);
+ UNSIGNED_ATTR(PragmaPack);
SIMPLE_ATTR(Pure);
UNSIGNED_ATTR(Regparm);
STRING_ATTR(Section);
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=78483&r1=78482&r2=78483&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Sat Aug 8 13:23:56 2009
@@ -1698,10 +1698,13 @@
case Attr::Overloadable:
break;
- case Attr::Packed:
- Record.push_back(cast<PackedAttr>(Attr)->getAlignment());
+ case Attr::PragmaPack:
+ Record.push_back(cast<PragmaPackAttr>(Attr)->getAlignment());
break;
+ case Attr::Packed:
+ break;
+
case Attr::Pure:
break;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=78483&r1=78482&r2=78483&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Aug 8 13:23:56 2009
@@ -4200,7 +4200,7 @@
// the #pragma tokens are effectively skipped over during the
// parsing of the struct).
if (unsigned Alignment = getPragmaPackAlignment())
- New->addAttr(::new (Context) PackedAttr(Alignment * 8));
+ New->addAttr(::new (Context) PragmaPackAttr(Alignment * 8));
}
if (getLangOptions().CPlusPlus && SS.isEmpty() && Name && !Invalid) {
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=78483&r1=78482&r2=78483&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sat Aug 8 13:23:56 2009
@@ -283,7 +283,7 @@
}
if (TagDecl *TD = dyn_cast<TagDecl>(d))
- TD->addAttr(::new (S.Context) PackedAttr(1));
+ TD->addAttr(::new (S.Context) PackedAttr);
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.
@@ -292,7 +292,7 @@
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored_for_field_of_type)
<< Attr.getName() << FD->getType();
else
- FD->addAttr(::new (S.Context) PackedAttr(1));
+ FD->addAttr(::new (S.Context) PackedAttr);
} else
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
}
More information about the cfe-commits
mailing list