Changeset a28bc02 for src/InitTweak


Ignore:
Timestamp:
May 11, 2017, 2:09:51 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:
6a4f3d4
Parents:
ddbde34
Message:

assignment argument and return value are now always copy constructed

Location:
src/InitTweak
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    rddbde34 ra28bc02  
    361361                                        FunctionType * ftype = dynamic_cast< FunctionType * >( GenPoly::getFunctionType( funcDecl->get_type() ) );
    362362                                        assert( ftype );
    363                                         if ( (isConstructor( funcDecl->get_name() ) || funcDecl->get_name() == "?=?") && ftype->get_parameters().size() == 2 ) {
     363                                        if ( isConstructor( funcDecl->get_name() ) && ftype->get_parameters().size() == 2 ) {
    364364                                                Type * t1 = ftype->get_parameters().front()->get_type();
    365365                                                Type * t2 = ftype->get_parameters().back()->get_type();
     
    367367
    368368                                                if ( ResolvExpr::typesCompatible( ptrType->get_base(), t2, SymTab::Indexer() ) ) {
    369                                                         // optimization: don't need to copy construct in order to call a copy constructor or
    370                                                         // assignment operator
     369                                                        // optimization: don't need to copy construct in order to call a copy constructor
    371370                                                        return appExpr;
    372371                                                } // if
     
    636635                                assert( ! stmtExpr->get_returnDecls().empty() );
    637636                                body->get_kids().push_back( new ExprStmt( noLabels, new VariableExpr( stmtExpr->get_returnDecls().front() ) ) );
    638                         }
    639                         stmtExpr->get_returnDecls().clear();
    640                         stmtExpr->get_dtors().clear();
     637                                stmtExpr->get_returnDecls().clear();
     638                                stmtExpr->get_dtors().clear();
     639                        }
     640                        assert( stmtExpr->get_returnDecls().empty() );
     641                        assert( stmtExpr->get_dtors().empty() );
    641642                        return stmtExpr;
    642643                }
     
    667668                        stmtsToAdd.splice( stmtsToAdd.end(), fixer.stmtsToAdd );
    668669                        unqMap[unqExpr->get_id()] = unqExpr;
     670                        if ( unqCount[ unqExpr->get_id() ] == 0 ) {  // insert destructor after the last use of the unique expression
     671                                stmtsToAdd.splice( stmtsToAddAfter.end(), dtors[ unqExpr->get_id() ] );
     672                        } else { // remember dtors for last instance of unique expr
     673                                dtors[ unqExpr->get_id() ] = fixer.stmtsToAddAfter;
     674                        }
    669675                        if ( UntypedExpr * deref = dynamic_cast< UntypedExpr * >( unqExpr->get_expr() ) ) {
    670676                                // unique expression is now a dereference, because the inner expression is an lvalue returning function call.
     
    675681                                getCallArg( deref, 0 ) = unqExpr;
    676682                                addDeref.insert( unqExpr->get_id() );
    677                                 if ( unqCount[ unqExpr->get_id() ] == 0 ) {  // insert destructor after the last use of the unique expression
    678                                         stmtsToAdd.splice( stmtsToAddAfter.end(), dtors[ unqExpr->get_id() ] );
    679                                 } else { // remember dtors for last instance of unique expr
    680                                         dtors[ unqExpr->get_id() ] = fixer.stmtsToAddAfter;
    681                                 }
    682683                                return deref;
    683684                        }
  • src/InitTweak/GenInit.cc

    rddbde34 ra28bc02  
    142142                // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address
    143143                // is being returned
    144                 // Note: under the assumption that assignments return *this, checking for ?=? here is an optimization, since it shouldn't be necessary to copy construct `this`. This is a temporary optimization until reference types are added, at which point this should be removed, along with the analogous optimization in copy constructor generation.
    145                 if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_lvalue() ) {
     144                if ( returnStmt->get_expr() && returnVals.size() == 1 && ! returnVals.front()->get_type()->get_lvalue() ) {
    146145                        // explicitly construct the return value using the return expression and the retVal object
    147146                        assertf( returnVals.front()->get_name() != "", "Function %s has unnamed return value\n", funcName.c_str() );
Note: See TracChangeset for help on using the changeset viewer.