Changeset 2c6c893


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

Files:
6 edited

Legend:

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

    ra4683611 r2c6c893  
    44
    55#include "lsda.h"
     6
     7// This macro should be the only thing that needs to change across machines.
     8// struct _Unwind_Context * -> _Unwind_Reason_Code(*)()
     9#define MATCHER_FROM_CONTEXT(ptr_to_context) \
     10        (*(_Unwind_Reason_Code(**)())(_Unwind_GetCFA(ptr_to_context) + 8))
     11
    612
    713//Global which defines the current exception
     
    1723                     struct _Unwind_Exception* unwind_exception, struct _Unwind_Context* context)
    1824{
     25        printf("CFA: 0x%lx\n", _Unwind_GetCFA(context));
     26
    1927        //DEBUG
    2028        printf("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context);
     
    111119
    112120                                        //Get a function pointer from the relative offset and call it
    113                                         _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher;                                     
     121                                        // _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher;                                   
     122
     123                                        _Unwind_Reason_Code (*matcher)() =
     124                                                MATCHER_FROM_CONTEXT(context);
    114125                                        _Unwind_Reason_Code ret = matcher();
    115126
  • 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");
  • doc/working/exception/reference.c

    ra4683611 r2c6c893  
    114114// __builtin_eh_return_data_regno(^) ^=[0..3]? gives index.
    115115
     116// Locally we also seem to have:
     117_Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
    116118
    117119// GCC (Dwarf2 ?) Frame Layout Macros
    118 // https://gcc.gnu.org/onlinedocs/gccint/Frame-Layout.html
     120// See: https://gcc.gnu.org/onlinedocs/gccint/Frame-Layout.html
     121// Include from: ???
    119122
    120123FIRST_PARAM_OFFSET(fundecl)
  • src/Common/PassVisitor.impl.h

    ra4683611 r2c6c893  
    11#pragma once
     2
     3#define VISIT_START( node )  \
     4        call_previsit( node ); \
     5
     6#define VISIT_END( node )                \
     7        return call_postvisit( node ); \
    28
    39#define MUTATE_START( node )  \
    410        call_premutate( node ); \
    511
    6 
    712#define MUTATE_END( type, node )                \
    813        return call_postmutate< type * >( node ); \
     
    1015
    1116#define VISIT_BODY( node )    \
    12         call_previsit( node );  \
     17        VISIT_START( node );  \
    1318        Visitor::visit( node ); \
    14         call_postvisit( node ); \
     19        VISIT_END( node ); \
    1520
    1621
     
    3944                if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); }
    4045                try {
    41                         *i = (*i)->accept( *this );
     46                        (*i)->accept( *this );
    4247                } catch ( SemanticError &e ) {
    4348                        errors.append( e );
     
    7883        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
    7984
    80         Statement *newStmt = maybeVisit( stmt, *this );
     85        maybeAccept( stmt, *this );
    8186
    8287        StmtList_t* beforeStmts = get_beforeStmts();
    8388        StmtList_t* afterStmts  = get_afterStmts();
    8489
    85         if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; }
     90        if( empty(beforeStmts) && empty(afterStmts) ) { return stmt; }
    8691
    8792        CompoundStmt *compound = new CompoundStmt( noLabels );
    8893        if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); }
    89         compound->get_kids().push_back( newStmt );
     94        compound->get_kids().push_back( stmt );
    9095        if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); }
    9196        return compound;
     
    187192}
    188193
     194//--------------------------------------------------------------------------
     195// CompoundStmt
    189196template< typename pass_type >
    190197void PassVisitor< pass_type >::visit( CompoundStmt * node ) {
    191         VISIT_BODY( node );
     198        VISIT_START( node );
     199        call_beginScope();
     200
     201        visitStatementList( node->get_kids() );
     202
     203        call_endScope();
     204        VISIT_END( node );
    192205}
    193206
     
    203216}
    204217
     218//--------------------------------------------------------------------------
     219// ExprStmt
    205220template< typename pass_type >
    206221void PassVisitor< pass_type >::visit( ExprStmt * node ) {
    207         VISIT_BODY( node );
     222        VISIT_START( node );
     223        call_beginScope();
     224
     225        visitExpression( node->get_expr() );
     226
     227        call_endScope();
     228        VISIT_END( node );
    208229}
    209230
     
    222243}
    223244
     245//--------------------------------------------------------------------------
     246// IfStmt
    224247template< typename pass_type >
    225248void PassVisitor< pass_type >::visit( IfStmt * node ) {
    226         VISIT_BODY( node );
     249        VISIT_START( node );
     250
     251        visitExpression( node->get_condition() );
     252        node->set_thenPart ( visitStatement( node->get_thenPart() ) );
     253        node->set_elsePart ( visitStatement( node->get_elsePart() ) );
     254
     255        VISIT_END( node );
    227256}
    228257
     
    238267}
    239268
     269//--------------------------------------------------------------------------
     270// WhileStmt
    240271template< typename pass_type >
    241272void PassVisitor< pass_type >::visit( WhileStmt * node ) {
    242         VISIT_BODY( node );
     273        VISIT_START( node );
     274
     275        visitExpression( node->get_condition() );
     276        node->set_body( visitStatement( node->get_body() ) );
     277
     278        VISIT_END( node );
    243279}
    244280
     
    253289}
    254290
    255 
     291//--------------------------------------------------------------------------
     292// WhileStmt
    256293template< typename pass_type >
    257294void PassVisitor< pass_type >::visit( ForStmt * node ) {
    258         VISIT_BODY( node );
     295        VISIT_START( node );
     296
     297        acceptAll( node->get_initialization(), *this );
     298        visitExpression( node->get_condition() );
     299        visitExpression( node->get_increment() );
     300        node->set_body( visitStatement( node->get_body() ) );
     301
     302        VISIT_END( node );
    259303}
    260304
     
    264308
    265309        mutateAll( node->get_initialization(), *this );
    266         node->set_condition(  mutateExpression( node->get_condition() ) );
    267         node->set_increment(  mutateExpression( node->get_increment() ) );
    268         node->set_body(  mutateStatement( node->get_body() ) );
     310        node->set_condition( mutateExpression( node->get_condition() ) );
     311        node->set_increment( mutateExpression( node->get_increment() ) );
     312        node->set_body( mutateStatement( node->get_body() ) );
    269313
    270314        MUTATE_END( Statement, node );
    271315}
    272316
     317//--------------------------------------------------------------------------
     318// SwitchStmt
    273319template< typename pass_type >
    274320void PassVisitor< pass_type >::visit( SwitchStmt * node ) {
    275         VISIT_BODY( node );
     321        VISIT_START( node );
     322
     323        visitExpression( node->get_condition() );
     324        visitStatementList( node->get_statements() );
     325
     326        VISIT_END( node );
    276327}
    277328
     
    286337}
    287338
     339//--------------------------------------------------------------------------
     340// SwitchStmt
    288341template< typename pass_type >
    289342void PassVisitor< pass_type >::visit( CaseStmt * node ) {
    290         VISIT_BODY( node );
     343        VISIT_START( node );
     344       
     345        visitExpression( node->get_condition() );
     346        visitStatementList( node->get_statements() );
     347       
     348        VISIT_END( node );
    291349}
    292350
     
    306364}
    307365
     366//--------------------------------------------------------------------------
     367// ReturnStmt
    308368template< typename pass_type >
    309369void PassVisitor< pass_type >::visit( ReturnStmt * node ) {
    310         VISIT_BODY( node );
     370        VISIT_START( node );
     371
     372        visitExpression( node->get_expr() );
     373
     374        VISIT_END( node );
    311375}
    312376
     
    320384}
    321385
     386//--------------------------------------------------------------------------
     387// TryStmt
    322388template< typename pass_type >
    323389void PassVisitor< pass_type >::visit( TryStmt * node ) {
    324         VISIT_BODY( node );
     390        VISIT_START( node );
     391
     392        maybeAccept( node->get_block(), *this );
     393        acceptAll( node->get_catchers(), *this );
     394
     395        VISIT_END( node );
    325396}
    326397
     
    335406}
    336407
     408//--------------------------------------------------------------------------
     409// CatchStmt
    337410template< typename pass_type >
    338411void PassVisitor< pass_type >::visit( CatchStmt * node ) {
    339         VISIT_BODY( node );
     412        VISIT_START( node );
     413
     414        node->set_body( visitStatement( node->get_body() ) );
     415        maybeAccept( node->get_decl(), *this );
     416
     417        VISIT_END( node );
    340418}
    341419
     
    375453}
    376454
     455//--------------------------------------------------------------------------
     456// UntypedExpr
    377457template< typename pass_type >
    378458void PassVisitor< pass_type >::visit( UntypedExpr * node ) {
    379         VISIT_BODY( node );
     459        VISIT_START( node );
     460
     461        for ( auto expr : node->get_args() ) {
     462                visitExpression( expr );
     463        }
     464
     465        VISIT_END( node );
    380466}
    381467
     
    536622}
    537623
     624//--------------------------------------------------------------------------
     625// UntypedExpr
    538626template< typename pass_type >
    539627void PassVisitor< pass_type >::visit( StmtExpr * node ) {
    540         VISIT_BODY( node );
     628        VISIT_START( node );
     629
     630        // don't want statements from outer CompoundStmts to be added to this StmtExpr
     631        ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
     632        ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
     633        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
     634
     635        Visitor::visit( node );
     636
     637        VISIT_END( node );
    541638}
    542639
     
    640737}
    641738
     739//--------------------------------------------------------------------------
     740// UntypedExpr
    642741template< typename pass_type >
    643742void PassVisitor< pass_type >::visit( SingleInit * node ) {
    644         VISIT_BODY( node );
     743        VISIT_START( node );
     744
     745        visitExpression( node->get_value() );
     746
     747        VISIT_END( node );
    645748}
    646749
  • src/Makefile.am

    ra4683611 r2c6c893  
    4343driver_cfa_cpp_SOURCES = ${SRC}
    4444driver_cfa_cpp_LDADD = ${LEXLIB} -ldl                   # yywrap
    45 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -Werror -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
     45driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
    4646driver_cfa_cpp_LDFLAGS = -Xlinker -export-dynamic
    4747
  • src/Makefile.in

    ra4683611 r2c6c893  
    447447driver_cfa_cpp_SOURCES = ${SRC}
    448448driver_cfa_cpp_LDADD = ${LEXLIB} -ldl                   # yywrap
    449 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -Werror -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
     449driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
    450450driver_cfa_cpp_LDFLAGS = -Xlinker -export-dynamic
    451451all: $(BUILT_SOURCES)
Note: See TracChangeset for help on using the changeset viewer.