diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-11-29 22:48:16 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-11-29 22:48:16 +0000 |
commit | c8d7f586180995ba33d03c0f6115b6a7bdefe326 (patch) | |
tree | f4f1aee0e983e537d623109a3baa0ce128c30ae5 /lib/Sema/Sema.cpp | |
parent | 381711c6e7911d762f81a65e9ef4339a6a3d6524 (diff) |
Revert r145244. It causes us to create broken ASTs with missing type information
for some cast expressions.
Original commit message:
Removed useless ImplicitCast nodes in explicit cstyle and static casts
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145447 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/Sema.cpp')
-rw-r--r-- | lib/Sema/Sema.cpp | 58 |
1 files changed, 15 insertions, 43 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 0ce816b8dc..fe393dd2fe 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -234,16 +234,13 @@ void Sema::PrintStats() const { AnalysisWarnings.PrintStats(); } -/// CastExprToType - If Expr is not of type 'Type', insert a cast of the -/// specified kind. -/// Redundant implicit casts are merged together. -/// Pay attention: if CCK != CCK_ImplicitConversion, -/// users of this function must fill -/// SourceTypeInfos and SourceLocations later -ExprResult Sema::CastExprToType(Expr *E, QualType Ty, - CastKind Kind, ExprValueKind VK, - const CXXCastPath *BasePath, - CheckedConversionKind CCK) { +/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. +/// If there is already an implicit cast, merge into the existing one. +/// The result is of the given category. +ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty, + CastKind Kind, ExprValueKind VK, + const CXXCastPath *BasePath, + CheckedConversionKind CCK) { #ifndef NDEBUG if (VK == VK_RValue && !E->isRValue()) { switch (Kind) { @@ -279,41 +276,16 @@ ExprResult Sema::CastExprToType(Expr *E, QualType Ty, MarkVTableUsed(E->getLocStart(), cast<CXXRecordDecl>(RecordTy->getDecl())); } - - switch(CCK) { - default: - llvm_unreachable("Unexpected CheckedConversionKind"); - case CCK_ImplicitConversion: - if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(E)) { - if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) { - ImpCast->setType(Ty); - ImpCast->setValueKind(VK); - return Owned(E); - } - } - return Owned(ImplicitCastExpr::Create(Context, Ty, Kind, E, BasePath, VK)); - case CCK_CStyleCast: - return Owned(CStyleCastExpr::Create(Context, Ty, VK, Kind, E, BasePath, - 0, SourceLocation(), SourceLocation())); - case CCK_FunctionalCast: - return Owned(CXXFunctionalCastExpr::Create(Context, Ty, VK, 0, - SourceLocation(), Kind, E, - BasePath, SourceLocation())); - case CCK_StaticCast: - return Owned(CXXStaticCastExpr::Create(Context, Ty, VK, Kind, E, BasePath, - 0, SourceLocation(), - SourceLocation())); + + if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(E)) { + if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) { + ImpCast->setType(Ty); + ImpCast->setValueKind(VK); + return Owned(E); + } } - -} -/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. -/// If there is already an implicit cast, merge into the existing one. -/// The result is of the given category. -ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty, - CastKind Kind, ExprValueKind VK, - const CXXCastPath *BasePath) { - return CastExprToType(E, Ty, Kind, VK, BasePath, CCK_ImplicitConversion); + return Owned(ImplicitCastExpr::Create(Context, Ty, Kind, E, BasePath, VK)); } /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding |