@@ -238,17 +238,14 @@ void IRGeneratorForStatements::initializeStateVar(VariableDeclaration const& _va
238238
239239 _varDecl.value ()->accept (*this );
240240
241- Type const * rightIntermediateType = _varDecl.value ()->annotation ().type ->closestTemporaryType (_varDecl.type ());
242- solAssert (rightIntermediateType, " " );
243- IRVariable value = convert (*_varDecl.value (), *rightIntermediateType);
244241 writeToLValue (
245242 _varDecl.immutable () ?
246243 IRLValue{*_varDecl.annotation ().type , IRLValue::Immutable{&_varDecl}} :
247244 IRLValue{*_varDecl.annotation ().type , IRLValue::Storage{
248245 util::toCompactHexWithPrefix (m_context.storageLocationOfStateVariable (_varDecl).first ),
249246 m_context.storageLocationOfStateVariable (_varDecl).second
250247 }},
251- value
248+ *_varDecl. value ()
252249 );
253250 }
254251 catch (langutil::UnimplementedFeatureError const & _error)
@@ -407,55 +404,49 @@ bool IRGeneratorForStatements::visit(Assignment const& _assignment)
407404 assignmentOperator :
408405 TokenTraits::AssignmentToBinaryOp (assignmentOperator);
409406
410- Type const * rightIntermediateType =
411- TokenTraits::isShiftOp (binaryOperator) ?
412- type (_assignment.rightHandSide ()).mobileType () :
413- type (_assignment.rightHandSide ()).closestTemporaryType (
414- &type (_assignment.leftHandSide ())
415- );
416- solAssert (rightIntermediateType, " " );
417- IRVariable value = convert (_assignment.rightHandSide (), *rightIntermediateType);
407+ if (TokenTraits::isShiftOp (binaryOperator))
408+ solAssert (type (_assignment.rightHandSide ()).mobileType (), " " );
409+ IRVariable value =
410+ type (_assignment.leftHandSide ()).isValueType () ?
411+ convert (
412+ _assignment.rightHandSide (),
413+ TokenTraits::isShiftOp (binaryOperator) ? *type (_assignment.rightHandSide ()).mobileType () : type (_assignment)
414+ ) :
415+ _assignment.rightHandSide ();
416+
418417 _assignment.leftHandSide ().accept (*this );
418+
419419 solAssert (!!m_currentLValue, " LValue not retrieved." );
420420 setLocation (_assignment);
421421
422422 if (assignmentOperator != Token::Assign)
423423 {
424424 solAssert (type (_assignment.leftHandSide ()).isValueType (), " Compound operators only available for value types." );
425- solAssert (rightIntermediateType->isValueType (), " Compound operators only available for value types." );
426- IRVariable leftIntermediate = readFromLValue (*m_currentLValue);
427425 solAssert (binaryOperator != Token::Exp, " " );
428- if (TokenTraits::isShiftOp (binaryOperator))
429- {
430- solAssert (type (_assignment) == leftIntermediate.type (), " " );
431- solAssert (type (_assignment) == type (_assignment.leftHandSide ()), " " );
432- define (_assignment) << shiftOperation (binaryOperator, leftIntermediate, value) << " \n " ;
426+ solAssert (type (_assignment) == type (_assignment.leftHandSide ()), " " );
433427
434- writeToLValue (*m_currentLValue, IRVariable (_assignment));
435- m_currentLValue.reset ();
436- return false ;
437- }
438- else
439- {
440- solAssert (type (_assignment.leftHandSide ()) == *rightIntermediateType, " " );
441- m_code << value.name () << " := " << binaryOperation (
442- binaryOperator,
443- *rightIntermediateType,
444- leftIntermediate.name (),
445- value.name ()
446- );
447- }
448- }
428+ IRVariable leftIntermediate = readFromLValue (*m_currentLValue);
429+ solAssert (type (_assignment) == leftIntermediate.type (), " " );
449430
450- writeToLValue (*m_currentLValue, value);
431+ define (_assignment) << (
432+ TokenTraits::isShiftOp (binaryOperator) ?
433+ shiftOperation (binaryOperator, leftIntermediate, value) :
434+ binaryOperation (binaryOperator, type (_assignment), leftIntermediate.name (), value.name ())
435+ ) << " \n " ;
451436
452- if (dynamic_cast <ReferenceType const *>(&m_currentLValue->type ))
453- define (_assignment, readFromLValue (*m_currentLValue));
454- else if (*_assignment.annotation ().type != *TypeProvider::emptyTuple ())
455- define (_assignment, value);
437+ writeToLValue (*m_currentLValue, IRVariable (_assignment));
438+ }
439+ else
440+ {
441+ writeToLValue (*m_currentLValue, value);
456442
457- m_currentLValue.reset ();
443+ if (dynamic_cast <ReferenceType const *>(&m_currentLValue->type ))
444+ define (_assignment, readFromLValue (*m_currentLValue));
445+ else if (*_assignment.annotation ().type != *TypeProvider::emptyTuple ())
446+ define (_assignment, value);
447+ }
458448
449+ m_currentLValue.reset ();
459450 return false ;
460451}
461452
@@ -2857,10 +2848,17 @@ void IRGeneratorForStatements::writeToLValue(IRLValue const& _lvalue, IRVariable
28572848 prepared.commaSeparatedList () <<
28582849 " )\n " ;
28592850 }
2851+ else if (auto const * literalType = dynamic_cast <StringLiteralType const *>(&_value.type ()))
2852+ m_code <<
2853+ m_utils.writeToMemoryFunction (*TypeProvider::uint256 ()) <<
2854+ " (" <<
2855+ _memory.address <<
2856+ " , " <<
2857+ m_utils.copyLiteralToMemoryFunction (literalType->value ()) + " ()" <<
2858+ " )\n " ;
28602859 else
28612860 {
28622861 solAssert (_lvalue.type .sizeOnStack () == 1 , " " );
2863- solAssert (dynamic_cast <ReferenceType const *>(&_lvalue.type ), " " );
28642862 auto const * valueReferenceType = dynamic_cast <ReferenceType const *>(&_value.type ());
28652863 solAssert (valueReferenceType && valueReferenceType->dataStoredIn (DataLocation::Memory), " " );
28662864 m_code << " mstore(" + _memory.address + " , " + _value.part (" mpos" ).name () + " )\n " ;
0 commit comments