Ignore:
Timestamp:
Jan 5, 2018, 3:21:42 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
65deb18, cae28da
Parents:
5c4f2c2 (diff), b834e98 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    r5c4f2c2 r5b51f5e  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // FixInit.h --
     7// FixInit.cc --
    88//
    99// Author           : Rob Schluntz
     
    365365                        // arrays are not copy constructed, so this should always be an ExprStmt
    366366                        ImplicitCtorDtorStmt * stmt = genCtorDtor( fname, var, cpArg );
    367                         ExprStmt * exprStmt = strict_dynamic_cast< ExprStmt * >( stmt->get_callStmt() );
     367                        assertf( stmt, "ResolveCopyCtors: genCtorDtor returned nullptr: %s / %s / %s", fname.c_str(), toString( var ).c_str(), toString( cpArg ).c_str() );
     368                        ExprStmt * exprStmt = strict_dynamic_cast< ExprStmt * >( stmt->callStmt );
    368369                        Expression * resolved = exprStmt->expr;
    369370                        exprStmt->expr = nullptr; // take ownership of expr
     
    382383                        } // if
    383384                        delete stmt;
     385                        if ( TupleAssignExpr * assign = dynamic_cast< TupleAssignExpr * >( resolved ) ) {
     386                                // fix newly generated StmtExpr
     387                                postvisit( assign->stmtExpr );
     388                        }
    384389                        return resolved;
    385390                }
     
    475480                                static UniqueName retNamer("_tmp_stmtexpr_ret");
    476481
    477                                 // create variable that will hold the result of the stmt expr
    478482                                result = result->clone();
    479483                                env->apply( result );
     484                                if ( ! InitTweak::isConstructable( result ) ) {
     485                                        delete result;
     486                                        return;
     487                                }
     488
     489                                // create variable that will hold the result of the stmt expr
    480490                                ObjectDecl * ret = ObjectDecl::newObject( retNamer.newName(), result, nullptr );
    481                                 ret->get_type()->set_const( false );
    482                                 stmtExpr->get_returnDecls().push_front( ret );
     491                                ret->type->set_const( false );
     492                                stmtExpr->returnDecls.push_front( ret );
    483493
    484494                                // must have a non-empty body, otherwise it wouldn't have a result
    485                                 CompoundStmt * body = stmtExpr->get_statements();
     495                                CompoundStmt * body = stmtExpr->statements;
    486496                                assert( ! body->get_kids().empty() );
    487497                                // must be an ExprStmt, otherwise it wouldn't have a result
    488498                                ExprStmt * last = strict_dynamic_cast< ExprStmt * >( body->get_kids().back() );
    489                                 last->set_expr( makeCtorDtor( "?{}", ret, last->get_expr() ) );
    490 
    491                                 stmtExpr->get_dtors().push_front( makeCtorDtor( "^?{}", ret ) );
     499                                last->expr = makeCtorDtor( "?{}", ret, last->get_expr() );
     500
     501                                stmtExpr->dtors.push_front( makeCtorDtor( "^?{}", ret ) );
    492502                        } // if
    493503                }
     
    590600                        // to the outer context, rather than inside of the statement expression.
    591601                        visit_children = false;
    592                         std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids();
     602                        std::list< Statement * > & stmts = stmtExpr->statements->get_kids();
    593603                        for ( Statement *& stmt : stmts ) {
    594604                                stmt = stmt->acceptMutator( *visitor );
    595605                        } // for
    596                         assert( stmtExpr->get_result() );
    597                         Type * result = stmtExpr->get_result();
     606                        assert( stmtExpr->result );
     607                        Type * result = stmtExpr->result;
    598608                        if ( ! result->isVoid() ) {
    599                                 for ( ObjectDecl * obj : stmtExpr->get_returnDecls() ) {
     609                                for ( ObjectDecl * obj : stmtExpr->returnDecls ) {
    600610                                        stmtsToAddBefore.push_back( new DeclStmt( obj ) );
    601611                                } // for
    602612                                // add destructors after current statement
    603                                 for ( Expression * dtor : stmtExpr->get_dtors() ) {
     613                                for ( Expression * dtor : stmtExpr->dtors ) {
    604614                                        stmtsToAddAfter.push_back( new ExprStmt( dtor ) );
    605615                                } // for
    606616                                // must have a non-empty body, otherwise it wouldn't have a result
    607617                                assert( ! stmts.empty() );
    608                                 assert( ! stmtExpr->get_returnDecls().empty() );
    609                                 stmts.push_back( new ExprStmt( new VariableExpr( stmtExpr->get_returnDecls().front() ) ) );
    610                                 stmtExpr->get_returnDecls().clear();
    611                                 stmtExpr->get_dtors().clear();
    612                         }
    613                         assert( stmtExpr->get_returnDecls().empty() );
    614                         assert( stmtExpr->get_dtors().empty() );
     618                                assertf( ! stmtExpr->returnDecls.empty() || stmtExpr->dtors.empty(), "StmtExpr returns non-void, but no return decls: %s", toString( stmtExpr ).c_str() );
     619                                // if there is a return decl, add a use as the last statement; will not have return decl on non-constructable returns
     620                                if ( ! stmtExpr->returnDecls.empty() ) {
     621                                        stmts.push_back( new ExprStmt( new VariableExpr( stmtExpr->returnDecls.front() ) ) );
     622                                }
     623                                stmtExpr->returnDecls.clear();
     624                                stmtExpr->dtors.clear();
     625                        }
     626                        assert( stmtExpr->returnDecls.empty() );
     627                        assert( stmtExpr->dtors.empty() );
    615628                }
    616629
Note: See TracChangeset for help on using the changeset viewer.