<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/136135>136135</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang][bytecode] Find a way around `PointerToIntegral` cast that result in an lvalue
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend,
            clang:bytecode
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          tbaederr
      </td>
    </tr>
</table>

<pre>
    Consider this simple example:
```c
typedef __typeof((int*) 0 - (int*) 0) intptr_t;

int a = 10;
intptr_t s = (intptr_t) &a;
```

Comipiled as C, there are no compilation errors. However, when evaluating the initializer for `s`:
```
CStyleCastExpr 0x7d6799454e40 'intptr_t':'long' <PointerToIntegral>
`-UnaryOperator 0x7d6799454e08 'int *' prefix '&' cannot overflow
  `-DeclRefExpr 0x7d6799454de0 'int' lvalue Var 0x7d6799454bf8 'a' 'int'
```

the current interpreter doesn't actually return an integer value at all, it returns an lvalue pointing to `a`:
```
LValue Base=VarDecl 0x7d6799454bf8, Null=0, Offset=0, HasPath=0
```

which ultimately means we get the following IR:
```llvm
@a = dso_local global i32 10, align 4
@s = dso_local global i64 ptrtoint (ptr @a to i64), align 8
```

that's because the current interpreter takes this code path:
https://github.com/llvm/llvm-project/blob/fb00fa56b51b191d026eec104905e416bf34bbda/clang/lib/AST/ExprConstant.cpp#L15269-L15280

which means it returns an lvalue from an AST node that returns an integer. That works in the current interpreter where everything is an `APValue` an one can check the type of those values, but in a bytecode interpreter, where we expect the computed type to match the node type, it doesn't work.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVcuO27gS_Rp6U2iDol7Wwgu3HSMBgpsg6ZttoySVLE7TpECW2u35-gEle_q9GMCwxGK9z6kShqAPlmgt8luR7xY4cu_8mmuklrxf1K49r7fOBt2SB-51gKCPgyGgJ4xPkW6E3IhCzr9G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