[analyzer] How to detect a block inside which SVal is used?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[analyzer] How to detect a block inside which SVal is used?

Keane, Erich via cfe-dev

 How to detect a block inside which SVal is used in a path-sensitive way?


E.g.

void foo(int x) // Here `x` has a Symbolic representation (e.g. reg_$0<int x>)
{
  // block 1  
  {  
    int y = x; // Here I want to know that `x` is used inside a simple block
  }

  // block 2  
  if(){  
    int y = x; ​ // Here I want to know that `x` is used inside if-true-block
  }

  // block 3  
  while(){  
    int y = x; // Here ​I want to know that `x` is used inside while-loop-body
  }
}

​I'm fighting with this sereval days. Insensitive way (checkASTCodeBody) is quite poor and not the case.

Thanks.



Denys Petrov
Senior С++ Developer | Kharkiv, Ukraine


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [analyzer] How to detect a block inside which SVal is used?

Keane, Erich via cfe-dev
There was a plan to handle this stuff with LocationContexts but it's currently stuck (https://reviews.llvm.org/D19979). I.e., when we enter a scope, we can put another LocationContext on the stack that'll indicate that we're in that scope, and when we exit the scope we remove it.

You can still figure this out syntactically by exploring parent statements of the current statement via ParentMap. This should work fairly well.

Given that nobody needed this particular functionality so far: what are you trying to achieve? 'Cause your high-level goal sounds extraordinary enough to discuss *before* discussing implementation details.


On 20.07.2020 08:28, Denis Petrov via cfe-dev wrote:

 How to detect a block inside which SVal is used in a path-sensitive way?


E.g.

void foo(int x) // Here `x` has a Symbolic representation (e.g. reg_$0<int x>)
{
  // block 1  
  {  
    int y = x; // Here I want to know that `x` is used inside a simple block
  }

  // block 2  
  if(){  
    int y = x; ​ // Here I want to know that `x` is used inside if-true-block
  }

  // block 3  
  while(){  
    int y = x; // Here ​I want to know that `x` is used inside while-loop-body
  }
}

​I'm fighting with this sereval days. Insensitive way (checkASTCodeBody) is quite poor and not the case.

Thanks.



Denys Petrov
Senior С++ Developer | Kharkiv, Ukraine


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [analyzer] How to detect a block inside which SVal is used?

Keane, Erich via cfe-dev

>Cause your high-level goal sounds extraordinary enough to discuss *before* discussing implementation details.


I'm developing this idea of a checker:

Consider this:

std::mutex m;
void foo()
{
  m.lock(); // catch the context
  for(int i = 0; i < 99999999; ++i) //long loop
  {
    // I'm trying to detect that `m` is not used inside long/inf loop
    // in other words all the rest threads may be potentially locked/idle for a long/inf time.
    // For this I have to determine whether `m` is inside the loop body block.
  }  
  m.unlock();
}



Denys Petrov
Senior С++ Developer | Kharkiv, Ukraine


От: Artem Dergachev <[hidden email]>
Отправлено: 20 июля 2020 г. 20:41
Кому: Denis Petrov; cfe-dev
Тема: Re: [cfe-dev] [analyzer] How to detect a block inside which SVal is used?
 

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.  If you suspect potential phishing or spam email, report it to [hidden email]

There was a plan to handle this stuff with LocationContexts but it's currently stuck (https://reviews.llvm.org/D19979). I.e., when we enter a scope, we can put another LocationContext on the stack that'll indicate that we're in that scope, and when we exit the scope we remove it.

You can still figure this out syntactically by exploring parent statements of the current statement via ParentMap. This should work fairly well.

Given that nobody needed this particular functionality so far: what are you trying to achieve? 'Cause your high-level goal sounds extraordinary enough to discuss *before* discussing implementation details.


On 20.07.2020 08:28, Denis Petrov via cfe-dev wrote:

 How to detect a block inside which SVal is used in a path-sensitive way?


E.g.

void foo(int x) // Here `x` has a Symbolic representation (e.g. reg_$0<int x>)
{
  // block 1  
  {  
    int y = x; // Here I want to know that `x` is used inside a simple block
  }

  // block 2  
  if(){  
    int y = x; ​ // Here I want to know that `x` is used inside if-true-block
  }

  // block 3  
  while(){  
    int y = x; // Here ​I want to know that `x` is used inside while-loop-body
  }
}

​I'm fighting with this sereval days. Insensitive way (checkASTCodeBody) is quite poor and not the case.

Thanks.



Denys Petrov
Senior С++ Developer | Kharkiv, Ukraine


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev