Skip to content
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

fix(trigger): extern label should not be inside switch case block. #638

Merged
merged 3 commits into from
Nov 6, 2024

Conversation

ha0lyu
Copy link
Contributor

@ha0lyu ha0lyu commented Nov 6, 2024

extern Decode *prev_s; inside a switch case block, which is not allowed because it is a declaration and not an executable statement.

`extern Decode *prev_s;` inside a switch case block, which is not allowed because it is a declaration and not an executable statement.
@ha0lyu
Copy link
Contributor Author

ha0lyu commented Nov 6, 2024

When I make riscv64-xs-ref_defconfig, error occurred:

+ CC src/isa/riscv64/instr/rvv/vcompute_impl.c
+ CC src/isa/riscv64/instr/rvv/vreg_impl.c
src/isa/riscv64/system/trigger.c: In function ‘trigger_handler’:
src/isa/riscv64/system/trigger.c:328:11: error: a label can only be part of a statement and a declaration is not a statement
  328 |           extern Decode *prev_s;
      |           ^~~~~~
make: *** [/home/xs-env/NEMU/scripts/build.mk:62: /home/xs-env/NEMU/build/obj-riscv64-nemu-interpreter-so/src/isa/riscv64/system/trigger.o] Error 1
make: *** Waiting for unfinished jobs....

cc = gcc version 9.5.0 (Ubuntu 9.5.0-1ubuntu1~22.04)
commit id: fce68dc

@NewPaulWalker
Copy link
Contributor

In our work environment, the GCC version is 11.4.0, and this version allows a declaration to follow a label, which is not allowed in GCC 9.5.0.
Although this PR is okay, I suggest that you update and use GCC 11.4.0.
Additionally, there is another feasible fix for GCC 9.5.0, that is enclose the declaration immediately following the case label with {}.

case TRIG_TYPE_ICOUNT:
{
  extern Decode *prev_s;
  prev_s->pc = cpu.pc;
}

@ha0lyu
Copy link
Contributor Author

ha0lyu commented Nov 6, 2024

Thanks for your suggestion, bug the code should be robust and not rely solely on a high-version GCC compiler.

case TRIG_TYPE_ICOUNT:
{
  extern Decode *prev_s;
  prev_s->pc = cpu.pc;
}

Yes, this is elegant.

@NewPaulWalker NewPaulWalker changed the title fix(trigger): extern label should not be inside swich case block. fix(trigger): extern label should not be inside switch case block. Nov 6, 2024
@NewPaulWalker NewPaulWalker merged commit 3e22e1f into OpenXiangShan:master Nov 6, 2024
7 checks passed
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.

2 participants