[cfe-commits] r111857 - in /cfe/trunk: include/clang/Sema/Action.h include/clang/Sema/Sema.h lib/Parse/ParseObjc.cpp lib/Sema/SemaDecl.cpp
Fariborz Jahanian
fjahanian at apple.com
Mon Aug 23 15:46:53 PDT 2010
Author: fjahanian
Date: Mon Aug 23 17:46:52 2010
New Revision: 111857
URL: http://llvm.org/viewvc/llvm-project?rev=111857&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Sema/Action.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/include/clang/Sema/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Action.h?rev=111857&r1=111856&r2=111857&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Action.h (original)
+++ cfe/trunk/include/clang/Sema/Action.h Mon Aug 23 17:46:52 2010
@@ -722,6 +722,9 @@
return 0;
}
+ virtual void ActOnLastBitfield(SourceLocation DeclStart, Decl *IntfDecl,
+ llvm::SmallVectorImpl<Decl *> &AllIvarDecls) {}
+
virtual void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl,
Decl **Fields, unsigned NumFields,
SourceLocation LBrac, SourceLocation RBrac,
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=111857&r1=111856&r2=111857&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Aug 23 17:46:52 2010
@@ -1022,7 +1022,8 @@
bool CheckNontrivialField(FieldDecl *FD);
void DiagnoseNontrivial(const RecordType* Record, CXXSpecialMember mem);
CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD);
-
+ virtual void ActOnLastBitfield(SourceLocation DeclStart, Decl *IntfDecl,
+ llvm::SmallVectorImpl<Decl *> &AllIvarDecls);
virtual Decl *ActOnIvar(Scope *S, SourceLocation DeclStart,
Decl *IntfDecl,
Declarator &D, ExprTy *BitfieldWidth,
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=111857&r1=111856&r2=111857&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Aug 23 17:46:52 2010
@@ -1097,7 +1097,7 @@
return Field;
}
} Callback(*this, interfaceDecl, visibility, AllIvarDecls);
-
+
// Parse all the comma separated declarators.
DeclSpec DS;
ParseStructDeclaration(DS, Callback);
@@ -1111,6 +1111,7 @@
}
}
SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc);
+ Actions.ActOnLastBitfield(RBraceLoc, interfaceDecl, AllIvarDecls);
// Call ActOnFields() even if we don't have any decls. This is useful
// for code rewriting tools that need to be aware of the empty list.
Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl,
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=111857&r1=111856&r2=111857&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Aug 23 17:46:52 2010
@@ -6399,6 +6399,48 @@
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,
More information about the cfe-commits
mailing list