Ordering issue in Sema::ActOnStartOfFunctionDef

I think I can explain what's causing the behavior in this FIXME from Sema::GetTypeForDeclarator() in case DeclaratorChunk::Function and what I'd like to do about it.

           // FIXME: We still apparently need the conversion in
           // Sema::ParseParamDeclarator(). This doesn't make any sense, since
           // it should be driving off the type being created here.

In Sema::ActOnStartOfFunctionDef
ActOnDeclarator() creates the FunctionType, with its (apparently immutable) argument type VLA. The FunctionType's argument type array is based on DeclaratorChunk::FunctionTypeInfo with the default conversions applied in GetTypeForDeclarator(), however the converted types are never propagated back into the FunctionTypeInfo. It is exactly these types in the FunctionTypeInfo, and not the FunctionType's argument type array, which ActOnParamDeclarator() uses to generate the types for it's ParmVarDecls.

The duplicated default conversions _could_ be eliminated by having Sema::GetTypeForDeclarator() update the FunctionTypeInfo, or by passing the FunctionType (or FunctionDecl) into ActOnParamDeclarator(). However, this is bad because it means that ActOnParamDeclarator() may not mutate the argument types in any way, which breaks address spaces at the least.

My proposal is for ActOnDeclarator() for the FunctionDecl to be moved after the loop over the parameter decls, which would allow ActOnParamDeclarator() to modify types (default conversions, address spaces, etc.) and update the FunctionTypeInfo object to by captured subsequently in the FunctionType.