33use super :: { Foundry , FunctionCall , GenericVisitor , LocalFunction , Storage , Test , WithContents } ;
44use anyhow:: Result ;
55use necessist_core:: framework:: { SpanTestMaps , TestSet } ;
6- use solang_parser:: pt:: { Expression , FunctionDefinition , Identifier , Loc , SourceUnit , Statement } ;
6+ use solang_parser:: pt:: {
7+ Expression , FunctionAttribute , FunctionDefinition , Identifier , Loc , Mutability , SourceUnit ,
8+ Statement ,
9+ } ;
710use std:: { cell:: RefCell , collections:: BTreeMap , convert:: Infallible } ;
811
912mod visit;
@@ -43,7 +46,9 @@ impl<'ast> visit_fns::Visitor<'ast> for FunctionDefinitionCollector<'ast> {
4346 & mut self ,
4447 function_definition : & ' ast FunctionDefinition ,
4548 ) -> Result < ( ) , Self :: Error > {
46- if let Some ( name) = & function_definition. name {
49+ if let Some ( name) = & function_definition. name
50+ && !is_pure ( function_definition)
51+ {
4752 self . function_definitions
4853 . entry ( name. to_string ( ) )
4954 . or_default ( )
@@ -172,6 +177,7 @@ impl<'ast> visit_fns::Visitor<'ast> for Visitor<'_, '_, '_, 'ast, '_> {
172177fn is_test_function ( function_definition : & FunctionDefinition ) -> Option < Test < ' _ > > {
173178 if let Some ( Identifier { name, .. } ) = & function_definition. name
174179 && name. starts_with ( "test" )
180+ && !is_pure ( function_definition)
175181 && let Some ( Statement :: Block { statements, .. } ) = & function_definition. body
176182 {
177183 Some ( Test {
@@ -183,6 +189,17 @@ fn is_test_function(function_definition: &FunctionDefinition) -> Option<Test<'_>
183189 }
184190}
185191
192+ // smoelius: Skip `pure` functions. @smonicas noticed that instrumenting them is a bug because
193+ // `vm.envBytes` is a `view` function. See: https://github.com/trailofbits/necessist/issues/1728
194+ fn is_pure ( function_definition : & FunctionDefinition ) -> bool {
195+ function_definition. attributes . iter ( ) . any ( |attribute| {
196+ matches ! (
197+ attribute,
198+ FunctionAttribute :: Mutability ( Mutability :: Pure ( _) )
199+ )
200+ } )
201+ }
202+
186203fn filter_statements < ' ast , I : IntoIterator < Item = & ' ast Statement > > (
187204 statements : I ,
188205) -> impl Iterator < Item = & ' ast Statement > {
0 commit comments