diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-08-23 22:46:52 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-08-23 22:46:52 +0000 |
commit | d097be8f81fbf4ed96ac10bae18562dd8202666b (patch) | |
tree | 73b517af59a3867e52909c247c91371fccfe8b49 /lib/Sema/SemaDecl.cpp | |
parent | 00577ada44c889fbe311d61c51a8da89e65c7c9a (diff) |
Handling remaining rule for synthesize bitfields in
class extensions (nonfragile-abi2).For every class @interface and class
extension @interface, if the last ivar is a bitfield of any type,
then add an implicit `char :0` ivar to the end of that interface.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111857 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index f08092f922..e9a2b3cd72 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -6399,6 +6399,48 @@ Decl *Sema::ActOnIvar(Scope *S, return NewID; } +/// ActOnLastBitfield - This routine handles synthesized bitfields rules for +/// class and class extensions. For every class @interface and class +/// extension @interface, if the last ivar is a bitfield of any type, +/// then add an implicit `char :0` ivar to the end of that interface. +void Sema::ActOnLastBitfield(SourceLocation DeclLoc, Decl *EnclosingDecl, + llvm::SmallVectorImpl<Decl *> &AllIvarDecls) { + if (!LangOpts.ObjCNonFragileABI2 || AllIvarDecls.empty()) + return; + + Decl *ivarDecl = AllIvarDecls[AllIvarDecls.size()-1]; + ObjCIvarDecl *Ivar = cast<ObjCIvarDecl>(ivarDecl); + + if (!Ivar->isBitField()) + return; + uint64_t BitFieldSize = + Ivar->getBitWidth()->EvaluateAsInt(Context).getZExtValue(); + if (BitFieldSize == 0) + return; + ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(EnclosingDecl); + if (!ID) { + if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(EnclosingDecl)) { + if (!CD->IsClassExtension()) + return; + } + // No need to add this to end of @implementation. + else + return; + } + // All conditions are met. Add a new bitfield to the tail end of ivars. + llvm::APInt Zero(Context.getTypeSize(Context.CharTy), 0); + Expr * BW = + new (Context) IntegerLiteral(Zero, Context.CharTy, DeclLoc); + + Ivar = ObjCIvarDecl::Create(Context, cast<ObjCContainerDecl>(EnclosingDecl), + DeclLoc, 0, + Context.CharTy, + Context.CreateTypeSourceInfo(Context.CharTy), + ObjCIvarDecl::Private, BW, + true); + AllIvarDecls.push_back(Ivar); +} + void Sema::ActOnFields(Scope* S, SourceLocation RecLoc, Decl *EnclosingDecl, Decl **Fields, unsigned NumFields, |