- Timestamp:
- Apr 7, 2017, 6:12:50 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, 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:
- d919f47
- Parents:
- 3a48e283
- git-author:
- Aaron Moss <a3moss@…> (04/07/17 18:12:21)
- git-committer:
- Aaron Moss <a3moss@…> (04/07/17 18:12:50)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r3a48e283 ra0ad7dc 34 34 #include "Parser/ParseNode.h" 35 35 36 #include "SynTree/Attribute.h" 36 37 #include "SynTree/Constant.h" 37 38 #include "SynTree/Declaration.h" … … 165 166 using Parent::mutate; 166 167 168 PolyGenericCalculator(); 169 167 170 template< typename DeclClass > 168 171 DeclClass *handleDecl( DeclClass *decl, Type *type ); … … 198 201 ScopedSet< std::string > knownLayouts; ///< Set of generic type layouts known in the current scope, indexed by sizeofName 199 202 ScopedSet< std::string > knownOffsets; ///< Set of non-generic types for which the offset array exists in the current scope, indexed by offsetofName 203 UniqueName bufNamer; ///< Namer for VLA buffers 200 204 }; 201 205 … … 1452 1456 ////////////////////////////////////////// PolyGenericCalculator //////////////////////////////////////////////////// 1453 1457 1458 PolyGenericCalculator::PolyGenericCalculator() 1459 : Parent(), knownLayouts(), knownOffsets(), bufNamer( "_buf" ) {} 1460 1454 1461 void PolyGenericCalculator::beginTypeScope( Type *ty ) { 1455 1462 scopeTyVars.beginScope(); … … 1528 1535 if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) { 1529 1536 if ( findGeneric( objectDecl->get_type() ) ) { 1530 // change initialization of a polymorphic value object 1531 // to allocate storage with alloca1537 // change initialization of a polymorphic value object to allocate via a VLA 1538 // (alloca was previously used, but can't be safely used in loops) 1532 1539 Type *declType = objectDecl->get_type(); 1533 UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) ); 1534 alloc->get_args().push_back( new NameExpr( sizeofName( mangleType( declType ) ) ) ); 1540 std::string bufName = bufNamer.newName(); 1541 ObjectDecl *newBuf = new ObjectDecl( bufName, Type::StorageClasses(), LinkageSpec::C, 0, 1542 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::Kind::Char), new NameExpr( sizeofName( mangleType(declType) ) ), 1543 true, false, std::list<Attribute*>{ new Attribute( std::string{"aligned"}, std::list<Expression*>{ new ConstantExpr( Constant::from_int(8) ) } ) } ), 0 ); 1544 stmtsToAdd.push_back( new DeclStmt( noLabels, newBuf ) ); 1535 1545 1536 1546 delete objectDecl->get_init(); 1537 1547 1538 std::list<Expression*> designators; 1539 objectDecl->set_init( new SingleInit( alloc, designators, false ) ); // not constructed 1548 objectDecl->set_init( new SingleInit( new NameExpr( bufName ) ) ); 1540 1549 } 1541 1550 }
Note: See TracChangeset
for help on using the changeset viewer.