Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/GenInit.cc

    r9ff56e7 rc6976ba  
    5454
    5555          protected:
    56                 FunctionType * ftype;
     56                FunctionType * ftype = nullptr;
    5757                std::string funcName;
    5858        };
     
    7171                // that need to be constructed or destructed
    7272                void previsit( StructDecl *aggregateDecl );
    73                 void previsit( __attribute__((unused)) UnionDecl    * aggregateDecl ) { visit_children = false; }
    74                 void previsit( __attribute__((unused)) EnumDecl     * aggregateDecl ) { visit_children = false; }
    75                 void previsit( __attribute__((unused)) TraitDecl    * aggregateDecl ) { visit_children = false; }
    76                 void previsit( __attribute__((unused)) TypeDecl     * typeDecl )      { visit_children = false; }
    77                 void previsit( __attribute__((unused)) TypedefDecl  * typeDecl )      { visit_children = false; }
    78                 void previsit( __attribute__((unused)) FunctionType * funcType )      { visit_children = false; }
     73                void previsit( UnionDecl *aggregateDecl ) { visit_children = false; }
     74                void previsit( EnumDecl *aggregateDecl ) { visit_children = false; }
     75                void previsit( TraitDecl *aggregateDecl ) { visit_children = false; }
     76                void previsit( TypeDecl *typeDecl ) { visit_children = false; }
     77                void previsit( TypedefDecl *typeDecl ) { visit_children = false; }
     78
     79                void previsit( FunctionType *funcType ) { visit_children = false; }
    7980
    8081                void previsit( CompoundStmt * compoundStmt );
     
    137138                std::list< DeclarationWithType * > & returnVals = ftype->get_returnVals();
    138139                assert( returnVals.size() == 0 || returnVals.size() == 1 );
    139                 // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address
     140                // hands off if the function returns a reference - we don't want to allocate a temporary if a variable's address
    140141                // is being returned
    141                 if ( returnStmt->get_expr() && returnVals.size() == 1 && ! returnVals.front()->get_type()->get_lvalue() ) {
     142                if ( returnStmt->get_expr() && returnVals.size() == 1 && ! dynamic_cast< ReferenceType * >( returnVals.front()->get_type() ) ) {
    142143                        // explicitly construct the return value using the return expression and the retVal object
    143144                        assertf( returnVals.front()->get_name() != "", "Function %s has unnamed return value\n", funcName.c_str() );
    144                         UntypedExpr *construct = new UntypedExpr( new NameExpr( "?{}" ) );
    145                         construct->get_args().push_back( new AddressExpr( new VariableExpr( returnVals.front() ) ) );
    146                         construct->get_args().push_back( returnStmt->get_expr() );
    147                         stmtsToAddBefore.push_back(new ExprStmt(noLabels, construct));
     145
     146                        stmtsToAddBefore.push_back( genCtorDtor( "?{}", dynamic_cast< ObjectDecl *>( returnVals.front() ), returnStmt->get_expr() ) );
    148147
    149148                        // return the retVal object
     
    212211
    213212        bool CtorDtor::isManaged( Type * type ) const {
     213                // at least for now, references are never constructed
     214                if ( dynamic_cast< ReferenceType * >( type ) ) return false;
    214215                // need to clear and reset qualifiers when determining if a type is managed
    215216                ValueGuard< Type::Qualifiers > qualifiers( type->get_qualifiers() );
     
    238239                        std::list< DeclarationWithType * > & params = GenPoly::getFunctionType( dwt->get_type() )->get_parameters();
    239240                        assert( ! params.empty() );
    240                         PointerType * type = safe_dynamic_cast< PointerType * >( params.front()->get_type() );
    241                         managedTypes.insert( SymTab::Mangler::mangle( type->get_base() ) );
     241                        Type * type = InitTweak::getPointerBase( params.front()->get_type() );
     242                        assert( type );
     243                        managedTypes.insert( SymTab::Mangler::mangle( type ) );
    242244                }
    243245        }
     
    335337        }
    336338
    337         void CtorDtor::previsit( __attribute__((unused)) CompoundStmt * compoundStmt ) {
     339        void CtorDtor::previsit( CompoundStmt * compoundStmt ) {
    338340                GuardScope( managedTypes );
    339341        }
Note: See TracChangeset for help on using the changeset viewer.