From: John McCall Date: Fri, 15 Jan 2010 18:56:44 +0000 (+0000) Subject: Don't lose type source information when rebuilding C-style cast expressions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b042fdfc9460e0018276412257e3c3226f9ea96e;p=clang Don't lose type source information when rebuilding C-style cast expressions. Also we don't need to recheck for altivec initializers, I think. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93529 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index fab7292999..e86da5d48f 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1651,6 +1651,11 @@ public: virtual OwningExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, TypeTy *Ty, SourceLocation RParenLoc, ExprArg Op); + OwningExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, + TypeSourceInfo *Ty, + SourceLocation RParenLoc, + ExprArg Op); + virtual bool TypeIsVectorType(TypeTy *Ty) { return GetTypeFromParser(Ty)->isVectorType(); } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index edd2945232..0b97d761b6 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3906,28 +3906,38 @@ bool Sema::CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *&CastExpr, Action::OwningExprResult Sema::ActOnCastExpr(Scope *S, SourceLocation LParenLoc, TypeTy *Ty, SourceLocation RParenLoc, ExprArg Op) { - CastExpr::CastKind Kind = CastExpr::CK_Unknown; - assert((Ty != 0) && (Op.get() != 0) && "ActOnCastExpr(): missing type or expr"); - Expr *castExpr = (Expr *)Op.get(); TypeSourceInfo *castTInfo; QualType castType = GetTypeFromParser(Ty, &castTInfo); if (!castTInfo) castTInfo = Context.getTrivialTypeSourceInfo(castType, SourceLocation()); // If the Expr being casted is a ParenListExpr, handle it specially. + // FIXME: preserve type source info. + Expr *castExpr = (Expr *)Op.get(); if (isa(castExpr)) return ActOnCastOfParenListExpr(S, LParenLoc, RParenLoc, move(Op),castType); + + return BuildCStyleCastExpr(LParenLoc, castTInfo, RParenLoc, move(Op)); +} + +Action::OwningExprResult +Sema::BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty, + SourceLocation RParenLoc, ExprArg Op) { + Expr *castExpr = static_cast(Op.get()); + CXXMethodDecl *Method = 0; - if (CheckCastTypes(SourceRange(LParenLoc, RParenLoc), castType, castExpr, + CastExpr::CastKind Kind = CastExpr::CK_Unknown; + if (CheckCastTypes(SourceRange(LParenLoc, RParenLoc), Ty->getType(), castExpr, Kind, Method)) return ExprError(); if (Method) { - OwningExprResult CastArg = BuildCXXCastArgument(LParenLoc, castType, Kind, - Method, move(Op)); + // FIXME: preserve type source info here + OwningExprResult CastArg = BuildCXXCastArgument(LParenLoc, Ty->getType(), + Kind, Method, move(Op)); if (CastArg.isInvalid()) return ExprError(); @@ -3937,8 +3947,8 @@ Sema::ActOnCastExpr(Scope *S, SourceLocation LParenLoc, TypeTy *Ty, Op.release(); } - return Owned(new (Context) CStyleCastExpr(castType.getNonReferenceType(), - Kind, castExpr, castTInfo, + return Owned(new (Context) CStyleCastExpr(Ty->getType().getNonReferenceType(), + Kind, castExpr, Ty, LParenLoc, RParenLoc)); } diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 65bf9e5c91..469ff72d3f 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -1018,11 +1018,8 @@ public: TypeSourceInfo *TInfo, SourceLocation RParenLoc, ExprArg SubExpr) { - return getSema().ActOnCastExpr(/*Scope=*/0, - LParenLoc, - TInfo->getType().getAsOpaquePtr(), - RParenLoc, - move(SubExpr)); + return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, + move(SubExpr)); } /// \brief Build a new compound literal expression.