Keep proper source location information for the type in an Objective-C
@encode expression.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101907 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp
index 2c954a6..60318de 100644
--- a/lib/Frontend/PCHReaderStmt.cpp
+++ b/lib/Frontend/PCHReaderStmt.cpp
@@ -725,7 +725,7 @@
unsigned PCHStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
VisitExpr(E);
- E->setEncodedType(Reader.GetType(Record[Idx++]));
+ E->setEncodedTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
return 0;
diff --git a/lib/Frontend/PCHWriterStmt.cpp b/lib/Frontend/PCHWriterStmt.cpp
index 9a5417c..9c9f891 100644
--- a/lib/Frontend/PCHWriterStmt.cpp
+++ b/lib/Frontend/PCHWriterStmt.cpp
@@ -655,7 +655,7 @@
void PCHStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
VisitExpr(E);
- Writer.AddTypeRef(E->getEncodedType(), Record);
+ Writer.AddTypeSourceInfo(E->getEncodedTypeSourceInfo(), Record);
Writer.AddSourceLocation(E->getAtLoc(), Record);
Writer.AddSourceLocation(E->getRParenLoc(), Record);
Code = pch::EXPR_OBJC_ENCODE;
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 0535923..2578332 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -2411,7 +2411,7 @@
unsigned NumStrings);
Expr *BuildObjCEncodeExpression(SourceLocation AtLoc,
- QualType EncodedType,
+ TypeSourceInfo *EncodedTypeInfo,
SourceLocation RParenLoc);
CXXMemberCallExpr *BuildCXXMemberCallExpr(Expr *Exp,
NamedDecl *FoundDecl,
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index ad95f00..ce06abe 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -95,8 +95,9 @@
}
Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc,
- QualType EncodedType,
+ TypeSourceInfo *EncodedTypeInfo,
SourceLocation RParenLoc) {
+ QualType EncodedType = EncodedTypeInfo->getType();
QualType StrTy;
if (EncodedType->isDependentType())
StrTy = Context.DependentTy;
@@ -114,7 +115,7 @@
ArrayType::Normal, 0);
}
- return new (Context) ObjCEncodeExpr(StrTy, EncodedType, AtLoc, RParenLoc);
+ return new (Context) ObjCEncodeExpr(StrTy, EncodedTypeInfo, AtLoc, RParenLoc);
}
Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc,
@@ -123,9 +124,13 @@
TypeTy *ty,
SourceLocation RParenLoc) {
// FIXME: Preserve type source info ?
- QualType EncodedType = GetTypeFromParser(ty);
+ TypeSourceInfo *TInfo;
+ QualType EncodedType = GetTypeFromParser(ty, &TInfo);
+ if (!TInfo)
+ TInfo = Context.getTrivialTypeSourceInfo(EncodedType,
+ PP.getLocForEndOfToken(LParenLoc));
- return BuildObjCEncodeExpression(AtLoc, EncodedType, RParenLoc);
+ return BuildObjCEncodeExpression(AtLoc, TInfo, RParenLoc);
}
Sema::ExprResult Sema::ParseObjCSelectorExpression(Selector Sel,
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index e2fdf66..ba714e8 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -1688,9 +1688,9 @@
/// By default, performs semantic analysis to build the new expression.
/// Subclasses may override this routine to provide different behavior.
OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
- QualType T,
+ TypeSourceInfo *EncodeTypeInfo,
SourceLocation RParenLoc) {
- return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
+ return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
RParenLoc));
}
@@ -5464,18 +5464,17 @@
template<typename Derived>
Sema::OwningExprResult
TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
- // FIXME: poor source location
- TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
- QualType EncodedType = getDerived().TransformType(E->getEncodedType());
- if (EncodedType.isNull())
+ TypeSourceInfo *EncodedTypeInfo
+ = getDerived().TransformType(E->getEncodedTypeSourceInfo());
+ if (!EncodedTypeInfo)
return SemaRef.ExprError();
if (!getDerived().AlwaysRebuild() &&
- EncodedType == E->getEncodedType())
+ EncodedTypeInfo == E->getEncodedTypeSourceInfo())
return SemaRef.Owned(E->Retain());
return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
- EncodedType,
+ EncodedTypeInfo,
E->getRParenLoc());
}