driver: an unknown --opt= goal should name the valid goals

Open Beginner friendly
#190 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
83/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
cli

Research direction

Read the --pass=/--no-pass= handling near line 8580 in src/driver/main.c and the --opt= entries in src/driver/options.def (lines 114–121). Add coverage in tests/golden/options-table.sh or tests/golden/gcc-flags.sh, checking that an invalid goal lists valid goals and omits usage text. Done when the message is generated from the option table and the tests pass.

Written by the indexing model from the issue text.

Description

enhancement good first issue

Context. --opt= takes a goal (none, basic, debug, speed, max, size, min-size). A wrong one gets a generic error and the whole usage text:

$ ./embcc --opt=sped -c t.c
embcc: error: unknown argument '--opt=sped'
usage: embcc [-c|-S|-E] SOURCE... [-o FILE] ...

--pass= already does better: embcc: error: --pass=X: no optimizer pass has that name; the passes are a, b and c. --opt= should do the same, and suggest the closest goal.

Where.

  • src/driver/main.c, around line 8580: the --pass= / --no-pass= branch, which is the pattern to follow. The generic unknown argument error comes right after it.
  • src/driver/options.def, lines 114–121: the --opt= goals are entries in the option table, so the list does not need typing in again.
  • Tests: tests/golden/options-table.sh and tests/golden/gcc-flags.sh already check option errors.

Steps.

  1. When opt_typed(argv[i]) starts with --opt= and matched no entry, print embcc: error: --opt=sped: not a goal; the goals are none, basic, debug, speed, max, size and min-size. Build the list from the option table.
  2. Optionally, add did you mean --opt=speed? when one goal is close.
  3. Add a test that checks the message, and that the usage text is no longer printed.

Done when an unknown --opt= names the valid goals, the list comes from options.def (adding a goal there updates the message), and the tests pass.

Before you start: the contributor's guide has the rules. A new test counts only after it has failed against the code before your change, and a commit subject reads area: summary. Questions are welcome in the comments or in Discussions.

Dominant language
C
Stars
1
Forks
2
Avg merge
20h 55m
Merged PRs (30d)
73

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from EmbLinkOs/EmbCC

All issues in EmbLinkOs/EmbCC

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.