Changes in src/InitTweak/FixInit.cc [092528b:627f585]
- File:
 - 
      
- 1 edited
 
- 
          
  src/InitTweak/FixInit.cc (modified) (7 diffs)
 
 
Legend:
- Unmodified
 - Added
 - Removed
 
- 
      
src/InitTweak/FixInit.cc
r092528b r627f585 21 21 #include <unordered_set> 22 22 #include "InitTweak.h" 23 #include "GenInit.h"24 23 #include "FixInit.h" 25 24 #include "FixGlobalInit.h" … … 87 86 /// create and resolve ctor/dtor expression: fname(var, [cpArg]) 88 87 Expression * makeCtorDtor( const std::string & fname, ObjectDecl * var, Expression * cpArg = NULL ); 88 Expression * makeCtorDtor( const std::string & fname, Expression * thisArg, Expression * cpArg = NULL ); 89 89 /// true if type does not need to be copy constructed to ensure correctness 90 90 bool skipCopyConstruct( Type * type ); 91 91 void copyConstructArg( Expression *& arg, ImplicitCopyCtorExpr * impCpCtorExpr ); 92 void destructRet( ObjectDecl* ret, ImplicitCopyCtorExpr * impCpCtorExpr );92 void destructRet( Expression * ret, ImplicitCopyCtorExpr * impCpCtorExpr ); 93 93 94 94 TypeSubstitution * env; … … 398 398 Expression * ResolveCopyCtors::makeCtorDtor( const std::string & fname, ObjectDecl * var, Expression * cpArg ) { 399 399 assert( var ); 400 // arrays are not copy constructed, so this should always be an ExprStmt 401 ImplicitCtorDtorStmt * stmt = genCtorDtor( fname, var, cpArg ); 402 ExprStmt * exprStmt = safe_dynamic_cast< ExprStmt * >( stmt->get_callStmt() ); 403 Expression * untyped = exprStmt->get_expr(); 400 return makeCtorDtor( fname, new AddressExpr( new VariableExpr( var ) ), cpArg ); 401 } 402 403 Expression * ResolveCopyCtors::makeCtorDtor( const std::string & fname, Expression * thisArg, Expression * cpArg ) { 404 assert( thisArg ); 405 UntypedExpr * untyped = new UntypedExpr( new NameExpr( fname ) ); 406 untyped->get_args().push_back( thisArg ); 407 if (cpArg) untyped->get_args().push_back( cpArg->clone() ); 404 408 405 409 // resolve copy constructor … … 416 420 } // if 417 421 418 delete stmt;422 delete untyped; 419 423 return resolved; 420 424 } … … 452 456 } 453 457 454 void ResolveCopyCtors::destructRet( ObjectDecl* ret, ImplicitCopyCtorExpr * impCpCtorExpr ) {455 impCpCtorExpr->get_dtors().push_front( makeCtorDtor( "^?{}", ret) );458 void ResolveCopyCtors::destructRet( Expression * ret, ImplicitCopyCtorExpr * impCpCtorExpr ) { 459 impCpCtorExpr->get_dtors().push_front( makeCtorDtor( "^?{}", new AddressExpr( ret ) ) ); 456 460 } 457 461 … … 483 487 if ( ! result->get_isLvalue() ) { 484 488 // destructing lvalue returns is bad because it can cause multiple destructor calls to the same object - the returned object is not a temporary 485 destructRet( ret, impCpCtorExpr );489 destructRet( new VariableExpr( ret ), impCpCtorExpr ); 486 490 } 487 491 } // for … … 511 515 last->set_expr( makeCtorDtor( "?{}", ret, last->get_expr() ) ); 512 516 513 stmtExpr->get_dtors().push_front( makeCtorDtor( "^?{}", ret) );517 stmtExpr->get_dtors().push_front( makeCtorDtor( "^?{}", new AddressExpr( new VariableExpr( ret ) ) ) ); 514 518 } // if 515 519  
  Note:
 See   TracChangeset
 for help on using the changeset viewer.