Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 316076 - [fp] Codan doesn't pay attention to __attribute__((noreturn))
Summary: [fp] Codan doesn't pay attention to __attribute__((noreturn))
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-codan (show other bugs)
Version: 7.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 8.1.0   Edit
Assignee: Elena Laskavaia CLA
QA Contact: Elena Laskavaia CLA
URL:
Whiteboard:
Keywords:
: 350478 (view as bug list)
Depends on: 316230
Blocks: 346557
  Show dependency tree
 
Reported: 2010-06-07 21:19 EDT by Sergey Prigogin CLA
Modified: 2021-08-26 08:22 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Prigogin CLA 2010-06-07 21:19:03 EDT
The following code triggers a warning "No return, in function returning non-void", but gcc is happy with it.

void f() __attribute__((noreturn));

bool test() {
  f();
}
Comment 1 Elena Laskavaia CLA 2010-06-07 21:24:15 EDT
I did not know about this attribute. I have a concept. For example exit() hardcoded as "noreturn".
-> 7.0.1
Comment 2 Elena Laskavaia CLA 2010-06-07 21:49:39 EDT
how does it represented in AST btw?
Comment 3 Sergey Prigogin CLA 2010-06-08 01:15:18 EDT
(In reply to comment #2)
> how does it represented in AST btw?

Attributes, I'm afraid, are not preserved in the AST. This is something we'll have to change.
Comment 4 Marc-André Laperle CLA 2011-06-27 18:06:26 EDT
*** Bug 350478 has been marked as a duplicate of this bug. ***
Comment 5 Sergey Prigogin CLA 2012-04-12 22:49:39 EDT
Implementation of IFinction.isNoReturn method uploaded to Gerrit at https://git.eclipse.org/r/#/c/5578/.
Comment 6 Sergey Prigogin CLA 2012-04-13 15:18:14 EDT
IFinction.isNoReturn() method is now available.
Comment 7 Elena Laskavaia CLA 2012-04-16 21:59:37 EDT
fixed thanks for Sergey implementing annotations support
Comment 8 Andrew McKinlay CLA 2012-07-09 18:47:03 EDT
I'm still having problems with this. Simple examples work, but my actual production code doesn't and I can't seem to make a small example.

Putting __attribute__((noreturn)) on the function definition as well as the declaration stops the warning, but GCC doesn't allow this.
Comment 9 Sergey Prigogin CLA 2012-07-09 18:53:52 EDT
(In reply to comment #8)
> I'm still having problems with this. Simple examples work, but my actual
> production code doesn't and I can't seem to make a small example.

There is little chance to fix this bug unless you can provide an example that triggers the false warning. Another alternative is for you to debug the issue yourself to determine where the existing logic fails.
Comment 10 Andrew McKinlay CLA 2012-07-09 19:00:56 EDT
Fair enough. I tried and failed to isolate it (in the time I had).  Just thought you might want to know.

Should the attribute be accepted in a place where GCC does not allow it?
Comment 11 Sergey Prigogin CLA 2012-07-09 19:09:09 EDT
(In reply to comment #10)
> Should the attribute be accepted in a place where GCC does not allow it?

CDT parser is pretty lax when accepting __attribute__ in various places. The problem is that GCC doesn't provide a formal definition of the grammar for __attribute__.
Comment 12 Yoann Le Montagner CLA 2012-11-11 12:58:40 EST
I also encounter this bug, even in simple situations. For instance:

void do_throw() __attribute__((noreturn));

int fun(int x) { // <- Warning
  if(x==0) return 42;
  else do_throw();
}

This code raise the warning "No return, in function returnin non-void". However,
with a simplier 'fun' function, the warning disappear:

void do_throw() __attribute__((noreturn));

int fun(int x) { // <- No warning
  do_throw();
}

Finally, whatever the function 'fun' is, I obtain an exception if the definition of 'do_throw' is included:

void do_throw() __attribute__((noreturn));

void do_throw() {
  throw "Stop it";
}

int fun(int x) { // <- Warning
  do_throw();
}

And also:

void __attribute__((noreturn)) do_throw() {
  throw std::exception();
}

int fun(int x) { // <- Warning
  do_throw();
}
Comment 13 Yoann Le Montagner CLA 2012-11-11 13:04:16 EST
PS: I use CDT v8.1.1 and Juno.
Comment 14 CDT Genie CLA 2013-02-27 11:39:46 EST
*** cdt git genie on behalf of Alena Laskavaia ***

    Bug 316076 - fixed f.p. when using gcc annotation about no return

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=77a06573a9ac854ef0e75b021f39625a7a6dc3ff