Changeset 5b40f30 for src/InitTweak


Ignore:
Timestamp:
Mar 15, 2016, 3:16:53 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, 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, pthread-emulation, qualifiedEnum, 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

Location:
src/InitTweak
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    r972e6f7 r5b40f30  
    4848        }
    4949
    50         // in the case where an object has an initializer and a polymorphic type, insert an assignment immediately after the
    51         // declaration. This will (seemingly) cause the later phases to do the right thing with the assignment
    5250        ObjectDecl *FixInit::mutate( ObjectDecl *objDecl ) {
    5351                if ( ConstructorInit * ctorInit = dynamic_cast< ConstructorInit * >( objDecl->get_init() ) ) {
     
    7977                                if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( exprStmt->get_expr() ) ) {
    8078                                        if ( VariableExpr * function = dynamic_cast< VariableExpr * >( appExpr->get_function() ) ) {
     79                                                // check for Intrinsic only - don't want to remove all overridable dtors because autogenerated dtor
     80                                                // will call all member dtors, and some members may have a user defined dtor.
    8181                                                if ( function->get_var()->get_name() == "^?{}" && function->get_var()->get_linkage() == LinkageSpec::Intrinsic ) {
    8282                                                        statements.erase(it++);
  • 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.