Skip to content

[clang] Ternary elementwise builtin operators treat constness differently than others #155405

@ckoparkar

Description

@ckoparkar

Consider this code:

typedef float float3 __attribute__((ext_vector_type(3)));

typedef struct {
  float3 b;
} struct_float3;

float3 foo(float3 a, const struct_float3* hi) {
  return __builtin_elementwise_fma(a, a, hi->b.yyy);
}

float3 bar(float3 a, const struct_float3* hi) {
  return __builtin_elementwise_pow(a, hi->b.yyy);
}

Clang will report an error about foo but not bar:

source.cpp:19:36: error: arguments are of different types ('float3' (vector of 3 'float' values) vs 'const float3' (vector of 3 'float' values))
   19 |   return __builtin_elementwise_fma(a, a, hi->b.yyy);
      |                                    ^

The solution is to use ASTContext::hasSameUnqualifiedType() in BuiltinElementwiseTernaryMath similar to #141397. This was originally discovered by @tbaederr in #153572 (comment).

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang: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