Skip to content

constexpr can't handle vector types #41806

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

Closed
RKSimon opened this issue Jul 1, 2019 · 4 comments
Closed

constexpr can't handle vector types #41806

RKSimon opened this issue Jul 1, 2019 · 4 comments
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@RKSimon
Copy link
Collaborator

RKSimon commented Jul 1, 2019

Bugzilla Link 42461
Version unspecified
OS Windows NT
Blocks #30794
CC @erichkeane,@mshockwave,@zygoloid
Fixed by commit(s) b30c166

Extended Description

Godbolt: https://godbolt.org/z/l-RaB7

We are unable to use __vector_size or ext_vector_type defined types in constexpr functions.

typedef int __v4si __attribute__((__vector_size__(16)));

constexpr int sum_i32(__v4si x) {
  return x[0] + x[1] + x[2] + x[3];
}

constexpr __v4si add_i32(__v4si x, __v4si y) {
  return x + y;
}

clang -g0 -O3

<source>:3:18: error: constexpr function never produces a constant expression [-Winvalid-constexpr]

constexpr __v4si add_i32(__v4si x, __v4si y) {
                 ^

<source>:4:12: note: subexpression not valid in a constant expression
  return x + y;

           ^

<source>:7:15: error: constexpr function never produces a constant expression [-Winvalid-constexpr]

constexpr int sum_i32(__v4si x) {

              ^

<source>:8:10: note: subexpression not valid in a constant expression
  return x[0] + x[1] + x[2] + x[3];
@RKSimon
Copy link
Collaborator Author

RKSimon commented May 8, 2020

CC'ing some more people that might have some ideas on how best to get this done - based off the recent cfe-dev discussions about adding vector ternary support.

@erichkeane
Copy link
Collaborator

Partial support here:
https://reviews.llvm.org/D79755

I don't have array subscript expressions implemented (perhaps a future task), so the error in 'sum_i32' still happens but add_i32 will work with that patch.

@yronglin
Copy link
Contributor

yronglin commented Sep 7, 2024

IIUC, this issue has already fixed. https://godbolt.org/z/rccbYzYrc

@yronglin yronglin closed this as completed Sep 7, 2024
@RKSimon
Copy link
Collaborator Author

RKSimon commented Sep 7, 2024

IIUC, this issue has already fixed. https://godbolt.org/z/rccbYzYrc

I think this was addressed by #101126 / 7753429

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

3 participants