Changes in / [b5563e1:af1ed1ad]


Ignore:
Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Common/Debug.h

    rb5563e1 raf1ed1ad  
    2828namespace Debug {
    2929        /// debug codegen a translation unit
    30         static inline void codeGen( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, __attribute__((unused)) LinkageSpec::Spec linkageFilter = LinkageSpec::Compiler ) {
     30        static inline void codeGen( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, LinkageSpec::Spec linkageFilter = LinkageSpec::Compiler ) {
    3131        #ifdef DEBUG
    3232                std::list< Declaration * > decls;
     
    4141        } // dump
    4242
    43         static inline void treeDump( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, __attribute__((unused)) LinkageSpec::Spec linkageFilter = LinkageSpec::Compiler ) {
     43        static inline void treeDump( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, LinkageSpec::Spec linkageFilter = LinkageSpec::Compiler ) {
    4444        #ifdef DEBUG
    4545                std::list< Declaration * > decls;
  • src/GenPoly/Lvalue.cc

    rb5563e1 raf1ed1ad  
    4545                Expression * mkDeref( Expression * arg ) {
    4646                        if ( SymTab::dereferenceOperator ) {
    47                                 // note: reference depth can be arbitrarily deep here, so peel off the outermost pointer/reference, not just pointer because they are effecitvely equivalent in this pass
    4847                                VariableExpr * deref = new VariableExpr( SymTab::dereferenceOperator );
    4948                                deref->result = new PointerType( Type::Qualifiers(), deref->result );
     
    198197                                        PRINT(
    199198                                                std::cerr << "pair<0>: " << arg << std::endl;
    200                                                 std::cerr << " -- " << arg->result << std::endl;
    201199                                                std::cerr << "pair<1>: " << formal << std::endl;
    202200                                        )
    203201                                        if ( dynamic_cast<ReferenceType*>( formal ) ) {
    204                                                 PRINT(
    205                                                         std::cerr << "===formal is reference" << std::endl;
    206                                                 )
    207                                                 // TODO: it's likely that the second condition should be ... && ! isIntrinsicReference( arg ), but this requires investigation.
    208                                                 if ( function->get_linkage() != LinkageSpec::Intrinsic && isIntrinsicReference( arg ) ) {
    209                                                         // if argument is dereference or array subscript, the result isn't REALLY a reference, but non-intrinsic functions expect a reference: take address
    210                                                         PRINT(
    211                                                                 std::cerr << "===is intrinsic arg in non-intrinsic call - adding address" << std::endl;
    212                                                         )
    213                                                         arg = new AddressExpr( arg );
    214                                                 } else if ( function->get_linkage() == LinkageSpec::Intrinsic && arg->result->referenceDepth() != 0 ) {
    215                                                         // argument is a 'real' reference, but function expects a C lvalue: add a dereference to the reference-typed argument
    216                                                         PRINT(
    217                                                                 std::cerr << "===is non-intrinsic arg in intrinsic call - adding deref to arg" << std::endl;
    218                                                         )
     202                                                if ( isIntrinsicReference( arg ) ) { // do not combine conditions, because that changes the meaning of the else if
     203                                                        if ( function->get_linkage() != LinkageSpec::Intrinsic ) { // intrinsic functions that turn pointers into references
     204                                                                // if argument is dereference or array subscript, the result isn't REALLY a reference, so it's not necessary to fix the argument
     205                                                                PRINT(
     206                                                                        std::cerr << "===is intrinsic arg in non-intrinsic call - adding address" << std::endl;
     207                                                                )
     208                                                                arg = new AddressExpr( arg );
     209                                                        }
     210                                                } else if ( function->get_linkage() == LinkageSpec::Intrinsic ) {
     211                                                        // std::cerr << "===adding deref to arg" << std::endl;
     212                                                        // if the parameter is a reference, add a dereference to the reference-typed argument.
    219213                                                        Type * baseType = InitTweak::getPointerBase( arg->result );
    220214                                                        assertf( baseType, "parameter is reference, arg must be pointer or reference: %s", toString( arg->result ).c_str() );
     
    223217                                                        arg->set_result( ptrType );
    224218                                                        arg = mkDeref( arg );
    225                                                         assertf( arg->result->referenceDepth() == 0, "Reference types should have been eliminated from intrinsic function calls, but weren't: %s", toCString( arg->result ) );
    226219                                                }
    227220                                        }
  • src/tests/.expect/references.txt

    rb5563e1 raf1ed1ad  
    4413 1 12
    5514 14
    6 x = 6 ; x2 = 789
    7 x = 6 ; x2 = 999
    8 x = 12345 ; x2 = 999
    9 x = 22222 ; x2 = 999
    106Default constructing a Y
    117Copy constructing a Y
  • src/tests/references.c

    rb5563e1 raf1ed1ad  
    4646
    4747int main() {
    48         int x = 123456, x2 = 789, *p1 = &x, **p2 = &p1, ***p3 = &p2,
     48        int x = 123456, *p1 = &x, **p2 = &p1, ***p3 = &p2,
    4949                &r1 = x,    &&r2 = r1,   &&&r3 = r2;
    5050        ***p3 = 3;                          // change x
     51        // ((int&)r3 = 3;                      // change x, ***r3
    5152        **p3 = &x;                          // change p1
     53        // ((int*&)&r3) = &x;                  // change r1, (&*)**r3
    5254        *p3 = &p1;                          // change p2
     55        // ((int**&)&&r3) = &p2;               // change r2, (&(&*)*)*r3
     56        // ((int***&)&&&r3) = p3;              // change r3 to p3, (&(&(&*)*)*)r3
    5357        int y = 0, z = 11, & ar[3] = { x, y, z };    // initialize array of references
    5458        // &ar[1] = &z;                        // change reference array element
     
    5862        // sizeof( &ar[1] ) == sizeof( int *); // is true, i.e., the size of a reference
    5963
    60         ((int*&)&r3) = &x;                  // change r1, (&*)**r3
    61         x = 3;
    6264        // test that basic reference properties are true - r1 should be an alias for x
    6365        printf("%d %d %d\n", x, r1, &x == &r1);
     
    7476        changeRef( r1 );
    7577        printf("%d %d\n", r1, x);
    76 
    77         ((int&)r3) = 6;                       // change x, ***r3
    78         printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
    79         ((int*&)&r3) = &x2;                   // change r1 to refer to x2, (&*)**r3
    80         ((int&)r3) = 999;                     // modify x2
    81         printf("x = %d ; x2 = %d\n", x, x2);  // check that x2 was changed
    82         ((int**&)&&r3) = p2;                  // change r2, (&(&*)*)*r3
    83         ((int&)r3) = 12345;                   // modify x
    84         printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
    85         ((int***&)&&&r3) = p3;                // change r3 to p3, (&(&(&*)*)*)r3
    86         ((int&)r3) = 22222;                   // modify x
    87         printf("x = %d ; x2 = %d\n", x, x2);  // check that x was changed
    8878
    8979        // test that reference members are not implicitly constructed/destructed/assigned
Note: See TracChangeset for help on using the changeset viewer.