- Timestamp:
- Aug 24, 2016, 12:36:33 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 0555f4b
- Parents:
- f87408e
- Location:
- src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/GenType.h
rf87408e r79970ed 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // GenType.h -- 7 // GenType.h -- 8 8 // 9 9 // Author : Richard C. Bilson -
src/Common/utility.h
rf87408e r79970ed 144 144 145 145 template < typename T > 146 std::string toString ( T value ) { 146 void toString_single ( std::ostream & os, const T & value ) { 147 os << value; 148 } 149 150 template < typename T, typename... Params > 151 void toString_single ( std::ostream & os, const T & value, const Params & ... params ) { 152 os << value; 153 toString_single( os, params ... ); 154 } 155 156 template < typename ... Params > 157 std::string toString ( const Params & ... params ) { 147 158 std::ostringstream os; 148 os << value; // << std::ends;159 toString_single( os, params... ); 149 160 return os.str(); 150 161 } … … 218 229 } 219 230 231 template< typename T > 232 void warn_single( const T & arg ) { 233 std::cerr << arg << std::endl; 234 } 235 236 template< typename T, typename... Params > 237 void warn_single(const T & arg, const Params & ... params ) { 238 std::cerr << arg; 239 warn_single( params... ); 240 } 241 242 template< typename... Params > 243 void warn( const Params & ... params ) { 244 std::cerr << "Warning: "; 245 warn_single( params... ); 246 } 247 220 248 #endif // _UTILITY_H 221 249 -
src/InitTweak/FixInit.cc
rf87408e r79970ed 33 33 #include "GenPoly/PolyMutator.h" 34 34 #include "SynTree/AddStmtVisitor.h" 35 #include "CodeGen/GenType.h" // for warnings 35 36 36 37 bool ctordtorp = false; … … 174 175 virtual Expression * mutate( ImplicitCopyCtorExpr * impCpCtorExpr ); 175 176 }; 177 178 class WarnStructMembers : public Visitor { 179 public: 180 typedef Visitor Parent; 181 /// warn if a user-defined constructor or destructor is missing calls for 182 /// a struct member or if a member is used before constructed 183 static void warnings( std::list< Declaration * > & translationUnit ); 184 185 virtual void visit( FunctionDecl * funcDecl ); 186 187 virtual void visit( MemberExpr * memberExpr ); 188 virtual void visit( ApplicationExpr * appExpr ); 189 190 private: 191 void handleFirstParam( Expression * firstParam ); 192 193 FunctionDecl * function = 0; 194 std::set< DeclarationWithType * > unhandled; 195 ObjectDecl * thisParam = 0; 196 }; 176 197 } // namespace 177 198 … … 187 208 // FixCopyCtors must happen after FixInit, so that destructors are placed correctly 188 209 FixCopyCtors::fixCopyCtors( translationUnit ); 210 211 WarnStructMembers::warnings( translationUnit ); 189 212 } 190 213 … … 231 254 } 232 255 256 void WarnStructMembers::warnings( std::list< Declaration * > & translationUnit ) { 257 if ( true ) { // fix this condition to skip this pass if warnings aren't enabled 258 WarnStructMembers warner; 259 acceptAll( translationUnit, warner ); 260 } 261 } 262 233 263 Expression * InsertImplicitCalls::mutate( ApplicationExpr * appExpr ) { 234 264 appExpr = dynamic_cast< ApplicationExpr * >( Mutator::mutate( appExpr ) ); … … 242 272 FunctionType * ftype = dynamic_cast< FunctionType * >( GenPoly::getFunctionType( funcDecl->get_type() ) ); 243 273 assert( ftype ); 244 if ( ( funcDecl->get_name() == "?{}"|| funcDecl->get_name() == "?=?") && ftype->get_parameters().size() == 2 ) {274 if ( (isConstructor( funcDecl->get_name() ) || funcDecl->get_name() == "?=?") && ftype->get_parameters().size() == 2 ) { 245 275 Type * t1 = ftype->get_parameters().front()->get_type(); 246 276 Type * t2 = ftype->get_parameters().back()->get_type(); … … 253 283 return appExpr; 254 284 } // if 255 } else if ( funcDecl->get_name() == "^?{}") {285 } else if ( isDestructor( funcDecl->get_name() ) ) { 256 286 // correctness: never copy construct arguments to a destructor 257 287 return appExpr; … … 670 700 } // switch 671 701 } 702 703 bool checkWarnings( FunctionDecl * funcDecl ) { 704 // only check for warnings if the current function is a user-defined 705 // constructor or destructor 706 if ( ! funcDecl ) return false; 707 if ( ! funcDecl->get_statements() ) return false; 708 return isCtorDtor( funcDecl->get_name() ) && ! LinkageSpec::isOverridable( funcDecl->get_linkage() ); 709 } 710 711 void WarnStructMembers::visit( FunctionDecl * funcDecl ) { 712 WarnStructMembers old = *this; 713 *this = WarnStructMembers(); 714 715 function = funcDecl; 716 if ( checkWarnings( funcDecl ) ) { 717 FunctionType * type = funcDecl->get_functionType(); 718 assert( ! type->get_parameters().empty() ); 719 thisParam = safe_dynamic_cast< ObjectDecl * >( type->get_parameters().front() ); 720 PointerType * ptrType = safe_dynamic_cast< PointerType * > ( thisParam->get_type() ); 721 StructInstType * structType = dynamic_cast< StructInstType * >( ptrType->get_base() ); 722 if ( structType ) { 723 StructDecl * structDecl = structType->get_baseStruct(); 724 for ( Declaration * member : structDecl->get_members() ) { 725 if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) { 726 // record all of the struct type's members that need to be constructed or 727 // destructed by the end of the function 728 unhandled.insert( field ); 729 } 730 } 731 } 732 } 733 Parent::visit( funcDecl ); 734 735 for ( DeclarationWithType * member : unhandled ) { 736 // emit a warning for each unhandled member 737 warn( "in ", CodeGen::genType( function->get_functionType(), function->get_name() ), ", member ", member->get_name(), " may not have been ", isConstructor( funcDecl->get_name() ) ? "constructed" : "destructed" ); 738 } 739 740 *this = old; 741 } 742 743 void WarnStructMembers::visit( ApplicationExpr * appExpr ) { 744 if ( ! checkWarnings( function ) ) return; 745 746 std::string fname = getFunctionName( appExpr ); 747 if ( fname == function->get_name() ) { 748 // call to same kind of function 749 Expression * firstParam = appExpr->get_args().front(); 750 751 if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( firstParam ) ) { 752 // if calling another constructor on thisParam, assume that function handles 753 // all members - if it doesn't a warning will appear in that function. 754 if ( varExpr->get_var() == thisParam ) { 755 unhandled.clear(); 756 } 757 } else { 758 // if first parameter is a member expression then 759 // remove the member from unhandled set. 760 handleFirstParam( firstParam ); 761 } 762 } else if ( fname == "?=?" && isIntrinsicCallExpr( appExpr ) ) { 763 // forgive use of intrinsic assignment to construct, since instrinsic constructors 764 // codegen as assignment anyway. 765 assert( appExpr->get_args().size() == 2 ); 766 handleFirstParam( appExpr->get_args().front() ); 767 } 768 769 Parent::visit( appExpr ); 770 } 771 772 void WarnStructMembers::handleFirstParam( Expression * firstParam ) { 773 using namespace std; 774 if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( firstParam ) ) { 775 if ( MemberExpr * memberExpr = dynamic_cast< MemberExpr * >( addrExpr->get_arg() ) ) { 776 if ( ApplicationExpr * deref = dynamic_cast< ApplicationExpr * >( memberExpr->get_aggregate() ) ) { 777 if ( getFunctionName( deref ) == "*?" && deref->get_args().size() == 1 ) { 778 if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( deref->get_args().front() ) ) { 779 if ( varExpr->get_var() == thisParam ) { 780 unhandled.erase( memberExpr->get_member() ); 781 } 782 } 783 } 784 } 785 } 786 } 787 } 788 789 void WarnStructMembers::visit( MemberExpr * memberExpr ) { 790 if ( ! checkWarnings( function ) ) return; 791 if ( ! isConstructor( function->get_name() ) ); 792 793 if ( ApplicationExpr * deref = dynamic_cast< ApplicationExpr * >( memberExpr->get_aggregate() ) ) { 794 if ( getFunctionName( deref ) == "*?" && deref->get_args().size() == 1 ) { 795 if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( deref->get_args().front() ) ) { 796 if ( varExpr->get_var() == thisParam ) { 797 if ( unhandled.count( memberExpr->get_member() ) ) { 798 // emit a warning because a member was used before it was constructed 799 warn( "in ", CodeGen::genType( function->get_functionType(), function->get_name() ), ", member ", memberExpr->get_member()->get_name(), " used before being constructed" ); 800 } 801 } 802 } 803 } 804 } 805 Parent::visit( memberExpr ); 806 } 672 807 } // namespace 673 808 } // namespace InitTweak -
src/InitTweak/InitTweak.cc
rf87408e r79970ed 433 433 } 434 434 435 bool isConstructor( const std::string & str ) { return str == "?{}"; } 436 bool isDestructor( const std::string & str ) { return str == "^?{}"; } 437 bool isCtorDtor( const std::string & str ) { return isConstructor( str ) || isDestructor( str ); } 435 438 } -
src/InitTweak/InitTweak.h
rf87408e r79970ed 26 26 // helper functions for initialization 27 27 namespace InitTweak { 28 bool isConstructor( const std::string & ); 29 bool isDestructor( const std::string & ); 30 bool isCtorDtor( const std::string & ); 31 28 32 /// transform Initializer into an argument list that can be passed to a call expression 29 33 std::list< Expression * > makeInitList( Initializer * init ); -
src/Parser/LinkageSpec.cc
rf87408e r79970ed 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // LinkageSpec.cc -- 8 // 7 // LinkageSpec.cc -- 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:22:09 2015 … … 12 12 // Last Modified On : Sun Aug 21 12:32:53 2016 13 13 // Update Count : 17 14 // 14 // 15 15 16 16 #include <string> … … 32 32 33 33 std::string LinkageSpec::toString( LinkageSpec::Spec linkage ) { 34 assert( linkage >= 0 && linkage < LinkageSpec::NoOfSpecs ); 34 35 static const char *linkageKinds[LinkageSpec::NoOfSpecs] = { 35 36 "intrinsic", "Cforall", "C", "automatically generated", "compiler built-in", … … 39 40 40 41 bool LinkageSpec::isDecoratable( Spec spec ) { 42 assert( spec >= 0 && spec < LinkageSpec::NoOfSpecs ); 41 43 static bool decoratable[LinkageSpec::NoOfSpecs] = { 42 44 // Intrinsic, Cforall, C, AutoGen, Compiler 43 true, true, false, true, false, 45 true, true, false, true, false, 44 46 }; 45 47 return decoratable[spec]; … … 47 49 48 50 bool LinkageSpec::isGeneratable( Spec spec ) { 51 assert( spec >= 0 && spec < LinkageSpec::NoOfSpecs ); 49 52 static bool generatable[LinkageSpec::NoOfSpecs] = { 50 53 // Intrinsic, Cforall, C, AutoGen, Compiler 51 true, true, true, true, false, 54 true, true, true, true, false, 52 55 }; 53 56 return generatable[spec]; … … 55 58 56 59 bool LinkageSpec::isOverridable( Spec spec ) { 60 assert( spec >= 0 && spec < LinkageSpec::NoOfSpecs ); 57 61 static bool overridable[LinkageSpec::NoOfSpecs] = { 58 62 // Intrinsic, Cforall, C, AutoGen, Compiler 59 true, false, false, true, false, 63 true, false, false, true, false, 60 64 }; 61 65 return overridable[spec]; … … 63 67 64 68 bool LinkageSpec::isBuiltin( Spec spec ) { 69 assert( spec >= 0 && spec < LinkageSpec::NoOfSpecs ); 65 70 static bool builtin[LinkageSpec::NoOfSpecs] = { 66 71 // Intrinsic, Cforall, C, AutoGen, Compiler 67 true, false, false, false, true, 72 true, false, false, false, true, 68 73 }; 69 74 return builtin[spec]; -
src/ResolvExpr/AlternativeFinder.cc
rf87408e r79970ed 244 244 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { 245 245 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) { 246 alternatives.push_back( Alternative( new MemberExpr( dwt ->clone(), expr->clone() ), env, newCost ) );246 alternatives.push_back( Alternative( new MemberExpr( dwt, expr->clone() ), env, newCost ) ); 247 247 renameTypes( alternatives.back().expr ); 248 248 } else { … … 418 418 // /// Map of declaration uniqueIds (intended to be the assertions in an AssertionSet) to their parents and the number of times they've been included 419 419 //typedef std::unordered_map< UniqueId, std::unordered_map< UniqueId, unsigned > > AssertionParentSet; 420 420 421 421 static const int recursionLimit = /*10*/ 4; ///< Limit to depth of recursion satisfaction 422 422 //static const unsigned recursionParentLimit = 1; ///< Limit to the number of times an assertion can recursively use itself … … 429 429 } 430 430 } 431 431 432 432 template< typename ForwardIterator, typename OutputIterator > 433 void inferRecursive( ForwardIterator begin, ForwardIterator end, const Alternative &newAlt, OpenVarSet &openVars, const SymTab::Indexer &decls, const AssertionSet &newNeed, /*const AssertionParentSet &needParents,*/ 433 void inferRecursive( ForwardIterator begin, ForwardIterator end, const Alternative &newAlt, OpenVarSet &openVars, const SymTab::Indexer &decls, const AssertionSet &newNeed, /*const AssertionParentSet &needParents,*/ 434 434 int level, const SymTab::Indexer &indexer, OutputIterator out ) { 435 435 if ( begin == end ) { … … 469 469 std::cerr << std::endl; 470 470 ) 471 471 472 472 AssertionSet newHave, newerNeed( newNeed ); 473 473 TypeEnvironment newEnv( newAlt.env ); … … 847 847 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { 848 848 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) { 849 alternatives.push_back( Alternative( new OffsetofExpr( aggInst->clone(), dwt ->clone()), env, Cost::zero ) );849 alternatives.push_back( Alternative( new OffsetofExpr( aggInst->clone(), dwt ), env, Cost::zero ) ); 850 850 renameTypes( alternatives.back().expr ); 851 851 } else { -
src/SymTab/Validate.cc
rf87408e r79970ed 58 58 #include "Autogen.h" 59 59 #include "ResolvExpr/typeops.h" 60 #include <algorithm> 60 61 61 62 #define debugPrint( x ) if ( doDebug ) { std::cout << x; } … … 372 373 } // if 373 374 374 applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) ); 375 // need to clone members of the context for ownership purposes 376 std::list< Declaration * > members; 377 std::transform( ctx->get_members().begin(), ctx->get_members().end(), back_inserter( members ), [](Declaration * dwt) { return dwt->clone(); } ); 378 379 applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), members.begin(), members.end(), back_inserter( contextInst->get_members() ) ); 375 380 } 376 381 -
src/SynTree/AggregateDecl.cc
rf87408e r79970ed 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // AggregateDecl.cc -- 7 // AggregateDecl.cc -- 8 8 // 9 9 // Author : Richard C. Bilson -
src/SynTree/Expression.cc
rf87408e r79970ed 200 200 201 201 OffsetofExpr::OffsetofExpr( const OffsetofExpr &other ) : 202 Expression( other ), type( maybeClone( other.type ) ), member( maybeClone( other.member )) {}202 Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {} 203 203 204 204 OffsetofExpr::~OffsetofExpr() { 205 205 delete type; 206 delete member;207 206 } 208 207 … … 359 358 assert( member ); 360 359 os << std::string( indent + 2, ' ' ); 360 os << (void*)member << " "; 361 361 member->print( os, indent + 2 ); 362 362 os << std::endl; -
src/SynTree/TypeSubstitution.h
rf87408e r79970ed 169 169 TypeSubstitution sub = TypeSubstitution( formalBegin, formalEnd, actual ); 170 170 for ( std::list< Declaration* >::iterator i = memberBegin; i != memberEnd; ++i ) { 171 Declaration *newdecl = (*i)->clone(); 172 sub.apply( newdecl ); 173 *out++ = newdecl; 171 sub.apply( *i ); 172 *out++ = *i; 174 173 } // for 175 174 }
Note: See TracChangeset
for help on using the changeset viewer.