Changeset 5527759
- Timestamp:
- Apr 27, 2018, 2:35:11 PM (5 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, 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, with_gc
- Children:
- 399a908, a0c7d5cc
- Parents:
- b9f383f (diff), 9d5fb67 (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. - Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Lvalue.cc
rb9f383f r5527759 211 211 ) 212 212 // TODO: it's likely that the second condition should be ... && ! isIntrinsicReference( arg ), but this requires investigation. 213 213 214 if ( function->get_linkage() != LinkageSpec::Intrinsic && isIntrinsicReference( arg ) ) { 215 // needed for definition of prelude functions, etc. 214 216 // if argument is dereference or array subscript, the result isn't REALLY a reference, but non-intrinsic functions expect a reference: take address 215 217 … … 225 227 ) 226 228 arg = new AddressExpr( arg ); 229 // } else if ( function->get_linkage() == LinkageSpec::Intrinsic && InitTweak::getPointerBase( arg->result ) ) { 227 230 } else if ( function->get_linkage() == LinkageSpec::Intrinsic && arg->result->referenceDepth() != 0 ) { 228 231 // argument is a 'real' reference, but function expects a C lvalue: add a dereference to the reference-typed argument … … 234 237 PointerType * ptrType = new PointerType( Type::Qualifiers(), baseType->clone() ); 235 238 delete arg->result; 236 arg-> set_result( ptrType );239 arg->result = ptrType; 237 240 arg = mkDeref( arg ); 238 assertf( arg->result->referenceDepth() == 0, "Reference types should have been eliminated from intrinsic function calls, but weren't: %s", toCString( arg->result ) );241 // assertf( arg->result->referenceDepth() == 0, "Reference types should have been eliminated from intrinsic function calls, but weren't: %s", toCString( arg->result ) ); 239 242 } 240 243 } … … 298 301 } 299 302 300 if ( addCast ) { 301 PRINT( std::cerr << "adding cast..." << std::endl; ) 303 // if addrExpr depth is 0, then the result is a pointer because the arg was depth 1 and not lvalue. 304 // This means the dereference result is not a reference, is lvalue, and one less pointer depth than 305 // the addrExpr. Thus the cast is meaningless. 306 // TODO: One thing to double check is whether it is possible for the types to differ outside of the single 307 // pointer level (i.e. can the base type of addrExpr differ from the type of addrExpr-arg?). 308 // If so then the cast might need to be added, conditional on a more sophisticated check. 309 if ( addCast && addrExpr->result->referenceDepth() != 0 ) { 310 PRINT( std::cerr << "adding cast to " << addrExpr->result << std::endl; ) 302 311 return new CastExpr( ret, addrExpr->result->clone() ); 303 312 } … … 413 422 for ( int i = 0; i < diff; ++i ) { 414 423 ret = mkDeref( ret ); 424 // xxx - try removing one reference here? actually, looks like mkDeref already does this, so more closely look at the types generated. 415 425 } 416 426 if ( ! ResolvExpr::typesCompatibleIgnoreQualifiers( destType->stripReferences(), srcType->stripReferences(), SymTab::Indexer() ) ) { -
src/InitTweak/InitTweak.cc
rb9f383f r5527759 528 528 } 529 529 if ( dynamic_cast< ReferenceType * >( dst->result ) ) { 530 dst = new AddressExpr( dst ); 530 for (int depth = dst->result->referenceDepth(); depth > 0; depth--) { 531 dst = new AddressExpr( dst ); 532 } 531 533 } else { 532 534 dst = new CastExpr( dst, new ReferenceType( noQualifiers, dst->result->clone() ) ); 533 535 } 534 536 if ( dynamic_cast< ReferenceType * >( src->result ) ) { 535 src = new CastExpr( src, new ReferenceType( noQualifiers, src->result->stripReferences()->clone() ) ); 537 for (int depth = src->result->referenceDepth(); depth > 0; depth--) { 538 src = new AddressExpr( src ); 539 } 540 // src = new CastExpr( src, new ReferenceType( noQualifiers, src->result->stripReferences()->clone() ) ); 536 541 } 537 542 return new ApplicationExpr( VariableExpr::functionPointer( assign ), { dst, src } ); -
src/ResolvExpr/CommonType.cc
rb9f383f r5527759 101 101 int diff = depth1-depth2; 102 102 // TODO: should it be possible for commonType to generate complicated conversions? I would argue no, only conversions that involve types of the same reference level or a difference of 1 should be allowed. 103 if ( diff > 1 || diff < -1 ) return nullptr;103 // if ( diff > 1 || diff < -1 ) return nullptr; 104 104 105 105 // special case where one type has a reference depth of 1 larger than the other -
src/tests/references.c
rb9f383f r5527759 75 75 printf("%d %d\n", r1, x); 76 76 77 ((int&)r3) = 6;// change x, ***r377 r3 = 6; // change x, ***r3 78 78 printf("x = %d ; x2 = %d\n", x, x2); // check that x was changed 79 ((int*&)&r3) = &x2;// change r1 to refer to x2, (&*)**r380 ((int&)r3) = 999;// modify x279 &r3 = &x2; // change r1 to refer to x2, (&*)**r3 80 r3 = 999; // modify x2 81 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 x82 ((int**&)&&r3) = p2; // change r2, (&(&*)*)*r3, ensure explicit cast to reference works 83 r3 = 12345; // modify x 84 84 printf("x = %d ; x2 = %d\n", x, x2); // check that x was changed 85 ((int***&)&&&r3) = p3;// change r3 to p3, (&(&(&*)*)*)r386 ((int&)r3) = 22222; // modify x 85 &&&r3 = p3; // change r3 to p3, (&(&(&*)*)*)r3 86 ((int&)r3) = 22222; // modify x, ensure explicit cast to reference works 87 87 printf("x = %d ; x2 = %d\n", x, x2); // check that x was changed 88 88
Note: See TracChangeset
for help on using the changeset viewer.