Skip to content

Add human readable error message for invalid main signatures #5416

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

Conversation

hannes-steffenhagen-diffblue
Copy link
Contributor

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue commented Jul 9, 2020

Currently we have special handling if the entry point for analysis is called
main, in particular we assume it is one of the following:

int main(void)
int main(int argc, char *argv[])
int main(int argc, char *argv[], char *envp[])

If it is not so far we have been failing with an UNREACHABLE invariant failure.
Since it is completely possible to have a main signature like that, we should
fail with a proper human readable error message that tells people what is wrong
and maybe how they can work around it.

For now, addresses #5415. As I say in that ticket maybe we want to handle non-standard main signatures in a more graceful way, but until we decide on that having a better error message should take away some of the pain.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Currently we have special handling if the entry point for analysis is called
`main`, in particular we assume it is one of the following:

    int main(void)
    int main(int argc, char *argv[])
    int main(int argc, char *argv[], char *envp[])

If it is not so far we have been failing with an UNREACHABLE invariant failure.
Since it is completely possible to have a main signature like that, we should
fail with a proper human readable error message that tells people what is wrong
and maybe how they can work around it.
Copy link
Contributor

@NlightNFotis NlightNFotis left a comment

Choose a reason for hiding this comment

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

Okay

@NlightNFotis
Copy link
Contributor

Is there a long term plan for better handling of the situation? Or is it how we're going to work with this?

@hannes-steffenhagen-diffblue
Copy link
Contributor Author

@NlightNFotis Like I said, I am not sure what the ‘better’ version looks like.

@codecov
Copy link

codecov bot commented Jul 9, 2020

Codecov Report

Merging #5416 into develop will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #5416   +/-   ##
========================================
  Coverage    68.20%   68.21%           
========================================
  Files         1176     1176           
  Lines        97521    97524    +3     
========================================
+ Hits         66518    66522    +4     
+ Misses       31003    31002    -1     
Flag Coverage Δ
#cproversmt2 42.75% <100.00%> (+<0.01%) ⬆️
#regression 65.37% <100.00%> (+<0.01%) ⬆️
#unit 32.24% <0.00%> (-0.01%) ⬇️
Impacted Files Coverage Δ
src/ansi-c/ansi_c_entry_point.cpp 89.72% <100.00%> (+0.91%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 695a360...3b9b155. Read the comment docs.

" int main(int argc, char *argv[])\n"
" int main(int argc, char *argv[], char *envp[])\n"
"If this is a non-standard main entry point please provide a custom\n"
"entry function and point to it via cbmc --function instead"};
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great error message 💚
❔ If I do cbmc main.c --function main does this work? No worries if not, but if it does, I'd be half tempted to give that as the advice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn’t unfortunately. What does work is adding something like

void harness(void) {
  main(NULL);
}

and pointing at that.

const namespacet ns{symbol_table};
const std::string main_signature = type2c(symbol.type, ns);
throw invalid_source_file_exceptiont{
"'main' with signature '" + main_signature +
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it explicitly say "with an invalid signature" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I feel like ‘invalid’ is a matter of opinion. Maybe this is coming from code that does have a non-standard entry point. It is certainly not what we expect though, so saying that much is value neutral.

" int main(void)\n"
" int main(int argc, char *argv[])\n"
" int main(int argc, char *argv[], char *envp[])\n"
"If this is a non-standard main entry point please provide a custom\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the extra user help in the message :-)

Copy link
Contributor

@thomasspriggs thomasspriggs left a comment

Choose a reason for hiding this comment

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

👍

@NlightNFotis NlightNFotis merged commit 354b2c1 into diffblue:develop Jul 9, 2020
@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue deleted the fix/human-readable-error-on-wrong-main-signature branch July 9, 2020 13:49
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.

5 participants