diff options
| author | Douglas Gregor <dgregor@apple.com> | 2009-12-22 07:24:36 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2009-12-22 07:24:36 +0000 |
| commit | 96596c98fbb584d8c9eec99d0a1c0734da756787 (patch) | |
| tree | 4cc2aa0da213cc084b87ef78df8bc359440a0d8e /clang/lib/Sema | |
| parent | 778f92ab024794d6751a30dfbe59852fd0d0522c (diff) | |
| download | bcm5719-llvm-96596c98fbb584d8c9eec99d0a1c0734da756787.tar.gz bcm5719-llvm-96596c98fbb584d8c9eec99d0a1c0734da756787.zip | |
Switch initialization of parameters in a call over to
InitializationSequence (when a FunctionDecl is present). This required
a few small fixes to initialization sequences:
- Make sure to use the adjusted parameter type for initialization of
function parameters.
- Implement transparent union calling semantics in C
llvm-svn: 91902
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 16 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 23 |
2 files changed, 33 insertions, 6 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 181d6d1c8f8..718d5ab577b 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3182,8 +3182,20 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc, return true; // Pass the argument. - if (PerformCopyInitialization(Arg, ProtoArgType, AA_Passing)) - return true; + if (FDecl && i < FDecl->getNumParams()) { + ParmVarDecl *Param = FDecl->getParamDecl(i); + InitializedEntity Entity =InitializedEntity::InitializeParameter(Param); + OwningExprResult ArgE = PerformCopyInitialization(Entity, + SourceLocation(), + Owned(Arg)); + if (ArgE.isInvalid()) + return true; + + Arg = ArgE.takeAs<Expr>(); + } else { + if (PerformCopyInitialization(Arg, ProtoArgType, AA_Passing)) + return true; + } if (!ProtoArgType->isReferenceType()) Arg = MaybeBindToTemporary(Arg).takeAs<Expr>(); diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 80cfc3637e4..f831b415121 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -1811,8 +1811,15 @@ InitializedEntity::InitializedEntity(ASTContext &Context, unsigned Index, void InitializedEntity::InitDeclLoc() { assert((Kind == EK_Variable || Kind == EK_Parameter || Kind == EK_Member) && "InitDeclLoc cannot be used with non-declaration entities."); - - if (TypeSourceInfo *DI = VariableOrMember->getTypeSourceInfo()) { + + ASTContext &Context = VariableOrMember->getASTContext(); + if (Kind == EK_Parameter && + !Context.hasSameUnqualifiedType( + cast<ParmVarDecl>(VariableOrMember)->getOriginalType(), + VariableOrMember->getType())) { + // For a parameter whose type has decayed, use the decayed type to + // build new source information. + } else if (TypeSourceInfo *DI = VariableOrMember->getTypeSourceInfo()) { TL = DI->getTypeLoc(); return; } @@ -1820,8 +1827,8 @@ void InitializedEntity::InitDeclLoc() { // FIXME: Once we've gone through the effort to create the fake // TypeSourceInfo, should we cache it in the declaration? // (If not, we "leak" it). - TypeSourceInfo *DI = VariableOrMember->getASTContext() - .CreateTypeSourceInfo(VariableOrMember->getType()); + TypeSourceInfo *DI + = Context.CreateTypeSourceInfo(VariableOrMember->getType()); DI->getTypeLoc().initialize(VariableOrMember->getLocation()); TL = DI->getTypeLoc(); } @@ -3346,6 +3353,14 @@ InitializationSequence::Perform(Sema &S, QualType SourceType = CurInitExpr->getType(); Sema::AssignConvertType ConvTy = S.CheckSingleAssignmentConstraints(Step->Type, CurInitExpr); + + // If this is a call, allow conversion to a transparent union. + if (ConvTy != Sema::Compatible && + Entity.getKind() == InitializedEntity::EK_Parameter && + S.CheckTransparentUnionArgumentConstraints(Step->Type, CurInitExpr) + == Sema::Compatible) + ConvTy = Sema::Compatible; + if (S.DiagnoseAssignmentResult(ConvTy, Kind.getLocation(), Step->Type, SourceType, CurInitExpr, getAssignmentAction(Entity))) |

