Changeset fea7ca7 for src/InitTweak
- Timestamp:
- Apr 29, 2016, 12:26:50 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- d8ba086
- Parents:
- a0fdbd5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
ra0fdbd5 rfea7ca7 10 10 // Created On : Wed Jan 13 16:29:30 2016 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Apr 28 12:25:14201612 // Last Modified On : Fri Apr 29 12:25:40 2016 13 13 // Update Count : 30 14 14 // … … 231 231 callExpr->set_env( impCpCtorExpr->get_env()->clone() ); 232 232 for ( Type * result : appExpr->get_results() ) { 233 ObjectDecl * ret = new ObjectDecl( retNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, result->clone(), 0 ); 233 result = result->clone(); 234 impCpCtorExpr->get_env()->apply( result ); 235 ObjectDecl * ret = new ObjectDecl( retNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, result, 0 ); 234 236 ret->get_type()->set_isConst( false ); 235 237 impCpCtorExpr->get_returnDecls().push_back( ret ); … … 285 287 // add that onto the assignment expression so that later steps have the necessary information 286 288 assign->add_result( returnDecl->get_type()->clone() ); 287 // return new CommaExpr( assign, new VariableExpr( returnDecl ) ); 288 return assign; 289 290 Expression * retExpr = new CommaExpr( assign, new VariableExpr( returnDecl ) ); 291 if ( callExpr->get_results().front()->get_isLvalue() ) { 292 // lvalue returning functions are funny. Lvalue.cc inserts a *? in front of any 293 // lvalue returning non-intrinsic function. Add an AddressExpr to the call to negate 294 // the derefence and change the type of the return temporary from T to T* to properly 295 // capture the return value. Then dereference the result of the comma expression, since 296 // the lvalue returning call was originally wrapped with an AddressExpr. 297 // Effectively, this turns 298 // lvalue T f(); 299 // &*f() 300 // into 301 // T * tmp_cp_retN; 302 // tmp_cp_ret_N = &*(tmp_cp_ret_N = &*f(), tmp_cp_ret); 303 // which work out in terms of types, but is pretty messy. It would be nice to find a better way. 304 assign->get_args().back() = new AddressExpr( assign->get_args().back() ); 305 306 Type * resultType = returnDecl->get_type()->clone(); 307 returnDecl->set_type( new PointerType( Type::Qualifiers(), returnDecl->get_type() ) ); 308 UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) ); 309 deref->get_args().push_back( retExpr ); 310 deref->add_result( resultType ); 311 retExpr = deref; 312 } 313 return retExpr; 289 314 } else { 290 315 return callExpr;
Note: See TracChangeset
for help on using the changeset viewer.