Skip to content

[HLSL] Make a plan for builtin diagnostics #211

@llvm-beanz

Description

@llvm-beanz

Many of the HLSL builtins are reporting diagnostics using err_typecheck_convert_incompatible, which produces diagnostics of the form:
error: passing <type1> to parameter of incompatible type <type2>. This diagnostic strongly implies the usage of the builtin requires a specific type, which is not the case. For example see the __builtin_hlsl_cross intrinsic which is valid for 16 and 32-bit floating point types and vectors of such type.

export int4 fn(int4 x, int4 y) {
    return __builtin_hlsl_cross(x, y);
}

export int16_t4 fn(int16_t4 x, int16_t4 y) {
    return __builtin_hlsl_cross(x, y);
}

Compiler Explorer

Diagnostics:

<source>:2:33: error: passing 'int4' (aka 'vector<int, 4>') to parameter of incompatible type '__attribute__((__vector_size__(4 * sizeof(float)))) float' (vector of 4 'float' values)
    2 |     return __builtin_hlsl_cross(x, y);
      |                                 ^
<source>:6:33: error: passing 'int16_t4' (aka 'vector<int16_t, 4>') to parameter of incompatible type '__attribute__((__vector_size__(4 * sizeof(float)))) float' (vector of 4 'float' values)
    6 |     return __builtin_hlsl_cross(x, y);
      |                                 ^

These diagnostics strongly indicate to a user that you must call the builtin with a float4.

Related: llvm/llvm-project#125673

Our strategy for diagnosing builtins for HLSL should align with Clang's general approach.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions