Changeset c6976ba


Ignore:
Timestamp:
Jul 13, 2017, 1:36:00 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
0a81c3f
Parents:
c5e3208
Message:

No longer construct reference return values.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/GenInit.cc

    rc5e3208 rc6976ba  
    5454
    5555          protected:
    56                 FunctionType * ftype;
     56                FunctionType * ftype = nullptr;
    5757                std::string funcName;
    5858        };
     
    138138                std::list< DeclarationWithType * > & returnVals = ftype->get_returnVals();
    139139                assert( returnVals.size() == 0 || returnVals.size() == 1 );
    140                 // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address
     140                // hands off if the function returns a reference - we don't want to allocate a temporary if a variable's address
    141141                // is being returned
    142                 if ( returnStmt->get_expr() && returnVals.size() == 1 && ! returnVals.front()->get_type()->get_lvalue() ) {
     142                if ( returnStmt->get_expr() && returnVals.size() == 1 && ! dynamic_cast< ReferenceType * >( returnVals.front()->get_type() ) ) {
    143143                        // explicitly construct the return value using the return expression and the retVal object
    144144                        assertf( returnVals.front()->get_name() != "", "Function %s has unnamed return value\n", funcName.c_str() );
    145                         UntypedExpr *construct = new UntypedExpr( new NameExpr( "?{}" ) );
    146                         construct->get_args().push_back( new AddressExpr( new VariableExpr( returnVals.front() ) ) );
    147                         construct->get_args().push_back( returnStmt->get_expr() );
    148                         stmtsToAddBefore.push_back(new ExprStmt(noLabels, construct));
     145
     146                        stmtsToAddBefore.push_back( genCtorDtor( "?{}", dynamic_cast< ObjectDecl *>( returnVals.front() ), returnStmt->get_expr() ) );
    149147
    150148                        // return the retVal object
     
    213211
    214212        bool CtorDtor::isManaged( Type * type ) const {
     213                // at least for now, references are never constructed
     214                if ( dynamic_cast< ReferenceType * >( type ) ) return false;
    215215                // need to clear and reset qualifiers when determining if a type is managed
    216216                ValueGuard< Type::Qualifiers > qualifiers( type->get_qualifiers() );
Note: See TracChangeset for help on using the changeset viewer.