-
Notifications
You must be signed in to change notification settings - Fork 18
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
[RISCV][Clang] Added code to generate clang error if immediate operan… #93
[RISCV][Clang] Added code to generate clang error if immediate operan… #93
Conversation
…d of the following builtins is out of range: - __builtin_riscv_cv_simd_extract_h - __builtin_riscv_cv_simd_extract_b - __builtin_riscv_cv_simd_extractu_h - __builtin_riscv_cv_simd_extractu_b - __builtin_riscv_cv_simd_insert_h - __builtin_riscv_cv_simd_insert_b
clang/lib/Sema/SemaChecking.cpp
Outdated
case RISCVCOREV::BI__builtin_riscv_cv_simd_extract_b: | ||
case RISCVCOREV::BI__builtin_riscv_cv_simd_extractu_h: | ||
case RISCVCOREV::BI__builtin_riscv_cv_simd_extractu_b: | ||
return SemaBuiltinConstantArgRange(TheCall, 1, 0, 63); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use 63 as range limit. These instructions are supposed to be used with values [0,1,2,3] for *_b and [0,1] *_h to select the bytes or half words. I'd make that clear straight away in the front-end, otherwise we may need to truncate or crash or silently mis-select the byte/half word later. So I'd say:
for extract_h and extractu_h:
return SemaBuiltinConstantArgRange(TheCall, 1, 0, 1);
while for extract_b and extractu_b:
return SemaBuiltinConstantArgRange(TheCall, 1, 0, 3);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. I'll make the changes accordingly.
clang/lib/Sema/SemaChecking.cpp
Outdated
return SemaBuiltinConstantArgRange(TheCall, 1, 0, 63); | ||
case RISCVCOREV::BI__builtin_riscv_cv_simd_insert_h: | ||
case RISCVCOREV::BI__builtin_riscv_cv_simd_insert_b: | ||
return SemaBuiltinConstantArgRange(TheCall, 2, 0, 63); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same fix as above for the range
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed the ranges accordingly. I just noticed that I have run clang-format on the files. Is it fine or should I reverse it?
I've added a couple of comments but otherwise it looks good. Could you also check whether there are Sema tests for this kind of validations? We could do with a test for these |
I see there are not many Sema tests so probably the best way to test the errors is to add cases to |
ok sure. |
…ics: - __builtin_riscv_cv_simd_extract_h - __builtin_riscv_cv_simd_extract_b - __builtin_riscv_cv_simd_extractu_h - __builtin_riscv_cv_simd_extractu_b - __builtin_riscv_cv_simd_insert_h - __builtin_riscv_cv_simd_insert_b
Hi @paolo, |
Legit question. You'll need a separate test like |
On a separate note, I see that the diffs contain a lot of indentation changes. Has some formatting happened? Would it be possible to reload a patch with just your changes? |
Yeah, sure. I ran clang-format by mistake (force of habit). I'll revert it. |
This reverts commit 1c372bc.
…he following intrinsics: - __builtin_riscv_cv_simd_extract_h - __builtin_riscv_cv_simd_extract_b - __builtin_riscv_cv_simd_extractu_h - __builtin_riscv_cv_simd_extractu_b - __builtin_riscv_cv_simd_insert_h - __builtin_riscv_cv_simd_insert_b
I have added the tests. |
Hi @PaoloS02 , Also, I think I should adjust the value of the immediate operand for those __builtin_riscv_cv_simd_extract* tests in simd.c that are using positive immediate value but the value is out of valid range. |
Hi @adeel10x sorry for the delay. Yes to all the above. Since we have a separate test to cover the error cases so that we can see whether future changes break the check on the operand all we need in the simd.c test is normal use cases with appropriate operands to check that the selection of the intrinsics works. Thanks for this! |
The new tests look good! |
__builtin_riscv_cv_simd_extract_h __builtin_riscv_cv_simd_extract_b __builtin_riscv_cv_simd_extractu_h __builtin_riscv_cv_simd_extractu_b
…d of the following builtins is out of range: