Changeset de7b7a5 for src/GenPoly


Ignore:
Timestamp:
Nov 21, 2024, 8:38:47 AM (4 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
10a9479d, e25ef8c
Parents:
1cd2839 (diff), bdf40650 (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 plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/GenPoly/Lvalue.cpp

    r1cd2839 rde7b7a5  
    365365                        ret = new ast::AddressExpr( ret->location, ret );
    366366                }
     367                // Must keep cast if types are different.
    367368                if ( !ResolvExpr::typesCompatible(
    368369                                srcType,
    369370                                strict_dynamic_cast<ast::ReferenceType const *>( dstType )->base ) ) {
    370                         // Must keep cast if cast-to type is different from the actual type.
    371371                        return ast::mutate_field( expr, &ast::CastExpr::arg, ret );
    372372                }
     
    503503}
    504504
     505/// Recursively move an address expression underneath casts. Casts are not
     506/// lvalue expressions in C but are sometimes considered as such in Cforall,
     507/// (passes like InstantiateGeneric can add them.) - &(int) => (int*)&
     508ast::Expr const * moveAddressUnderCast( ast::AddressExpr const * expr ) {
     509        if ( !dynamic_cast<ast::CastExpr const *>( expr->arg.get() ) ) {
     510                return expr;
     511        }
     512        auto mutExpr = ast::mutate( expr );
     513        auto mutCast = strict_dynamic_cast<ast::CastExpr *>(
     514                        ast::mutate( mutExpr->arg.release() ) );
     515        mutExpr->arg = mutCast->arg;
     516        mutCast->arg = moveAddressUnderCast( mutExpr );
     517        mutCast->result = new ast::PointerType( mutCast->result );
     518        return mutCast;
     519}
     520
    505521ast::Expr const * CollapseAddressDeref::postvisit(
    506522                ast::AddressExpr const * expr ) {
     
    514530                        return ret;
    515531                }
    516         } else if ( auto cast = dynamic_cast<ast::CastExpr const *>( arg ) ) {
    517                 // Need to move cast to pointer type out a level since address of
    518                 // pointer is not valid C code (can be introduced in prior passes,
    519                 // e.g., InstantiateGeneric)
    520                 if ( ast::getPointerBase( cast->result ) ) {
    521                         auto mutExpr = ast::mutate( expr );
    522                         auto mutCast = strict_dynamic_cast<ast::CastExpr *>(
    523                                         ast::mutate( mutExpr->arg.release() ) );
    524                         mutExpr->arg = mutCast->arg;
    525                         mutCast->arg = mutExpr;
    526                         mutCast->result = new ast::PointerType( mutCast->result );
    527                         return mutCast;
    528                 }
     532        } else {
     533                return moveAddressUnderCast( expr );
    529534        }
    530535        return expr;
Note: See TracChangeset for help on using the changeset viewer.