Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/GenInit.cc

    rc6976ba r9ff56e7  
    5454
    5555          protected:
    56                 FunctionType * ftype = nullptr;
     56                FunctionType * ftype;
    5757                std::string funcName;
    5858        };
     
    7171                // that need to be constructed or destructed
    7272                void previsit( StructDecl *aggregateDecl );
    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; }
     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; }
    8079
    8180                void previsit( CompoundStmt * compoundStmt );
     
    138137                std::list< DeclarationWithType * > & returnVals = ftype->get_returnVals();
    139138                assert( returnVals.size() == 0 || returnVals.size() == 1 );
    140                 // hands off if the function returns a reference - we don't want to allocate a temporary if a variable's address
     139                // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address
    141140                // is being returned
    142                 if ( returnStmt->get_expr() && returnVals.size() == 1 && ! dynamic_cast< ReferenceType * >( returnVals.front()->get_type() ) ) {
     141                if ( returnStmt->get_expr() && returnVals.size() == 1 && ! returnVals.front()->get_type()->get_lvalue() ) {
    143142                        // explicitly construct the return value using the return expression and the retVal object
    144143                        assertf( returnVals.front()->get_name() != "", "Function %s has unnamed return value\n", funcName.c_str() );
    145 
    146                         stmtsToAddBefore.push_back( genCtorDtor( "?{}", dynamic_cast< ObjectDecl *>( returnVals.front() ), returnStmt->get_expr() ) );
     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));
    147148
    148149                        // return the retVal object
     
    211212
    212213        bool CtorDtor::isManaged( Type * type ) const {
    213                 // at least for now, references are never constructed
    214                 if ( dynamic_cast< ReferenceType * >( type ) ) return false;
    215214                // need to clear and reset qualifiers when determining if a type is managed
    216215                ValueGuard< Type::Qualifiers > qualifiers( type->get_qualifiers() );
     
    239238                        std::list< DeclarationWithType * > & params = GenPoly::getFunctionType( dwt->get_type() )->get_parameters();
    240239                        assert( ! params.empty() );
    241                         Type * type = InitTweak::getPointerBase( params.front()->get_type() );
    242                         assert( type );
    243                         managedTypes.insert( SymTab::Mangler::mangle( type ) );
     240                        PointerType * type = safe_dynamic_cast< PointerType * >( params.front()->get_type() );
     241                        managedTypes.insert( SymTab::Mangler::mangle( type->get_base() ) );
    244242                }
    245243        }
     
    337335        }
    338336
    339         void CtorDtor::previsit( CompoundStmt * compoundStmt ) {
     337        void CtorDtor::previsit( __attribute__((unused)) CompoundStmt * compoundStmt ) {
    340338                GuardScope( managedTypes );
    341339        }
Note: See TracChangeset for help on using the changeset viewer.