aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2009-11-04 07:28:41 +0000
committerJohn McCall <rjmccall@apple.com>2009-11-04 07:28:41 +0000
commit5ab75172051a6d2ea71a80a79e81c65519fd3462 (patch)
treee03271bc6d106935276fbc951192f7e85b3f1a5b /lib/Sema
parentc86a6e988184867b09aa17a619402d0e81d0fda0 (diff)
Preserve type source information in sizeof/alignof expressions, and pass it
through to indexing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86018 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r--lib/Sema/Sema.h3
-rw-r--r--lib/Sema/SemaExpr.cpp18
-rw-r--r--lib/Sema/TreeTransform.h15
3 files changed, 20 insertions, 16 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index bb59e1c9f4..0f84b46ed4 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -1670,7 +1670,8 @@ public:
virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
tok::TokenKind Op, ExprArg Input);
- OwningExprResult CreateSizeOfAlignOfExpr(QualType T, SourceLocation OpLoc,
+ OwningExprResult CreateSizeOfAlignOfExpr(DeclaratorInfo *T,
+ SourceLocation OpLoc,
bool isSizeOf, SourceRange R);
OwningExprResult CreateSizeOfAlignOfExpr(Expr *E, SourceLocation OpLoc,
bool isSizeOf, SourceRange R);
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 2c54a792c1..ac7cced2ea 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1290,7 +1290,7 @@ bool Sema::CheckSizeOfAlignOfOperand(QualType exprType,
return false;
// C99 6.5.3.4p1:
- if (isa<FunctionType>(exprType)) {
+ if (exprType->isFunctionType()) {
// alignof(function) is allowed as an extension.
if (isSizeof)
Diag(OpLoc, diag::ext_sizeof_function_type) << ExprRange;
@@ -1348,17 +1348,20 @@ bool Sema::CheckAlignOfExpr(Expr *E, SourceLocation OpLoc,
/// \brief Build a sizeof or alignof expression given a type operand.
Action::OwningExprResult
-Sema::CreateSizeOfAlignOfExpr(QualType T, SourceLocation OpLoc,
+Sema::CreateSizeOfAlignOfExpr(DeclaratorInfo *DInfo,
+ SourceLocation OpLoc,
bool isSizeOf, SourceRange R) {
- if (T.isNull())
+ if (!DInfo)
return ExprError();
+ QualType T = DInfo->getType();
+
if (!T->isDependentType() &&
CheckSizeOfAlignOfOperand(T, OpLoc, R, isSizeOf))
return ExprError();
// C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
- return Owned(new (Context) SizeOfAlignOfExpr(isSizeOf, T,
+ return Owned(new (Context) SizeOfAlignOfExpr(isSizeOf, DInfo,
Context.getSizeType(), OpLoc,
R.getEnd()));
}
@@ -1400,12 +1403,11 @@ Sema::ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
if (TyOrEx == 0) return ExprError();
if (isType) {
- // FIXME: Preserve type source info.
- QualType ArgTy = GetTypeFromParser(TyOrEx);
- return CreateSizeOfAlignOfExpr(ArgTy, OpLoc, isSizeof, ArgRange);
+ DeclaratorInfo *DInfo;
+ (void) GetTypeFromParser(TyOrEx, &DInfo);
+ return CreateSizeOfAlignOfExpr(DInfo, OpLoc, isSizeof, ArgRange);
}
- // Get the end location.
Expr *ArgEx = (Expr *)TyOrEx;
Action::OwningExprResult Result
= CreateSizeOfAlignOfExpr(ArgEx, OpLoc, isSizeof, ArgEx->getSourceRange());
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index 9a6b851d63..5713da9fa5 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -884,9 +884,10 @@ public:
///
/// By default, performs semantic analysis to build the new expression.
/// Subclasses may override this routine to provide different behavior.
- OwningExprResult RebuildSizeOfAlignOf(QualType T, SourceLocation OpLoc,
+ OwningExprResult RebuildSizeOfAlignOf(DeclaratorInfo *DInfo,
+ SourceLocation OpLoc,
bool isSizeOf, SourceRange R) {
- return getSema().CreateSizeOfAlignOfExpr(T, OpLoc, isSizeOf, R);
+ return getSema().CreateSizeOfAlignOfExpr(DInfo, OpLoc, isSizeOf, R);
}
/// \brief Build a new sizeof or alignof expression with an expression
@@ -3532,16 +3533,16 @@ Sema::OwningExprResult
TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E,
bool isAddressOfOperand) {
if (E->isArgumentType()) {
- TemporaryBase Rebase(*this, E->getOperatorLoc(), DeclarationName());
+ DeclaratorInfo *OldT = E->getArgumentTypeInfo();
- QualType T = getDerived().TransformType(E->getArgumentType());
- if (T.isNull())
+ DeclaratorInfo *NewT = getDerived().TransformType(OldT);
+ if (!NewT)
return SemaRef.ExprError();
- if (!getDerived().AlwaysRebuild() && T == E->getArgumentType())
+ if (!getDerived().AlwaysRebuild() && OldT == NewT)
return SemaRef.Owned(E->Retain());
- return getDerived().RebuildSizeOfAlignOf(T, E->getOperatorLoc(),
+ return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
E->isSizeOf(),
E->getSourceRange());
}