[clang] [clang][bytecode] Implement arithmetic, bitwise and compound assignment operator (PR #108949)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 24 06:51:50 PDT 2024
tbaederr wrote:
For the code in question:
```c++
using FourCharsVecSize __attribute__((vector_size(4))) = char;
constexpr auto s = FourCharsVecSize{6, 3, 5, 10} << 1;
static_assert(s[0] == 12 && s[1] == 6 && s[2] == 10 && s[3] == 20, "");
```
The AST is:
```
BinaryOperator 0x16251b8 'FourCharsVecSize':'__attribute__((__vector_size__(4 * sizeof(char)))) char' '<<'
|-CXXFunctionalCastExpr 0x1625120 'FourCharsVecSize':'__attribute__((__vector_size__(4 * sizeof(char)))) char' functional cast to FourCharsVecSize <NoOp>
| `-InitListExpr 0x1625060 'FourCharsVecSize':'__attribute__((__vector_size__(4 * sizeof(char)))) char'
| |-ImplicitCastExpr 0x16250c0 'char' <IntegralCast>
| | `-IntegerLiteral 0x1624f80 'int' 6
| |-ImplicitCastExpr 0x16250d8 'char' <IntegralCast>
| | `-IntegerLiteral 0x1624fa0 'int' 3
| |-ImplicitCastExpr 0x16250f0 'char' <IntegralCast>
| | `-IntegerLiteral 0x1624fc0 'int' 5
| `-ImplicitCastExpr 0x1625108 'char' <IntegralCast>
| `-IntegerLiteral 0x1624fe0 'int' 10
`-ImplicitCastExpr 0x16251a0 'int __attribute__((ext_vector_type(4)))' <VectorSplat>
`-IntegerLiteral 0x1625148 'int' 1
```
so the assumption that the elemen tyopes of RHS and LHS are the same does not hold.
This would've come up earlier if I had put an assertion in the right place:
```diff
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 1f4c302b2619..d77646c2bdaf 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2584,6 +2584,7 @@ inline bool ArrayElemPop(InterpState &S, CodePtr OpPC, uint32_t Index) {
if (!CheckLoad(S, OpPC, Ptr))
return false;
+ assert(Ptr.atIndex(Index).getFieldDesc()->getPrimType() == Name);
S.Stk.push<T>(Ptr.atIndex(Index).deref<T>());
return true;
}
```
https://github.com/llvm/llvm-project/pull/108949
More information about the cfe-commits
mailing list