42 changes: 11 additions & 31 deletions clang/lib/AST/ExprObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ ObjCArrayLiteral *ObjCArrayLiteral::Create(const ASTContext &C,
ArrayRef<Expr *> Elements,
QualType T, ObjCMethodDecl *Method,
SourceRange SR) {
void *Mem =
C.Allocate(sizeof(ObjCArrayLiteral) + Elements.size() * sizeof(Expr *));
void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(Elements.size()));
return new (Mem) ObjCArrayLiteral(Elements, T, Method, SR);
}

ObjCArrayLiteral *ObjCArrayLiteral::CreateEmpty(const ASTContext &C,
unsigned NumElements) {

void *Mem =
C.Allocate(sizeof(ObjCArrayLiteral) + NumElements * sizeof(Expr *));
void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(NumElements));
return new (Mem) ObjCArrayLiteral(EmptyShell(), NumElements);
}

Expand All @@ -60,8 +58,8 @@ ObjCDictionaryLiteral::ObjCDictionaryLiteral(ArrayRef<ObjCDictionaryElement> VK,
false, false),
NumElements(VK.size()), HasPackExpansions(HasPackExpansions), Range(SR),
DictWithObjectsMethod(method) {
KeyValuePair *KeyValues = getKeyValues();
ExpansionData *Expansions = getExpansionData();
KeyValuePair *KeyValues = getTrailingObjects<KeyValuePair>();
ExpansionData *Expansions = getTrailingObjects<ExpansionData>();
for (unsigned I = 0; I < NumElements; I++) {
if (VK[I].Key->isTypeDependent() || VK[I].Key->isValueDependent() ||
VK[I].Value->isTypeDependent() || VK[I].Value->isValueDependent())
Expand Down Expand Up @@ -91,23 +89,16 @@ ObjCDictionaryLiteral::Create(const ASTContext &C,
ArrayRef<ObjCDictionaryElement> VK,
bool HasPackExpansions, QualType T,
ObjCMethodDecl *method, SourceRange SR) {
unsigned ExpansionsSize = 0;
if (HasPackExpansions)
ExpansionsSize = sizeof(ExpansionData) * VK.size();

void *Mem = C.Allocate(sizeof(ObjCDictionaryLiteral) +
sizeof(KeyValuePair) * VK.size() + ExpansionsSize);
void *Mem = C.Allocate(totalSizeToAlloc<KeyValuePair, ExpansionData>(
VK.size(), HasPackExpansions ? VK.size() : 0));
return new (Mem) ObjCDictionaryLiteral(VK, HasPackExpansions, T, method, SR);
}

ObjCDictionaryLiteral *
ObjCDictionaryLiteral::CreateEmpty(const ASTContext &C, unsigned NumElements,
bool HasPackExpansions) {
unsigned ExpansionsSize = 0;
if (HasPackExpansions)
ExpansionsSize = sizeof(ExpansionData) * NumElements;
void *Mem = C.Allocate(sizeof(ObjCDictionaryLiteral) +
sizeof(KeyValuePair) * NumElements + ExpansionsSize);
void *Mem = C.Allocate(totalSizeToAlloc<KeyValuePair, ExpansionData>(
NumElements, HasPackExpansions ? NumElements : 0));
return new (Mem)
ObjCDictionaryLiteral(EmptyShell(), NumElements, HasPackExpansions);
}
Expand All @@ -122,15 +113,6 @@ QualType ObjCPropertyRefExpr::getReceiverType(const ASTContext &ctx) const {
return getBase()->getType();
}

ObjCSubscriptRefExpr *
ObjCSubscriptRefExpr::Create(const ASTContext &C, Expr *base, Expr *key,
QualType T, ObjCMethodDecl *getMethod,
ObjCMethodDecl *setMethod, SourceLocation RB) {
void *Mem = C.Allocate(sizeof(ObjCSubscriptRefExpr));
return new (Mem) ObjCSubscriptRefExpr(
base, key, T, VK_LValue, OK_ObjCSubscript, getMethod, setMethod, RB);
}

ObjCMessageExpr::ObjCMessageExpr(QualType T, ExprValueKind VK,
SourceLocation LBracLoc,
SourceLocation SuperLoc, bool IsInstanceSuper,
Expand Down Expand Up @@ -293,11 +275,9 @@ ObjCMessageExpr *ObjCMessageExpr::alloc(const ASTContext &C,

ObjCMessageExpr *ObjCMessageExpr::alloc(const ASTContext &C, unsigned NumArgs,
unsigned NumStoredSelLocs) {
unsigned Size = sizeof(ObjCMessageExpr) + sizeof(void *) +
NumArgs * sizeof(Expr *) +
NumStoredSelLocs * sizeof(SourceLocation);
return (ObjCMessageExpr *)C.Allocate(
Size, llvm::AlignOf<ObjCMessageExpr>::Alignment);
totalSizeToAlloc<void *, SourceLocation>(NumArgs + 1, NumStoredSelLocs),
llvm::AlignOf<ObjCMessageExpr>::Alignment);
}

void ObjCMessageExpr::getSelectorLocs(
Expand Down Expand Up @@ -358,7 +338,7 @@ ObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const {
Stmt::child_range ObjCMessageExpr::children() {
Stmt **begin;
if (getReceiverKind() == Instance)
begin = reinterpret_cast<Stmt **>(this + 1);
begin = reinterpret_cast<Stmt **>(getTrailingObjects<void *>());
else
begin = reinterpret_cast<Stmt **>(getArgs());
return child_range(begin,
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Sema/SemaExprObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,9 @@ ExprResult Sema::BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr,
BaseExpr = Result.get();

// Build the pseudo-object expression.
return ObjCSubscriptRefExpr::Create(Context, BaseExpr, IndexExpr,
Context.PseudoObjectTy, getterMethod,
setterMethod, RB);
return new (Context) ObjCSubscriptRefExpr(
BaseExpr, IndexExpr, Context.PseudoObjectTy, VK_LValue, OK_ObjCSubscript,
getterMethod, setterMethod, RB);
}

ExprResult Sema::BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements) {
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Serialization/ASTReaderStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,10 @@ void ASTStmtReader::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
assert(NumElements == E->getNumElements() && "Wrong number of elements");
bool HasPackExpansions = Record[Idx++];
assert(HasPackExpansions == E->HasPackExpansions &&"Pack expansion mismatch");
ObjCDictionaryLiteral::KeyValuePair *KeyValues = E->getKeyValues();
ObjCDictionaryLiteral::ExpansionData *Expansions = E->getExpansionData();
ObjCDictionaryLiteral::KeyValuePair *KeyValues =
E->getTrailingObjects<ObjCDictionaryLiteral::KeyValuePair>();
ObjCDictionaryLiteral::ExpansionData *Expansions =
E->getTrailingObjects<ObjCDictionaryLiteral::ExpansionData>();
for (unsigned I = 0; I != NumElements; ++I) {
KeyValues[I].Key = Reader.ReadSubExpr();
KeyValues[I].Value = Reader.ReadSubExpr();
Expand Down