Ignore:
Timestamp:
Jun 28, 2016, 3:33:01 PM (8 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:
4dcea3f
Parents:
888cbe4
Message:

overhaul MLE code, attach label to break/continue statements so it can be used to generate dtor calls, mutate continue statements into goto statements so dtor generation works correctly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    r888cbe4 re39aa0f  
    3535bool ctorp = false;
    3636bool cpctorp = false;
    37 bool dtorp = true;
     37bool dtorp = false;
    3838#define PRINT( text ) if ( ctordtorp ) { text }
    3939#define CP_CTOR_PRINT( text ) if ( ctordtorp || cpctorp ) { text }
     
    499499                                curVars.insert( objDecl );
    500500                        }
    501                         return Parent::visit( stmt );
     501                        Parent::visit( stmt );
    502502                }
    503503
     
    563563                }
    564564
     565                // Handle break/continue/goto in the same manner as C++.
     566                // Basic idea: any objects that are in scope at the BranchStmt
     567                // but not at the labelled (target) statement must be destructed.
     568                // If there are any objects in scope at the target location but
     569                // not at the BranchStmt then those objects would be uninitialized
     570                // so notify the user of the error.
     571                // See C++ Reference 6.6 Jump Statements for details.
    565572                void InsertDtors::handleGoto( BranchStmt * stmt ) {
    566                         assert( stmt->get_type() == BranchStmt::Goto );
     573                        assert( stmt->get_target() != "" && "BranchStmt missing a label" );
    567574                        // S_L = lvars = set of objects in scope at label definition
    568575                        // S_G = curVars = set of objects in scope at goto statement
     
    602609
    603610                void InsertDtors::visit( BranchStmt * stmt ) {
    604                         // TODO: adding to the end of a block isn't sufficient, since
    605                         // return/break/goto should trigger destructor when block is left.
    606611                        switch( stmt->get_type() ) {
    607612                                case BranchStmt::Continue:
    608613                                case BranchStmt::Break:
    609                                 // xxx - easiest thing to do: generate a label for every break/continue
    610                                 // this label is unused, so attach unused attribute to it
    611                                 // finally, all of these cases can be the same (this is less efficient than it could be,
    612                                 // because the S_L-S_G check is unnecessary [the set should always be empty], but this
    613                                 // serves as a bit of a sanity check, so I'm okay with it.)
    614                                         // xxx - this is insufficient, because multiple blocks can be opened in a switch or loop
    615                                         insertDtors( reverseDeclOrder.front().begin(), reverseDeclOrder.front().end(), back_inserter( stmtsToAdd ) );
    616                                         break;
     614                                // could optimize the break/continue case, because the S_L-S_G check
     615                                // is unnecessary (this set should always be empty), but it serves
     616                                // as a small sanity check.
    617617                                case BranchStmt::Goto:
    618618                                        handleGoto( stmt );
Note: See TracChangeset for help on using the changeset viewer.