-
Notifications
You must be signed in to change notification settings - Fork 126
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
Certain operations lack consideration for data types #166
Comments
Due to the introduction of some recent pull requests, I fetched the latest changes, refactored the test code, and re-described this issue. (I will gradually improve the description about this issue in the future.) |
I'm currently testing snippet 2, but is the last printing statement supposed to be printing |
Sorry, it should test Due to personal reason, I will modify the code and description tomorrow. |
After testing snippet 3, I found that it's quite hard to handle data type conversion more conventionally, due to lack of data size information, but also because of peephole optimization, we'll need to also resize it in arithmetic operations instead of just in |
After fixing the typo and testing the code again, the result shows that the behavior of pointer dereferencing is correct. The code and the description have been updated. I think the main title of this issue should be |
[ Edit: 2025/01/21 19:15 ]
Recently, I used the following tricky code to test shecc:
When the code is compiled using GCC with no optimization, all outputs match the expected results:
However, if using shecc to compile the code, some outputs seem to be wrong:
By the code and the comment in
test.c
, it is obvious that the code is divided to 3 snippets. Next, I use these snippets to explain their behaviors and the bug what I found.snippet 1
After introducing the pull request (#171), every stack allocation increment had been ensured to be properly aligned. Due to stack alignment requirements, each single character variable occupies 4 bytes, despite a character's actual size being 1 byte.
Thus, the following results are correct.
bb - aa
,cc - bb
anddd - cc
are4
.aaa
points to the address ofa
, the result of the dereference throughaaa
is equaivalent to the value ofa
.snippet 2
(Previously, I made a typo so that I misunderstood pointer dereferencing also had an error. After fixing it, the result is correct.)
snippet 3 - (bug)
Because the variables (
a
~d
) are signed characters, their results should be overflowed after executing additions and subtractions.The correct results should be
a = -127
,b = -78
,c = -93
andd = -44
, but the results of the executable compiled by shecc produces error outputs.Conclusion
According to the result of the snippet 3, the current backends may lack consideration of the data type when generating load/store instructions.
For example, the Arm backend may generates a
ldr
instruction for loading a character (1 byte), regardless of the data type. But, For character variables, it must generateldrsb
instructions instead.Since these problems also occur in the RISC-V backend, both the Arm and RISC-V backends require improvements to generate data-type-specific instructions, such as
ldrsb
for signed characters.The text was updated successfully, but these errors were encountered: