]> granicus.if.org Git - clang/commitdiff
Don't lose type source information when rebuilding C-style cast expressions.
authorJohn McCall <rjmccall@apple.com>
Fri, 15 Jan 2010 18:56:44 +0000 (18:56 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 15 Jan 2010 18:56:44 +0000 (18:56 +0000)
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

lib/Sema/Sema.h
lib/Sema/SemaExpr.cpp
lib/Sema/TreeTransform.h

index fab729299936578afa2d4a9742fe5dcacefa801b..e86da5d48fc4f3ffd5a0cf578ad4bf1c7e4cbaab 100644 (file)
@@ -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();
   }
index edd2945232c7d14828c2f2bc739c050017eb9719..0b97d761b6235f0e1fe5b8d98404da2c204a57e8 100644 (file)
@@ -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<ParenListExpr>(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<Expr*>(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));
 }
 
index 65bf9e5c919b43507d70d365f887cdbf60f1a8bc..469ff72d3fc09b750802371067c534c2af6672ea 100644 (file)
@@ -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.