Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/GenInit.cc

    rbe9aa0f re35f30a  
    3030#include "InitTweak.h"             // for isConstExpr, InitExpander, checkIn...
    3131#include "Parser/LinkageSpec.h"    // for isOverridable, C
    32 #include "ResolvExpr/Resolver.h"
    3332#include "SymTab/Autogen.h"        // for genImplicitCall, SizeType
    3433#include "SymTab/Mangler.h"        // for Mangler
     
    4140#include "SynTree/Type.h"          // for Type, ArrayType, Type::Qualifiers
    4241#include "SynTree/Visitor.h"       // for acceptAll, maybeAccept
    43 #include "Tuples/Tuples.h"         // for maybeImpure
    4442
    4543namespace InitTweak {
     
    9189        };
    9290
    93         struct HoistArrayDimension final : public WithDeclsToAdd, public WithShortCircuiting, public WithGuards, public WithIndexer {
     91        struct HoistArrayDimension final : public WithDeclsToAdd, public WithShortCircuiting, public WithGuards {
    9492                /// hoist dimension from array types in object declaration so that it uses a single
    9593                /// const variable of type size_t, so that side effecting array dimensions are only
     
    106104                void premutate( FunctionType * ) { visit_children = false; }
    107105
    108                 // need this so that enumerators are added to the indexer, due to premutate(AggregateDecl *)
    109                 void premutate( EnumDecl * ) {}
    110 
    111106                void hoist( Type * type );
    112107
     
    140135                                if ( varExpr->var == retVal ) return;
    141136                        }
    142                         Statement * stmt = genCtorDtor( "?{}", retVal, returnStmt->expr );
    143                         assertf( stmt, "ReturnFixer: genCtorDtor returned nullptr: %s / %s", toString( retVal ).c_str(), toString( returnStmt->expr ).c_str() );
    144                         stmtsToAddBefore.push_back( stmt );
     137                        stmtsToAddBefore.push_back( genCtorDtor( "?{}", retVal, returnStmt->get_expr() ) );
    145138
    146139                        // return the retVal object
     
    185178                        if ( ! arrayType->get_dimension() ) return; // xxx - recursive call to hoist?
    186179
    187                         // need to resolve array dimensions in order to accurately determine if constexpr
    188                         ResolvExpr::findSingleExpression( arrayType->dimension, SymTab::SizeType->clone(), indexer );
    189                         // array is variable-length when the dimension is not constexpr
    190                         arrayType->isVarLen = ! isConstExpr( arrayType->dimension );
    191                         // don't need to hoist dimension if it's definitely pure - only need to if there's potential for side effects.
    192                         if ( ! Tuples::maybeImpure( arrayType->dimension ) ) return;
     180                        // don't need to hoist dimension if it's a constexpr - only need to if there's potential for side effects.
     181                        if ( isConstExpr( arrayType->get_dimension() ) ) return;
    193182
    194183                        ObjectDecl * arrayDimension = new ObjectDecl( dimensionName.newName(), storageClasses, LinkageSpec::C, 0, SymTab::SizeType->clone(), new SingleInit( arrayType->get_dimension() ) );
     
    205194        void HoistArrayDimension::premutate( FunctionDecl * ) {
    206195                GuardValue( inFunction );
    207                 inFunction = true;
    208196        }
    209197
     
    232220                Type * type = objDecl->get_type();
    233221                while ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) {
    234                         // must always construct VLAs with an initializer, since this is an error in C
    235                         if ( at->isVarLen && objDecl->init ) return true;
    236222                        type = at->get_base();
    237223                }
Note: See TracChangeset for help on using the changeset viewer.