Skip to content

C front-end: reject code containing duplicate labels #6496

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 3 commits into from
Dec 2, 2021

Conversation

tautschnig
Copy link
Collaborator

We previously silently accepted such code, maintaining the labels and
attaching them to multiple instructions. goto resolved to the first
such occurrence of the label.

GCC firmly rejects such code.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a 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).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

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.

Solid, thanks for that!

if(!labels_defined.emplace(code.get_label(), code.source_location()).second)
{
error().source_location = code.source_location();
error() << "duplicate label '" << code.get_label() << "'" << eom;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Can this be substituted for a throw of an invalid_source_file_exceptiont from src/utils/exception_utils.h? That would be great!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm going to do that once #5835 and #5837 have been merged.

@kroening kroening assigned tautschnig and unassigned kroening Dec 2, 2021
An upcoming change will enforce per-function unique labels, as mandated
by the C standard. We were sometimes sloppy about this with
__CPROVER_ASYNC_* pseudo-labels as they don't actually indicate jump
targets.
We previously silently accepted such code, maintaining the labels and
attaching them to multiple instructions. `goto` resolved to the first
such occurrence of the label.

GCC firmly rejects such code.
@codecov
Copy link

codecov bot commented Dec 2, 2021

Codecov Report

Merging #6496 (00f71da) into develop (f245b3a) will increase coverage by 0.20%.
The diff coverage is 80.32%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6496      +/-   ##
===========================================
+ Coverage    76.06%   76.27%   +0.20%     
===========================================
  Files         1546     1546              
  Lines       165584   165624      +40     
===========================================
+ Hits        125951   126325     +374     
+ Misses       39633    39299     -334     
Impacted Files Coverage Δ
...java_bytecode/java_bytecode_internal_additions.cpp 100.00% <ø> (ø)
src/analyses/escape_analysis.cpp 63.83% <ø> (ø)
src/ansi-c/ansi_c_internal_additions.cpp 90.36% <ø> (ø)
src/ansi-c/c_typecheck_base.h 100.00% <ø> (ø)
src/crangler/ctokenit.cpp 0.00% <0.00%> (ø)
src/crangler/ctokenit.h 0.00% <0.00%> (ø)
src/goto-diff/goto_diff_parse_options.cpp 59.04% <ø> (+0.16%) ⬆️
src/goto-instrument/contracts/assigns.h 100.00% <ø> (ø)
src/goto-instrument/contracts/contracts.h 100.00% <ø> (ø)
src/goto-instrument/contracts/utils.h 100.00% <ø> (ø)
... and 131 more

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 d42839d...00f71da. Read the comment docs.

@tautschnig tautschnig merged commit 024d668 into diffblue:develop Dec 2, 2021
@tautschnig tautschnig deleted the duplicate-label branch December 2, 2021 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants