- 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
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 += ")";
+ }
}
//===----------------------------------------------------------------------===//
/// }
///
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
};
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,
InvalidDecl = true;
}
- ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context, Loc, II, T);
+ ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context, Loc, II, T,
+ (Expr *)BitfieldWidth);
ProcessDeclAttributes(NewID, D);