llvm / llvm/llvm-project

[HLSL][AST] ArrayToPointer decay for array indexing?

Open
#179,951 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

clang:frontend HLSL
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Hi,

Found this while looking at the SGEP implementation on the frontend.
The following HLSL code:

void main() {
  uint array[4];
  array[2] = 12;
}

Yields this AST:

  | `-BinaryOperator 0x56193b16b770 <line:6:3, col:14> 'uint':'unsigned int' lvalue '='
  |   |-ArraySubscriptExpr 0x56193b16b718 <col:3, col:10> 'uint':'unsigned int' lvalue
  |   | |-ImplicitCastExpr 0x56193b16b700 <col:3> 'uint *' <ArrayToPointerDecay>
  |   | | `-DeclRefExpr 0x56193b16b648 <col:3> 'uint[4]' lvalue Var 0x56193b16b5c8 'array' 'uint[4]'
  |   | `-IntegerLiteral 0x56193b16b680 <col:9> 'int' 2
  |   `-ImplicitCastExpr 0x56193b16b758 <col:14> 'uint':'unsigned int' <IntegralCast>
  |     `-IntegerLiteral 0x56193b16b738 <col:14> 'int' 12

Is it by design that we have this ArrayToPointerDecay cast? When working on the SGEP emission (see https://github.com/llvm/llvm-project/pull/177332 ), I realized I needed to bypass those when emitting HLSL.

Seems to me this might be an oversight of the behavior we inherit from C/C++ no? Shouldn't we avoid those ArrayToPointer decay in HLSL since we have no pointers?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the HLSL example and inspect the generated AST, then read the frontend SGEP implementation discussed in PR 177332. Determine whether ArrayToPointerDecay is intended for HLSL array indexing and document or implement the agreed behavior so AST construction and SGEP emission are consistent.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.