Skip to content

[SYCL] Fix static_assert with -funsigned-char #17133

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

Merged
merged 1 commit into from
Mar 14, 2025

Conversation

hvdijk
Copy link
Contributor

@hvdijk hvdijk commented Feb 24, 2025

The type of (ext_vector<int8_t, 2>{1, 0} == 0)[1] has type char, not int8_t, and therefore depending on whether -funsigned-char is in effect may either have the value -1 or have the value 255. Cast to int8_t to ensure it always gets taken as signed. This is only needed for the static_assert: the rest of the code already works for signed and unsigned plain char alike.

@hvdijk hvdijk requested a review from a team as a code owner February 24, 2025 10:44
@hvdijk hvdijk changed the title Fix static_assert with -funsigned-char [SYCL] Fix static_assert with -funsigned-char Feb 24, 2025
@hvdijk
Copy link
Contributor Author

hvdijk commented Mar 3, 2025

ping, we are working on non-x86 target support, this is a blocker for AArch64 where -funsigned-char is the default, it would be nice if we could get this in.

@hvdijk
Copy link
Contributor Author

hvdijk commented Mar 11, 2025

ping again, it's been two weeks now, could someone review this please?

@hvdijk
Copy link
Contributor Author

hvdijk commented Mar 14, 2025

ping again @intel/llvm-reviewers-runtime

@uditagarwal97
Copy link
Contributor

ping again @intel/llvm-reviewers-runtime

Sorry about the delay. Could you also rebase your PR over the latest SYCL branch? The CI results are quite old, rebasing would re-trigger the CI.

The type of (ext_vector<int8_t, 2>{1, 0} == 0)[1] has type char, not
int8_t, and therefore depending on whether -funsigned-char is in effect
may either have the value -1 or have the value 255. Cast to int8_t to
ensure it always gets taken as signed. This is only needed for the
static_assert: the rest of the code already works for signed and
unsigned plain char alike.
@hvdijk
Copy link
Contributor Author

hvdijk commented Mar 14, 2025

Sure, changed to static_cast and rebased.

Copy link
Contributor

@uditagarwal97 uditagarwal97 left a comment

Choose a reason for hiding this comment

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

LGTM.

@hvdijk hvdijk temporarily deployed to WindowsCILock March 14, 2025 18:53 — with GitHub Actions Inactive
@hvdijk hvdijk temporarily deployed to WindowsCILock March 14, 2025 18:53 — with GitHub Actions Inactive
@uditagarwal97 uditagarwal97 merged commit d43aef3 into intel:sycl Mar 14, 2025
52 of 58 checks passed
@hvdijk
Copy link
Contributor Author

hvdijk commented Mar 14, 2025

@intel/llvm-gatekeepers This is ready to be merged, thanks (Edit: ha, already merged just as I was posting this. thanks!)

@hvdijk hvdijk deleted the funsigned-char branch March 14, 2025 22:14
Comment on lines +268 to +269
static_assert(
static_cast<int8_t>((ext_vector<int8_t, 2>{1, 0} == 0)[1]) == -1);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a better fix would be to use the same expression here and in line 272 (whatever it would be). @hvdijk any thoughts on that?

Copy link
Contributor Author

@hvdijk hvdijk Mar 17, 2025

Choose a reason for hiding this comment

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

Ideally yes, but the below needs to construct a vector which cannot be done with static_cast (and also, ext_vector is not available on GCC, but that might not matter here), and the below reinterpret_cast makes the expression non-constant so it cannot be used in static_assert.

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.

3 participants