Changes in src/InitTweak/GenInit.cc [be9aa0f:e35f30a]
- File:
-
- 1 edited
-
src/InitTweak/GenInit.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/GenInit.cc
rbe9aa0f re35f30a 30 30 #include "InitTweak.h" // for isConstExpr, InitExpander, checkIn... 31 31 #include "Parser/LinkageSpec.h" // for isOverridable, C 32 #include "ResolvExpr/Resolver.h"33 32 #include "SymTab/Autogen.h" // for genImplicitCall, SizeType 34 33 #include "SymTab/Mangler.h" // for Mangler … … 41 40 #include "SynTree/Type.h" // for Type, ArrayType, Type::Qualifiers 42 41 #include "SynTree/Visitor.h" // for acceptAll, maybeAccept 43 #include "Tuples/Tuples.h" // for maybeImpure44 42 45 43 namespace InitTweak { … … 91 89 }; 92 90 93 struct HoistArrayDimension final : public WithDeclsToAdd, public WithShortCircuiting, public WithGuards , public WithIndexer{91 struct HoistArrayDimension final : public WithDeclsToAdd, public WithShortCircuiting, public WithGuards { 94 92 /// hoist dimension from array types in object declaration so that it uses a single 95 93 /// const variable of type size_t, so that side effecting array dimensions are only … … 106 104 void premutate( FunctionType * ) { visit_children = false; } 107 105 108 // need this so that enumerators are added to the indexer, due to premutate(AggregateDecl *)109 void premutate( EnumDecl * ) {}110 111 106 void hoist( Type * type ); 112 107 … … 140 135 if ( varExpr->var == retVal ) return; 141 136 } 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() ) ); 145 138 146 139 // return the retVal object … … 185 178 if ( ! arrayType->get_dimension() ) return; // xxx - recursive call to hoist? 186 179 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; 193 182 194 183 ObjectDecl * arrayDimension = new ObjectDecl( dimensionName.newName(), storageClasses, LinkageSpec::C, 0, SymTab::SizeType->clone(), new SingleInit( arrayType->get_dimension() ) ); … … 205 194 void HoistArrayDimension::premutate( FunctionDecl * ) { 206 195 GuardValue( inFunction ); 207 inFunction = true;208 196 } 209 197 … … 232 220 Type * type = objDecl->get_type(); 233 221 while ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) { 234 // must always construct VLAs with an initializer, since this is an error in C235 if ( at->isVarLen && objDecl->init ) return true;236 222 type = at->get_base(); 237 223 }
Note:
See TracChangeset
for help on using the changeset viewer.