Skip to content

Added a warning for when function returns a value but has return void #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2016

Conversation

thk123
Copy link
Contributor

@thk123 thk123 commented Nov 11, 2016

Also included a simple regression that should produce this warning

@thk123
Copy link
Contributor Author

thk123 commented Nov 11, 2016

@cristina-david I think I should assign this to you, but I can't work out how to change the assignee. I suppose it is a permissions thing?

For context, I thought I'd got stuck trying to get the interpreter to give me the return variable, but actually I was being silly and had the return type as void. When Chris spotted this after I asked for help, he suggested I added a warning to the C to GOTO compiler to catch this mistake.

@kroening kroening self-assigned this Nov 12, 2016
{
warning() << "Function " << code.source_location().get_function();
warning() << " has return void but a return statement returning ";
warning() << follow(code.op0().type()).id();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use to_string here, to print the usual ANSI-C syntax

warning() << "Function " << code.source_location().get_function();
warning() << " has return void but a return statement returning ";
warning() << follow(code.op0().type()).id();
warning() << " was found on line " << code.source_location().get_line();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use warning().set_source_location instead.

@@ -911,7 +911,15 @@ void c_typecheck_baset::typecheck_return(codet &code)
{
// gcc doesn't actually complain, it just warns!
if(follow(code.op0().type()).id()!=ID_empty)
{
warning().source_location = code.source_location();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit picking: don't put spaces around assignment operator

CORE
main.c
--verbosity 2
^file main.c line . function fun: Function has return void but a return statement returning signed int$
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to insist the warning checks specifically for line 3

{
warning().source_location = code.source_location();

warning() << "Function has return void but a return statement returning ";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We seem to be starting all warnings with a lowercase character (i.e., use "function")

Also, that line is rather long, consider breaking it earlier.

@tautschnig
Copy link
Collaborator

@thk123 Many thanks for carefully addressing all the feedback! It might be best to now squash all three commits into one.
@mgudemann I don't think your regression test actually relates to this issue?

@mgudemann
Copy link
Contributor

@tautschnig You are right, I mentioned an internal issue #301 in the commit message of another PR and github automagically referenced this here. This was definitely not intended.

@kroening
Copy link
Member

This seems ready to get merged once it's squashed.

Also included a simple regression that should produce this warning
Set the source location on the warning and use the ANSI C version of the type. Also updated regression to reflect new format.
@thk123 thk123 force-pushed the void-return-warning branch from c82abe1 to f28f7ac Compare November 18, 2016 09:52
@kroening kroening merged commit 3933e85 into diffblue:master Nov 19, 2016
@thk123 thk123 deleted the void-return-warning branch November 21, 2016 09:53
smowton pushed a commit to smowton/cbmc that referenced this pull request May 9, 2018
…-clang-format

Add symlink to .clang-format in cbmc folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants