Changeset c51b5a3 for src/GenPoly/Box.cc


Ignore:
Timestamp:
Apr 7, 2017, 6:20:58 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
f92aa32
Parents:
af68f0a (diff), d919f47 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    raf68f0a rc51b5a3  
    3434#include "Parser/ParseNode.h"
    3535
     36#include "SynTree/Attribute.h"
    3637#include "SynTree/Constant.h"
    3738#include "SynTree/Declaration.h"
     
    165166                        using Parent::mutate;
    166167
     168                        PolyGenericCalculator();
     169
    167170                        template< typename DeclClass >
    168171                        DeclClass *handleDecl( DeclClass *decl, Type *type );
     
    198201                        ScopedSet< std::string > knownLayouts;          ///< Set of generic type layouts known in the current scope, indexed by sizeofName
    199202                        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
    200204                };
    201205
     
    14521456////////////////////////////////////////// PolyGenericCalculator ////////////////////////////////////////////////////
    14531457
     1458                PolyGenericCalculator::PolyGenericCalculator()
     1459                        : Parent(), knownLayouts(), knownOffsets(), bufNamer( "_buf" ) {}
     1460
    14541461                void PolyGenericCalculator::beginTypeScope( Type *ty ) {
    14551462                        scopeTyVars.beginScope();
     
    15281535                        if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) {
    15291536                                if ( findGeneric( objectDecl->get_type() ) ) {
    1530                                         // change initialization of a polymorphic value object
    1531                                         // to allocate storage with alloca
     1537                                        // 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)
    15321539                                        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 ) );
    15351545
    15361546                                        delete objectDecl->get_init();
    15371547
    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 ) ) );
    15401549                                }
    15411550                        }
Note: See TracChangeset for help on using the changeset viewer.