mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Detect var being assigned in inline assembly block
This commit is contained in:
		
							parent
							
								
									2528ff31ee
								
							
						
					
					
						commit
						0cb4bd9308
					
				| @ -24,6 +24,8 @@ | ||||
| #include <liblangutil/SemVerHandler.h> | ||||
| #include <libsolutil/Algorithms.h> | ||||
| #include <libsolutil/FunctionSelector.h> | ||||
| #include <libyul/optimiser/ASTWalker.h> | ||||
| #include <libyul/AST.h> | ||||
| 
 | ||||
| #include <memory> | ||||
| 
 | ||||
| @ -432,6 +434,23 @@ struct ReservedErrorSelector: public PostTypeChecker::Checker | ||||
| 	} | ||||
| }; | ||||
| 
 | ||||
| class YulLValueChecker : public solidity::yul::ASTWalker | ||||
| { | ||||
| public: | ||||
| 	YulLValueChecker(ASTString const& _identifierName): m_identifierName(_identifierName) {} | ||||
| 	bool willBeWrittenTo() { return m_willBeWrittenTo; } | ||||
| 	using solidity::yul::ASTWalker::operator(); | ||||
| 	void operator()(solidity::yul::Assignment const& _assignment) override | ||||
| 	{ | ||||
| 		for (auto const& yulIdentifier: _assignment.variableNames) | ||||
| 			if (yulIdentifier.name.str() == m_identifierName) | ||||
| 				m_willBeWrittenTo = true; | ||||
| 	} | ||||
| private: | ||||
| 	ASTString const& m_identifierName; | ||||
| 	bool m_willBeWrittenTo = false; | ||||
| }; | ||||
| 
 | ||||
| class LValueChecker: public ASTConstVisitor | ||||
| { | ||||
| public: | ||||
| @ -448,6 +467,12 @@ public: | ||||
| 		) | ||||
| 			m_willBeWrittenTo = true; | ||||
| 	} | ||||
| 	void endVisit(InlineAssembly const& _inlineAssembly) override | ||||
| 	{ | ||||
| 		YulLValueChecker yulChecker{m_declaration->name()}; | ||||
| 		yulChecker(_inlineAssembly.operations()); | ||||
| 		m_willBeWrittenTo = yulChecker.willBeWrittenTo(); | ||||
| 	} | ||||
| private: | ||||
| 	Declaration const* m_declaration{}; | ||||
| 	bool m_willBeWrittenTo = false; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user