Changes in / [7bf7fb9:04273e9]
- Location:
- src
- Files:
-
- 7 edited
-
InitTweak/InitTweak.cc (modified) (2 diffs)
-
InitTweak/InitTweak.h (modified) (1 diff)
-
ResolvExpr/Resolver.cc (modified) (2 diffs)
-
SymTab/Autogen.cc (modified) (2 diffs)
-
SymTab/Validate.cc (modified) (3 diffs)
-
tests/.expect/32/extension.txt (modified) (3 diffs)
-
tests/.expect/64/extension.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.cc
r7bf7fb9 r04273e9 291 291 } 292 292 293 namespace { 294 template <typename Predicate> 295 bool allofCtorDtor( Statement * stmt, const Predicate & pred ) { 296 std::list< Expression * > callExprs; 297 collectCtorDtorCalls( stmt, callExprs ); 298 // if ( callExprs.empty() ) return false; // xxx - do I still need this check? 299 return std::all_of( callExprs.begin(), callExprs.end(), pred); 300 } 301 } 302 293 303 bool isIntrinsicSingleArgCallStmt( Statement * stmt ) { 294 std::list< Expression * > callExprs; 295 collectCtorDtorCalls( stmt, callExprs ); 296 // if ( callExprs.empty() ) return false; // xxx - do I still need this check? 297 return std::all_of( callExprs.begin(), callExprs.end(), []( Expression * callExpr ){ 304 return allofCtorDtor( stmt, []( Expression * callExpr ){ 298 305 if ( ApplicationExpr * appExpr = isIntrinsicCallExpr( callExpr ) ) { 299 306 assert( ! appExpr->get_function()->get_results().empty() ); … … 303 310 } 304 311 return false; 312 }); 313 } 314 315 bool isIntrinsicCallStmt( Statement * stmt ) { 316 return allofCtorDtor( stmt, []( Expression * callExpr ) { 317 return isIntrinsicCallExpr( callExpr ); 305 318 }); 306 319 } -
src/InitTweak/InitTweak.h
r7bf7fb9 r04273e9 41 41 /// Intended to be used for default ctor/dtor calls, but might have use elsewhere. 42 42 /// Currently has assertions that make it less than fully general. 43 bool isIntrinsicSingleArgCallStmt( Statement * expr ); 43 bool isIntrinsicSingleArgCallStmt( Statement * stmt ); 44 45 /// True if stmt is a call statement where the function called is intrinsic. 46 bool isIntrinsicCallStmt( Statement * stmt ); 44 47 45 48 /// get all Ctor/Dtor call expressions from a Statement -
src/ResolvExpr/Resolver.cc
r7bf7fb9 r04273e9 446 446 } else if ( StructInstType * st = dynamic_cast< StructInstType * >( initContext ) ) { 447 447 resolveAggrInit( st->get_baseStruct(), iter, end ); 448 } else if ( UnionInstType * st = dynamic_cast< UnionInstType * >( initContext ) ) {448 } else if ( UnionInstType * st = dynamic_cast< UnionInstType * >( initContext ) ) { 449 449 resolveAggrInit( st->get_baseUnion(), iter, end ); 450 } else if ( TypeInstType * tt = dynamic_cast< TypeInstType * >( initContext ) ) { 451 Type * base = tt->get_baseType()->get_base(); 452 if ( base ) { 453 // know the implementation type, so try using that as the initContext 454 initContext = base; 455 visit( listInit ); 456 } else { 457 // missing implementation type -- might be an unknown type variable, so try proceeding with the current init context 458 Visitor::visit( listInit ); 459 } 450 460 } else { 461 assert( dynamic_cast< BasicType * >( initContext ) || dynamic_cast< PointerType * >( initContext ) ); 451 462 // basic types are handled here 452 463 Visitor::visit( listInit ); … … 539 550 } 540 551 541 // xxx - todo542 // if ( InitTweak::isIntrinsicCallStmt( ctorInit->get_ctor() ) ) {543 // // can reduce the constructor down to a SingleInit using the544 // // second argument from the ctor call545 // }546 547 552 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->get_dtor() ) ) { 548 553 delete ctorInit->get_dtor(); 549 554 ctorInit->set_dtor( NULL ); 550 555 } 556 557 // xxx - todo -- what about arrays? 558 // if ( dtor == NULL && InitTweak::isIntrinsicCallStmt( ctorInit->get_ctor() ) ) { 559 // // can reduce the constructor down to a SingleInit using the 560 // // second argument from the ctor call, since 561 // delete ctorInit->get_ctor(); 562 // ctorInit->set_ctor( NULL ); 563 564 // Expression * arg = 565 // ctorInit->set_init( new SingleInit( arg ) ); 566 // } 551 567 } 552 568 } // namespace ResolvExpr -
src/SymTab/Autogen.cc
r7bf7fb9 r04273e9 68 68 copy->get_args().push_back( new VariableExpr( dstParam ) ); 69 69 copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) ); 70 copy->get_args().push_back( new SizeofExpr( unionType) );70 copy->get_args().push_back( new SizeofExpr( srcParam->get_type()->clone() ) ); 71 71 72 72 *out++ = new ExprStmt( noLabels, copy ); … … 420 420 copyCtorDecl->set_statements( assignDecl->get_statements()->clone() ); 421 421 422 // create a constructor which takes the first member type as a parameter. 423 // for example, for Union A { int x; double y; }; generate 424 // void ?{}(A *, int) 425 // This is to mimic C's behaviour which initializes the first member of the union. 426 std::list<Declaration *> memCtors; 427 for ( Declaration * member : aggregateDecl->get_members() ) { 428 if ( DeclarationWithType * field = dynamic_cast< DeclarationWithType * >( member ) ) { 429 ObjectDecl * srcParam = new ObjectDecl( "src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, field->get_type()->clone(), 0 ); 430 431 FunctionType * memCtorType = ctorType->clone(); 432 memCtorType->get_parameters().push_back( srcParam ); 433 FunctionDecl * ctor = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, memCtorType, new CompoundStmt( noLabels ), true, false ); 434 ctor->fixUniqueId(); 435 436 makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( ctor->get_statements()->get_kids() ) ); 437 memCtors.push_back( ctor ); 438 // only generate a ctor for the first field 439 break; 440 } 441 } 442 422 443 declsToAdd.push_back( assignDecl ); 423 444 declsToAdd.push_back( ctorDecl ); 424 445 declsToAdd.push_back( copyCtorDecl ); 425 446 declsToAdd.push_back( dtorDecl ); 447 declsToAdd.splice( declsToAdd.end(), memCtors ); 426 448 } 427 449 -
src/SymTab/Validate.cc
r7bf7fb9 r04273e9 162 162 163 163 typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap; 164 typedef std::map< std::string, TypeDecl * > TypeDeclMap; 164 165 TypedefMap typedefNames; 166 TypeDeclMap typedeclNames; 165 167 int scopeLevel; 166 168 }; … … 521 523 delete typeInst; 522 524 return ret; 525 } else { 526 TypeDeclMap::const_iterator base = typedeclNames.find( typeInst->get_name() ); 527 assert( base != typedeclNames.end() ); 528 typeInst->set_baseType( base->second->clone() ); 523 529 } // if 524 530 return typeInst; … … 565 571 typedefNames.erase( i ) ; 566 572 } // if 573 574 typedeclNames[ typeDecl->get_name() ] = typeDecl; 567 575 return typeDecl; 568 576 } -
src/tests/.expect/32/extension.txt
r7bf7fb9 r04273e9 70 70 static inline void ___destructor__F_P2uU_autogen___1(union U *___dst__P2uU_1){ 71 71 } 72 static inline void ___constructor__F_P2uUi_autogen___1(union U *___dst__P2uU_1, int __src__i_1){ 73 void *_tmp_cp_ret2; 74 ((void)((_tmp_cp_ret2=__builtin_memcpy(((void *)___dst__P2uU_1), ((const void *)(&__src__i_1)), sizeof(int ))) , _tmp_cp_ret2)); 75 ((void)(_tmp_cp_ret2) /* ^?{} */); 76 } 72 77 __extension__ enum E { 73 78 __R__C2eE_1, … … 89 94 __extension__ int __c__i_2; 90 95 ((void)(__extension__ __a__i_2=(__extension__ __b__i_2+__extension__ __c__i_2))); 91 int _tmp_cp_ret 2;92 ((void)((_tmp_cp_ret 2=__extension__ __fred__Fi_i__1(3)) , _tmp_cp_ret2));93 ((void)(_tmp_cp_ret 2) /* ^?{} */);96 int _tmp_cp_ret3; 97 ((void)((_tmp_cp_ret3=__extension__ __fred__Fi_i__1(3)) , _tmp_cp_ret3)); 98 ((void)(_tmp_cp_ret3) /* ^?{} */); 94 99 ((void)__extension__ sizeof(3)); 95 100 ((void)__extension__ (((int )(3!=0)) || ((int )(4!=0)))); … … 100 105 ((void)((__extension__ __a__i_2 , __extension__ __b__i_2) , __extension__ __c__i_2)); 101 106 } 102 __attribute__ ((constructor(),)) static void _init_extension(void){103 int _global_init0;104 ((void)((*((int *)(&__a__i_1)))=_global_init0) /* ?{} */);105 int _global_init1;106 ((void)((*((int *)(&__b__i_1)))=_global_init1) /* ?{} */);107 int _global_init2;108 ((void)((*((int *)(&__c__i_1)))=_global_init2) /* ?{} */);109 }110 __attribute__ ((destructor(),)) static void _destroy_extension(void){111 ((void)((*((int *)(&__c__i_1)))) /* ^?{} */);112 ((void)((*((int *)(&__b__i_1)))) /* ^?{} */);113 ((void)((*((int *)(&__a__i_1)))) /* ^?{} */);114 } -
src/tests/.expect/64/extension.txt
r7bf7fb9 r04273e9 70 70 static inline void ___destructor__F_P2uU_autogen___1(union U *___dst__P2uU_1){ 71 71 } 72 static inline void ___constructor__F_P2uUi_autogen___1(union U *___dst__P2uU_1, int __src__i_1){ 73 void *_tmp_cp_ret2; 74 ((void)((_tmp_cp_ret2=__builtin_memcpy(((void *)___dst__P2uU_1), ((const void *)(&__src__i_1)), sizeof(int ))) , _tmp_cp_ret2)); 75 ((void)(_tmp_cp_ret2) /* ^?{} */); 76 } 72 77 __extension__ enum E { 73 78 __R__C2eE_1, … … 89 94 __extension__ int __c__i_2; 90 95 ((void)(__extension__ __a__i_2=(__extension__ __b__i_2+__extension__ __c__i_2))); 91 int _tmp_cp_ret 2;92 ((void)((_tmp_cp_ret 2=__extension__ __fred__Fi_i__1(3)) , _tmp_cp_ret2));93 ((void)(_tmp_cp_ret 2) /* ^?{} */);96 int _tmp_cp_ret3; 97 ((void)((_tmp_cp_ret3=__extension__ __fred__Fi_i__1(3)) , _tmp_cp_ret3)); 98 ((void)(_tmp_cp_ret3) /* ^?{} */); 94 99 ((void)__extension__ sizeof(3)); 95 100 ((void)__extension__ (((int )(3!=0)) || ((int )(4!=0))));
Note:
See TracChangeset
for help on using the changeset viewer.