Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 327375

Summary: IControlFlowGraph fails to detect unconnected node (dead code node)
Product: [Tools] CDT Reporter: Felipe <felipe.m.figueroa>
Component: cdt-codanAssignee: CDT Codan Inbox <cdt-codan-inbox>
Status: RESOLVED FIXED QA Contact: Elena Laskavaia <elaskavaia.cdt>
Severity: normal    
Priority: P3 CC: cdtdoug, yevshif, zeratul976
Version: 7.0   
Target Milestone: 8.7.0   
Hardware: PC   
OS: Windows XP   
See Also: https://git.eclipse.org/r/42092
https://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=3cf5ec86eef49327bd52622b702ca65c6af68472
Whiteboard:
Attachments:
Description Flags
Checker implementation where we detected the described bug
none
CDT project where the bug happens none

Description Felipe CLA 2010-10-08 22:25:14 EDT
Build Identifier: I20100603-1500

Given the following C code the last statement is NOT reported as unconnected node after calling getUnconnectedNodeIterator()

void called_from_macro() {
	int variable = 0;

	if (variable) {
		return;
	} else {
		return;
	}
	variable += 10;
}

Reproducible: Always

Steps to Reproduce:
1.Create a CDT project with a C function like the one cited in the details section.
2.Create a CODAN checker in order to catch function definitions.
3.Create an IControlFlowGraph over the function definition and get the number of unconnected nodes.  getUnconnectedNodeSize()
4.-Set a break point where the problematic function is processed and verify zero unconnected nodes are reported by the IControlFlowGraph.
Comment 1 Felipe CLA 2010-10-08 22:29:43 EDT
Created attachment 180535 [details]
Checker implementation where we detected the described bug

Checker used to detect the bug.
Comment 2 Felipe CLA 2010-10-08 22:35:18 EDT
Created attachment 180536 [details]
CDT project where the bug happens

Sample CDT project to elaborate more on this bug.
Comment 3 Nathan Ridge CLA 2014-08-13 01:53:51 EDT
This problem can also manifest as a user-visible false-positive Codan warning, if you change the return type of the function to non-void (and change the return statements accordingly):

int called_from_macro() {  // WARNING HERE: No return, in function returning non-void
    int variable = 0;

    if (variable) {
        return 2;
    } else {
        return 3;
    }
    variable += 10;
}

GCC, which has a similar warning, does not warn for this code.
Comment 5 Elena Laskavaia CLA 2015-02-18 19:47:10 EST
fixed (I hope)