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 declaration error when using clang #532

Merged
merged 1 commit into from
Dec 30, 2024

Conversation

ChinYikMing
Copy link
Collaborator

@ChinYikMing ChinYikMing commented Dec 29, 2024

When compile the rv32emu using clang, the error log shows the following:

src/emulate.c:1127:5: error: expected expression
    rv_insn_t ir;

According to [1], syntax of labeled-statement stated in the following:

labeled-statement:
identifier : statement
case constant-expression : statement
default : statement

Obviously, only the statement is valid after labeled-statement. When refering to [2], the following are the valid statements, excluding the declaration.

statement:
labeled-statement
compound-statement
expression-statement
selection-statement
iteration-statement
jump-statement

Thus, move the declaration of ir before the labeled-statement eliminates the clang compile error.

[1] C99 6.8.1 Labeled statements
[2] C99 6.8 Statement and blocks

When compile the rv32emu using clang, the error log shows the following:
src/emulate.c:1127:5: error: expected expression
    rv_insn_t ir;

According to [1], syntax of lebeled-statement stated in the following:

labeled-statement:
    identifier : statement
    case constant-expression : statement
    default : statement

Obviously, only the statement is valid after labeled-statement. When
refering to [2], the following are the valid statements, excluding the
declaration.

statement:
    labeled-statement
    compound-statement
    expression-statement
    selection-statement
    iteration-statement
    jump-statement

Thus, move the declaration of ir before the labeled-statement eliminates
the clang compile error.

[1] C99 6.8.1 Labeled statements
[2] C99 6.8 Statement and blocks
@ChinYikMing
Copy link
Collaborator Author

ChinYikMing commented Dec 29, 2024

During development, we might not consistently use multiple compilers (e.g., GCC and Clang) to build rv32emu for compatibility checks. The build checks can be automated in the CI pipeline. By default, GCC is used for behavioral verification, while Clang is reserved for build verification only. We can embrace Clang to our CI pipeline.

What do you think? @jserv

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Benchmarks

Benchmark suite Current: f560955 Previous: 8ee7304 Ratio
Dhrystone 1284 Average DMIPS over 10 runs 1346 Average DMIPS over 10 runs 1.05
Coremark 976.216 Average iterations/sec over 10 runs 961.255 Average iterations/sec over 10 runs 0.98

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Collaborator

@RinHizakura RinHizakura left a comment

Choose a reason for hiding this comment

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

LGTM

@visitorckw
Copy link
Collaborator

During development, we might not consistently use multiple compilers (e.g., GCC and Clang) to build rv32emu for compatibility checks. The build checks can be automated in the CI pipeline. By default, GCC is used for behavioral verification, while Clang is reserved for build verification only. We can embrace Clang to our CI pipeline.

Additionally, rv_clz() and rv_ctz() include MSVC implementations, but we don't have tests for them. Should we consider adding MSVC tests for these in CI?

@ChinYikMing
Copy link
Collaborator Author

During development, we might not consistently use multiple compilers (e.g., GCC and Clang) to build rv32emu for compatibility checks. The build checks can be automated in the CI pipeline. By default, GCC is used for behavioral verification, while Clang is reserved for build verification only. We can embrace Clang to our CI pipeline.

Additionally, rv_clz() and rv_ctz() include MSVC implementations, but we don't have tests for them. Should we consider adding MSVC tests for these in CI?

Seems applicable. BTW, did you try to build and run in Windows?

@visitorckw
Copy link
Collaborator

During development, we might not consistently use multiple compilers (e.g., GCC and Clang) to build rv32emu for compatibility checks. The build checks can be automated in the CI pipeline. By default, GCC is used for behavioral verification, while Clang is reserved for build verification only. We can embrace Clang to our CI pipeline.

Additionally, rv_clz() and rv_ctz() include MSVC implementations, but we don't have tests for them. Should we consider adding MSVC tests for these in CI?

Seems applicable. BTW, did you try to build and run in Windows?

I haven't tried it before, but I can give it a try! :)

@jserv jserv merged commit 060b0fb into sysprog21:master Dec 30, 2024
8 checks passed
@jserv
Copy link
Contributor

jserv commented Dec 30, 2024

Thank @ChinYikMing for contributing!

@ChinYikMing ChinYikMing deleted the fix-clang-build branch December 30, 2024 02:13
@jserv jserv added this to the release-2025.1 milestone Jan 19, 2025
vestata pushed a commit to vestata/rv32emu that referenced this pull request Jan 24, 2025
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