Ignore:
Timestamp:
Feb 25, 2016, 4:46:11 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
ac1ed49
Parents:
3be261a
Message:

changed unification constraints on array types to more closely match C11 standard

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    r3be261a r41a2620  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Unify.cc -- 
     7// Unify.cc --
    88//
    99// Author           : Richard C. Bilson
     
    3838                WidenMode operator&( const WidenMode &other ) { WidenMode newWM( *this ); newWM &= other; return newWM; }
    3939                operator bool() { return widenFirst && widenSecond; }
    40  
     40
    4141                bool widenFirst : 1, widenSecond : 1;
    4242        };
     
    4545          public:
    4646                Unify( Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer );
    47  
     47
    4848                bool get_result() const { return result; }
    4949          private:
     
    7878        bool unifyInexact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer, Type *&common );
    7979        bool unifyExact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer );
    80  
     80
    8181        bool typesCompatible( Type *first, Type *second, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
    8282                TypeEnvironment newEnv;
     
    136136                  case TypeDecl::Dtype:
    137137                        return ! isFtype( type, indexer );
    138  
     138
    139139                  case TypeDecl::Ftype:
    140140                        return isFtype( type, indexer );
     
    195195                bool widen1 = false, widen2 = false;
    196196                Type *type1 = 0, *type2 = 0;
    197  
     197
    198198                if ( env.lookup( var1->get_name(), class1 ) ) {
    199199                        hasClass1 = true;
     
    216216                        widen2 = widenMode.widenSecond && class2.allowWidening;
    217217                } // if
    218  
     218
    219219                if ( type1 && type2 ) {
    220220//    std::cout << "has type1 && type2" << std::endl;
     
    435435                // to unify, array types must both be VLA or both not VLA
    436436                // and must both have a dimension expression or not have a dimension
    437                 if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen()
    438                                 && ((arrayType->get_dimension() != 0 && otherArray->get_dimension() != 0)
    439                                         || (arrayType->get_dimension() == 0 && otherArray->get_dimension() == 0))) {
     437                if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen() ) {
    440438
    441439                        // not positive this is correct in all cases, but it's needed for typedefs
     
    448446                                ConstantExpr * ce1 = dynamic_cast< ConstantExpr * >( arrayType->get_dimension() );
    449447                                ConstantExpr * ce2 = dynamic_cast< ConstantExpr * >( otherArray->get_dimension() );
    450                                 assert(ce1 && ce2);
    451 
    452                                 Constant * c1 = ce1->get_constant();
    453                                 Constant * c2 = ce2->get_constant();
    454 
    455                                 if ( c1->get_value() != c2->get_value() ) {
    456                                         // does not unify if the dimension is different
    457                                         return;
     448                                // see C11 Reference Manual 6.7.6.2.6
     449                                // two array types with size specifiers that are integer constant expressions are
     450                                // compatible if both size specifiers have the same constant value
     451                                if ( ce1 && ce2 ) {
     452                                        Constant * c1 = ce1->get_constant();
     453                                        Constant * c2 = ce2->get_constant();
     454
     455                                        if ( c1->get_value() != c2->get_value() ) {
     456                                                // does not unify if the dimension is different
     457                                                return;
     458                                        }
    458459                                }
    459460                        }
     
    484485
    485486                        if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
    486        
     487
    487488                                if ( unifyDeclList( functionType->get_returnVals().begin(), functionType->get_returnVals().end(), otherFunction->get_returnVals().begin(), otherFunction->get_returnVals().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
    488489
Note: See TracChangeset for help on using the changeset viewer.