Changeset ceedde6


Ignore:
Timestamp:
May 29, 2018, 4:15:33 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, with_gc
Children:
1134b80
Parents:
8638cef
Message:

Fixed checks for number of mutex paramters on destructors and constructors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cc

    r8638cef rceedde6  
    443443                bool first = false;
    444444                std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl, first );
    445                 if( mutexArgs.empty() ) return;
    446 
    447                 if( CodeGen::isConstructor(decl->name) && first ) SemanticError( decl, "constructors cannot have mutex parameters" );
    448 
    449445                bool isDtor = CodeGen::isDestructor( decl->name );
    450446
     447                // Is this function relevant to monitors
     448                if( mutexArgs.empty() ) {
     449                        // If this is the destructor for a monitor it must be mutex
     450                        if(isDtor) {
     451                                Type* ty = decl->get_functionType()->get_parameters().front()->get_type();
     452
     453                                // If it's a copy, it's not a mutex
     454                                ReferenceType* rty = dynamic_cast< ReferenceType * >( ty );
     455                                if( ! rty ) return;
     456
     457                                // If we are not pointing directly to a type, it's not a mutex
     458                                Type* base = rty->get_base();
     459                                if( dynamic_cast< ReferenceType * >( base ) ) return;
     460                                if( dynamic_cast< PointerType * >( base ) ) return;
     461
     462                                // Check if its a struct
     463                                StructInstType * baseStruct = dynamic_cast< StructInstType * >( base );
     464                                if( !baseStruct ) return;
     465
     466                                // Check if its a monitor
     467                                if(baseStruct->baseStruct->is_monitor() || baseStruct->baseStruct->is_thread())
     468                                        SemanticError( decl, "destructors for structures declared as \"monitor\" must use mutex parameters\n" );
     469                        }
     470                        return;
     471                }
     472
     473                // Monitors can't be constructed with mutual exclusion
     474                if( CodeGen::isConstructor(decl->name) && !first ) SemanticError( decl, "constructors cannot have mutex parameters" );
     475
     476                // It makes no sense to have multiple mutex parameters for the destructor
    451477                if( isDtor && mutexArgs.size() != 1 ) SemanticError( decl, "destructors can only have 1 mutex argument" );
    452478
     479                // Make sure all the mutex arguments are monitors
    453480                for(auto arg : mutexArgs) {
    454481                        validate( arg );
    455482                }
    456483
     484                // Check if we need to instrument the body
    457485                CompoundStmt* body = decl->get_statements();
    458486                if( ! body ) return;
    459487
     488                // Do we have the required headers
    460489                if( !monitor_decl || !guard_decl || !dtor_guard_decl )
    461                         SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>" );
    462 
     490                        SemanticError( decl, "mutex keyword requires monitors to be in scope, add #include <monitor>\n" );
     491
     492                // Instrument the body
    463493                if( isDtor ) {
    464494                        addDtorStatments( decl, body, mutexArgs );
Note: See TracChangeset for help on using the changeset viewer.