[cfe-commits] r104797 - in /cfe/trunk/lib/Sema: Sema.h SemaAttr.cpp SemaDecl.cpp

Daniel Dunbar daniel at zuster.org
Wed May 26 18:53:40 PDT 2010


Author: ddunbar
Date: Wed May 26 20:53:40 2010
New Revision: 104797

URL: http://llvm.org/viewvc/llvm-project?rev=104797&view=rev
Log:
Sema: Replace getPragmaPackAlignment with AddAlignmentAttributesForRecord, which
exposes less details.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaAttr.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=104797&r1=104796&r2=104797&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed May 26 20:53:40 2010
@@ -4050,9 +4050,9 @@
                                     SourceLocation WeakNameLoc,
                                     SourceLocation AliasNameLoc);
 
-  /// getPragmaPackAlignment() - Return the current alignment as specified by
-  /// the current #pragma pack directive, or 0 if none is currently active.
-  unsigned getPragmaPackAlignment() const;
+  /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
+  /// a the record decl, to handle '#pragma pack' and '#pragma options align'.
+  void AddAlignmentAttributesForRecord(RecordDecl *RD);
 
   /// FreePackedContext - Deallocate and null out PackContext.
   void FreePackedContext();

Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=104797&r1=104796&r2=104797&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAttr.cpp Wed May 26 20:53:40 2010
@@ -88,12 +88,16 @@
   PackContext = 0;
 }
 
-/// getPragmaPackAlignment() - Return the current alignment as specified by
-/// the current #pragma pack directive, or 0 if none is currently active.
-unsigned Sema::getPragmaPackAlignment() const {
-  if (PackContext)
-    return static_cast<PragmaPackStack*>(PackContext)->getAlignment();
-  return 0;
+void Sema::AddAlignmentAttributesForRecord(RecordDecl *RD) {
+  // If there is no pack context, we don't need any attributes.
+  if (!PackContext)
+    return;
+
+  PragmaPackStack *Stack = static_cast<PragmaPackStack*>(PackContext);
+
+  // Otherwise, check to see if we need a max field alignment attribute.
+  if (unsigned Alignment = Stack->getAlignment())
+    RD->addAttr(::new (Context) MaxFieldAlignmentAttr(Alignment * 8));
 }
 
 void Sema::ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=104797&r1=104796&r2=104797&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed May 26 20:53:40 2010
@@ -5397,11 +5397,9 @@
       Invalid = true;
   }
 
-  if (Kind != TTK_Enum) {
-    // Handle #pragma pack: if the #pragma pack stack has non-default
-    // alignment, make up a packed attribute for this decl. These
-    // attributes are checked when the ASTContext lays out the
-    // structure.
+  if (RecordDecl *RD = dyn_cast<RecordDecl>(New)) {
+    // Add alignment attributes if necessary; these attributes are checked when
+    // the ASTContext lays out the structure.
     //
     // It is important for implementing the correct semantics that this
     // happen here (in act on tag decl). The #pragma pack stack is
@@ -5409,15 +5407,14 @@
     // many points during the parsing of a struct declaration (because
     // the #pragma tokens are effectively skipped over during the
     // parsing of the struct).
-    if (unsigned Alignment = getPragmaPackAlignment())
-      New->addAttr(::new (Context) MaxFieldAlignmentAttr(Alignment * 8));
+    AddAlignmentAttributesForRecord(RD);
   }
 
   // If this is a specialization of a member class (of a class template),
   // check the specialization.
   if (isExplicitSpecialization && CheckMemberSpecialization(New, Previous))
     Invalid = true;
-      
+
   if (Invalid)
     New->setInvalidDecl();
 





More information about the cfe-commits mailing list