Bug 545877 - [fn] No return in function returning non-void
Summary: [fn] No return in function returning non-void
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-codan (show other bugs)
Version: 9.7.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: CDT Codan Inbox CLA
QA Contact: Elena Laskavaia CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-28 03:41 EDT by Marco Stornelli CLA
Modified: 2019-03-30 19:22 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Stornelli CLA 2019-03-28 03:41:00 EDT
There's no warning in this case:

int foo(int a) {
    int* ptr = 0;

    ptr = &a;

    if (ptr) {
        std::cout << "hello" << std::endl;
    } else {
        return 1;
    }
}

The problem is the evaluation of variable ptr via ValueFactory. The evaluation is performed only on initial value :

/**
 * Extract a value off a binding.
 */
private static IValue evaluateBinding(IBinding b) {
    .....
    if (b instanceof IVariable) {
          value = ((IVariable) b).getInitialValue();
    .....
Comment 1 Eclipse Genie CLA 2019-03-28 13:18:16 EDT
New Gerrit change created: https://git.eclipse.org/r/139694
Comment 2 Nathan Ridge CLA 2019-03-28 19:39:14 EDT
This is the same issue as bug 476388. The discussion in the patch there is probably useful background.
Comment 3 Marco Stornelli CLA 2019-03-29 02:20:34 EDT
You are right, this is a duplicate. I didn't understand the final patch of that bug. It seems the initial value is still taken into account z regardless the condition of empty condition statements, the patch 14 doesn't add anything. The basic problem is the lack of a proper data flow analysis, without tracking variable uses we will have always false negative/positive. It's just a matter to understand what's better at the moment. However my patch is lesser "invasive" than the other patch, with the exception of cfg other code is not affected.
Comment 4 Nathan Ridge CLA 2019-03-30 19:22:27 EDT
(In reply to Marco Stornelli from comment #3)
> The basic problem is the lack of a proper data flow analysis,
> without tracking variable uses we will have always false negative/positive.

Agreed.

> It's just a matter to understand what's better at the moment.

In the review of https://git.eclipse.org/r/#/c/54358/, Elena was of the opinion that, for purposes of building the control flow graph, we should always use the initial value of the variable, even if it's not const.

I am not sure whether she has changed her opinion since then. I cc'd her so she can chime in here.