Ignore:
Timestamp:
Jun 2, 2017, 5:02:25 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
f94ca7e
Parents:
a4683611 (diff), 93684eb (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 plg2:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/working/exception/impl/main.c

    ra4683611 r2c6c893  
    11#include <stdio.h>
    22#include "except.h"
     3
     4// Requires -fexceptions to work.
    35
    46#define EXCEPTION 2
     
    2628extern int this_exception;
    2729_Unwind_Reason_Code foo_try_match() {
    28         return this_exception == 3 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
     30        printf(" (foo_try_match called)");
     31        return this_exception == EXCEPTION ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
    2932}
    3033
     
    3437//for details
    3538__attribute__((noinline))
    36 void try( void (*try_block)(), void (*catch_block)() )
     39void try( void (*try_block)(), void (*catch_block)(),
     40          _Unwind_Reason_Code (*match_block)() )
    3741{
     42        volatile int xy = 0;
     43        printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy);
     44
    3845        //Setup statments
    3946        //These 2 statments won't actually result in any code,
     
    95102        "       .uleb128 .CATCH-try\n"                          //Hanlder landing pad adress  (relative to start of function)
    96103        "       .uleb128 1\n"                                           //Action code, gcc seems to use always 0
    97         //Beyond this point we don't match gcc data'
    98         "       .uleb128 foo_try_match-try\n"                   //Handler routine to check if the exception is matched
    99104        ".LLSDACSECFA2:\n"                                              //BODY end
    100105        "       .text\n"                                                        //TABLE footer
     
    122127
    123128        //Actual call to the try block
    124         try( foo_try_block, foo_catch_block );
     129        try( foo_try_block, foo_catch_block, foo_try_match );
    125130
    126131        printf( "Foo exited normally\n" );
    127132}
    128133
     134// Not in main.cfa
     135void fy() {
     136        // Currently not destroyed if the exception is caught in fee.
     137        raii_t a = { "Fy dtor" };
     138
     139        void fy_try_block() {
     140                raii_t b = { "Fy try dtor" };
     141
     142                throw( 3 );
     143        }
     144
     145        void fy_catch_block() {
     146                printf("Fy caught exception\n");
     147        }
     148
     149        _Unwind_Reason_Code fy_match_block() {
     150                return this_exception == 2 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
     151        }
     152
     153        try(fy_try_block, fy_catch_block, fy_match_block);
     154
     155        printf( "Fy exited normally\n" );
     156}
     157
     158void fee() {
     159        raii_t a = { "Fee dtor" };
     160
     161        void fee_try_block() {
     162                raii_t b = { "Fee try dtor" };
     163
     164                fy();
     165
     166                printf("fy returned\n");
     167        }
     168
     169        void fee_catch_block() {
     170                printf("Fee caught exception\n");
     171        }
     172
     173        _Unwind_Reason_Code fee_match_block() {
     174                return this_exception == 3 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
     175        }
     176
     177        try(fee_try_block, fee_catch_block, fee_match_block);
     178
     179        printf( "Fee exited normally\n" );
     180}
     181// End not in main.cfa
     182
    129183int main() {
    130184        raii_t a = { "Main dtor" };
    131185
    132         for (unsigned int i = 0 ; i < 100000000 ; ++i) foo();
     186        //for (unsigned int i = 0 ; i < 100000000 ; ++i)
     187        foo();
     188        fee();
    133189
    134190        printf("End of program reached\n");
Note: See TracChangeset for help on using the changeset viewer.