Changeset 7f9968a


Ignore:
Timestamp:
Jun 24, 2020, 12:30:42 PM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
8b58bae
Parents:
a8a3485
Message:

Fixed a problem with 'throwResume;' translation and added some tests to check for similar problems.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ExceptTranslate.cc

    ra8a3485 r7f9968a  
    1010// Created On       : Wed Jun 14 16:49:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue May 26 10:56:00 2020
    13 // Update Count     : 16
     12// Last Modified On : Wed Jun 24 11:18:00 2020
     13// Update Count     : 17
    1414//
    1515
     
    7272                        ThrowStmt * throwStmt, const char * throwFunc );
    7373                Statement * create_terminate_rethrow( ThrowStmt * throwStmt );
    74                 Statement * create_resume_rethrow( ThrowStmt * throwStmt );
    7574
    7675        public:
     
    113112                        new UntypedExpr( new NameExpr( "__cfaehm_rethrow_terminate" ) )
    114113                        ) );
    115                 delete throwStmt;
    116                 return result;
    117         }
    118 
    119         Statement * ThrowMutatorCore::create_resume_rethrow(
    120                         ThrowStmt *throwStmt ) {
    121                 // return false;
    122                 Statement * result = new ReturnStmt(
    123                         new ConstantExpr( Constant::from_bool( false ) )
    124                         );
    125                 result->labels = throwStmt->labels;
    126114                delete throwStmt;
    127115                return result;
     
    167155                                return create_either_throw( throwStmt, "$throwResume" );
    168156                        } else if ( ResHandler == cur_context ) {
    169                                 return create_resume_rethrow( throwStmt );
     157                                // This has to be handled later.
     158                                return throwStmt;
    170159                        } else {
    171160                                abort("Invalid throwResume in %s at %i\n",
     
    196185                FunctionDecl * create_finally_wrapper( TryStmt * tryStmt );
    197186                ObjectDecl * create_finally_hook( FunctionDecl * finally_wrapper );
     187                Statement * create_resume_rethrow( ThrowStmt * throwStmt );
    198188
    199189                // Types used in translation, make sure to use clone.
     
    227217                void premutate( StructDecl *structDecl );
    228218                Statement * postmutate( TryStmt *tryStmt );
     219                Statement * postmutate( ThrowStmt *throwStmt );
    229220        };
    230221
     
    594585                        attributes
    595586                        );
     587        }
     588
     589        Statement * TryMutatorCore::create_resume_rethrow( ThrowStmt *throwStmt ) {
     590                // return false;
     591                Statement * result = new ReturnStmt(
     592                        new ConstantExpr( Constant::from_bool( false ) )
     593                        );
     594                result->labels = throwStmt->labels;
     595                delete throwStmt;
     596                return result;
    596597        }
    597598
     
    668669        }
    669670
     671        Statement * TryMutatorCore::postmutate( ThrowStmt *throwStmt ) {
     672                // Only valid `throwResume;` statements should remain. (2/3 checks)
     673                assert( ThrowStmt::Resume == throwStmt->kind && ! throwStmt->expr );
     674                return create_resume_rethrow( throwStmt );
     675        }
     676
    670677        void translateThrows( std::list< Declaration *> & translationUnit ) {
    671678                PassVisitor<ThrowMutatorCore> translator;
  • tests/exceptions/.expect/resume.txt

    ra8a3485 r7f9968a  
    3131inner catch
    3232outer catch
     33
     34throw
     35rethrow
     36handle
  • tests/exceptions/.expect/terminate.txt

    ra8a3485 r7f9968a  
    2929inner catch
    3030outer catch
     31
     32throw
     33rethrow
     34handle
  • tests/exceptions/resume.cfa

    ra8a3485 r7f9968a  
    88TRIVIAL_EXCEPTION(zen);
    99TRIVIAL_EXCEPTION(moment_of, zen);
     10
     11void in_void(void);
    1012
    1113int main(int argc, char * argv[]) {
     
    121123                printf("outer catch\n");
    122124        }
     125        printf("\n");
     126
     127        in_void();
    123128}
     129
     130// Do a throw and rethrow in a void function.
     131void in_void(void) {
     132        try {
     133                try {
     134                        printf("throw\n");
     135                        throwResume (zen){};
     136                } catchResume (zen *) {
     137                        printf("rethrow\n");
     138                        throwResume;
     139                }
     140        } catchResume (zen *) {
     141                printf("handle\n");
     142        }
     143}
  • tests/exceptions/terminate.cfa

    ra8a3485 r7f9968a  
    88TRIVIAL_EXCEPTION(zen);
    99TRIVIAL_EXCEPTION(moment_of, zen);
     10
     11void in_void(void);
    1012
    1113int main(int argc, char * argv[]) {
     
    121123                printf("outer catch\n");
    122124        }
     125        printf("\n");
     126
     127        in_void();
    123128}
     129
     130// Do a throw and rethrow in a void function.
     131void in_void(void) {
     132        try {
     133                try {
     134                        printf("throw\n");
     135                        throw (zen){};
     136                } catch (zen *) {
     137                        printf("rethrow\n");
     138                        throw;
     139                }
     140        } catch (zen *) {
     141                printf("handle\n");
     142        }
     143}
     144
Note: See TracChangeset for help on using the changeset viewer.