Changeset 5b40f30


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, 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

Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r972e6f7 r5b40f30  
    212212                printDesignators( init->get_designators() );
    213213                output << "{ ";
    214                 genCommaList( init->begin_initializers(), init->end_initializers() );
     214                if ( init->begin_initializers() == init->end_initializers() ) {
     215                        // illegal to leave initializer list empty for scalar initializers,
     216                        // but always legal to have 0
     217                        output << "0";
     218                } else {
     219                        genCommaList( init->begin_initializers(), init->end_initializers() );
     220                }
    215221                output << " }";
    216222        }
  • 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 ) );
  • src/SymTab/Autogen.cc

    r972e6f7 r5b40f30  
    8080                fExpr->get_args().push_back( dstselect );
    8181
    82                 Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) );
    83                 fExpr->get_args().push_back( srcselect );
     82                if ( srcParam ) {
     83                        Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) );
     84                        fExpr->get_args().push_back( srcselect );
     85                }
    8486
    8587                *out++ = new ExprStmt( noLabels, fExpr );
  • src/SynTree/Initializer.cc

    r972e6f7 r5b40f30  
    5454}
    5555
    56 ListInit::ListInit( std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed )
     56ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed )
    5757        : Initializer( maybeConstructed), initializers( _initializers ), designators( _designators ) {
    5858}
  • src/SynTree/Initializer.h

    r972e6f7 r5b40f30  
    8282class ListInit : public Initializer {
    8383  public:
    84         ListInit( std::list<Initializer*> &,
     84        ListInit( const std::list<Initializer*> &initializers,
    8585                          const std::list<Expression *> &designators, bool maybeConstructed = false );
    8686        virtual ~ListInit();
Note: See TracChangeset for help on using the changeset viewer.