Changeset bdf40650 for src/GenPoly
- Timestamp:
- Nov 20, 2024, 5:19:15 PM (4 weeks ago)
- Branches:
- master
- Children:
- de7b7a5
- Parents:
- d945be9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Lvalue.cpp
rd945be9 rbdf40650 365 365 ret = new ast::AddressExpr( ret->location, ret ); 366 366 } 367 // Must keep cast if types are different. 367 368 if ( !ResolvExpr::typesCompatible( 368 369 srcType, 369 370 strict_dynamic_cast<ast::ReferenceType const *>( dstType )->base ) ) { 370 // Must keep cast if cast-to type is different from the actual type.371 371 return ast::mutate_field( expr, &ast::CastExpr::arg, ret ); 372 372 } … … 503 503 } 504 504 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*)& 508 ast::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 505 521 ast::Expr const * CollapseAddressDeref::postvisit( 506 522 ast::AddressExpr const * expr ) { … … 514 530 return ret; 515 531 } 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 ); 529 534 } 530 535 return expr;
Note: See TracChangeset
for help on using the changeset viewer.