Ignore:
Timestamp:
Mar 15, 2016, 3:16:53 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
dac0aa9
Parents:
972e6f7
Message:

generate correct empty list initializer, ensure function return value is not incorrectly destructed before it is returned, do not add src parameter to autogenerated routines when they take a single argument

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/RemoveInit.cc

    r972e6f7 r5b40f30  
    2929        namespace {
    3030                const std::list<Label> noLabels;
     31                const std::list<Expression *> noDesignators;
    3132        }
    3233
     
    112113                // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address
    113114                // is being returned
    114                 // xxx - this should construct rather than assign
    115115                if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_isLvalue()  ) {
    116                         ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), 0 );
     116                        // ensure return value is not destructed by explicitly creating
     117                        // an empty SingleInit node wherein maybeConstruct is false
     118                        ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), new ListInit( std::list<Initializer*>(), noDesignators, false ) );
    117119                        stmtsToAdd.push_back( new DeclStmt( noLabels, newObj ) );
    118120
    119                         UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
    120                         assign->get_args().push_back( new AddressExpr (new NameExpr( newObj->get_name() ) ) );
    121                         assign->get_args().push_back( returnStmt->get_expr() );
    122                         stmtsToAdd.push_back(new ExprStmt(noLabels, assign));
     121                        // and explicitly create the constructor expression separately
     122                        UntypedExpr *construct = new UntypedExpr( new NameExpr( "?{}" ) );
     123                        construct->get_args().push_back( new AddressExpr (new NameExpr( newObj->get_name() ) ) );
     124                        construct->get_args().push_back( returnStmt->get_expr() );
     125                        stmtsToAdd.push_back(new ExprStmt(noLabels, construct));
    123126
    124127                        returnStmt->set_expr( new VariableExpr( newObj ) );
Note: See TracChangeset for help on using the changeset viewer.