Skip to content

constexpr can't handle vector types #41806

Closed
@RKSimon

Description

@RKSimon
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];

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions