File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ static char *dup_string(const char *value);
5151static void * xmalloc (size_t size );
5252static int compare_entries_by_index (const void * lhs , const void * rhs );
5353static int occurrence_survives_dce (const CseOccurrence * occ );
54+ static void eliminate_unreachable (AstStmtList * list );
5455
5556void optimize_program (AstProgram * program )
5657{
@@ -89,6 +90,7 @@ static void optimize_block(AstBlock *block)
8990 {
9091 optimize_statement_children (block -> statements .items [i ]);
9192 }
93+ eliminate_unreachable (& block -> statements );
9294}
9395
9496static void optimize_statement_children (AstStmt * stmt )
@@ -608,3 +610,24 @@ static char *expr_make_key(const AstExpr *expr)
608610 return dup_string ("<unsupported>" );
609611 }
610612}
613+
614+ static void eliminate_unreachable (AstStmtList * list ) {
615+ if (!list ) return ;
616+
617+ int after_return = 0 ;
618+ size_t write = 0 ;
619+
620+ for (size_t i = 0 ; i < list -> count ; i ++ ) {
621+ AstStmt * s = list -> items [i ];
622+ if (after_return ) {
623+ continue ;
624+ }
625+ list -> items [write ++ ] = s ;
626+ if (s -> kind == STMT_RETURN ) {
627+ after_return = 1 ;
628+ }
629+ }
630+
631+ list -> count = write ;
632+ }
633+
You can’t perform that action at this time.
0 commit comments