From: Steve Naroff Date: Wed, 16 Jul 2008 18:22:22 +0000 (+0000) Subject: Two fixes: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f3b2654a9ff6912862f366102f5c46f7757260a;p=clang Two fixes: - 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 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 --- diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp index 73277d163a..535cc0be3d 100644 --- a/Driver/RewriteObjC.cpp +++ b/Driver/RewriteObjC.cpp @@ -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 += ")"; + } } //===----------------------------------------------------------------------===// diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 2a79dd278d..641ebb4035 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -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 }; diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index ce9379f19c..ef3b2d74fb 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -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(); - return new (Mem) ObjCIvarDecl(L, Id, T); + return new (Mem) ObjCIvarDecl(L, Id, T, BW); } ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index f4d9da6014..00c73ea765 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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);