]> granicus.if.org Git - clang/commitdiff
Two fixes:
authorSteve Naroff <snaroff@apple.com>
Wed, 16 Jul 2008 18:22:22 +0000 (18:22 +0000)
committerSteve Naroff <snaroff@apple.com>
Wed, 16 Jul 2008 18:22:22 +0000 (18:22 +0000)
- Make sure ObjCIvarDecl propagates the bitfield width.
- RewriteObjC::SynthesizeIvarOffsetComputation(): Avoid using the __OFFSETOF__ mumbo jumbo for bitfields (since it isn't legal C). This fixes <rdar://problem/5986079> clang ObjC rewriter: bitfields and ivar access don't mix.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53694 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/RewriteObjC.cpp
include/clang/AST/DeclObjC.h
lib/AST/DeclObjC.cpp
lib/Sema/SemaDecl.cpp

index 73277d163a652f285cad474a5c7dba66e2d04406..535cc0be3dcc8ea706edbd33556630467449b0f2 100644 (file)
@@ -2779,13 +2779,19 @@ void RewriteObjC::RewriteObjCCategoryImplDecl(ObjCCategoryImplDecl *IDecl,
 void RewriteObjC::SynthesizeIvarOffsetComputation(ObjCImplementationDecl *IDecl, 
                                                   ObjCIvarDecl *ivar, 
                                                   std::string &Result) {
-  Result += "__OFFSETOFIVAR__(struct ";
-  Result += IDecl->getName();
-  if (LangOpts.Microsoft)
-    Result += "_IMPL";
-  Result += ", ";
-  Result += ivar->getName();
-  Result += ")";
+  if (ivar->isBitField()) {
+    // FIXME: The hack below doesn't work for bitfields. For now, we simply
+    // place all bitfields at offset 0.
+    Result += "0";
+  } else {
+    Result += "__OFFSETOFIVAR__(struct ";
+    Result += IDecl->getName();
+    if (LangOpts.Microsoft)
+      Result += "_IMPL";
+    Result += ", ";
+    Result += ivar->getName();
+    Result += ")";
+  }
 }
 
 //===----------------------------------------------------------------------===//
index 2a79dd278d5371040b1c31707adb27886b0a61d2..641ebb40357addf3fa9dbc0aa6cd9030e2752e7c 100644 (file)
@@ -451,12 +451,12 @@ public:
 ///   }
 ///
 class ObjCIvarDecl : public FieldDecl {
-  ObjCIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T)
-    : FieldDecl(ObjCIvar, L, Id, T) {}
+  ObjCIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Expr *BW)
+    : FieldDecl(ObjCIvar, L, Id, T, BW) {}
 public:
   static ObjCIvarDecl *Create(ASTContext &C, SourceLocation L,
-                              IdentifierInfo *Id, QualType T);
-    
+                              IdentifierInfo *Id, QualType T, Expr *BW = NULL);
+  
   enum AccessControl {
     None, Private, Protected, Public, Package
   };
index ce9379f19c15956555d6132ae0af0beaa4db2797..ef3b2d74fb9b10546cd9a419886ba704393c43fc 100644 (file)
@@ -89,9 +89,9 @@ void ObjCInterfaceDecl::Destroy(ASTContext& C) {
 
 
 ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L,
-                                   IdentifierInfo *Id, QualType T) {
+                                   IdentifierInfo *Id, QualType T, Expr *BW) {
   void *Mem = C.getAllocator().Allocate<ObjCIvarDecl>();
-  return new (Mem) ObjCIvarDecl(L, Id, T);
+  return new (Mem) ObjCIvarDecl(L, Id, T, BW);
 }
 
 ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C,
index f4d9da60147a749b9f037260e83a506fd6804fad..00c73ea765c432759c4044a27469350354af287a 100644 (file)
@@ -1946,7 +1946,8 @@ Sema::DeclTy *Sema::ActOnIvar(Scope *S,
     InvalidDecl = true;
   }
   
-  ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context, Loc, II, T);
+  ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context, Loc, II, T,
+                                             (Expr *)BitfieldWidth);
   
   ProcessDeclAttributes(NewID, D);