Commit c5f3b04
authored
Fix mismatch between ExprTypeName and ExprType (#2632)
There is an inconsistency between the order of enum values in
`ExprType` (defined in `ir.h`) and the corresponding string names in
`ExprTypeName` array (defined in `ir.cc`). This causes
`GetExprTypeName()` to return incorrect string representations for
atomic operation related expression types.
In `ir.h` (`ExprType` enum):
```cpp
enum class ExprType {
AtomicLoad, // index 0
AtomicRmw, // index 1
AtomicRmwCmpxchg, // index 2
AtomicStore, // index 3
AtomicNotify, // index 4
AtomicFence, // index 5
AtomicWait, // index 6
// ... rest of enum values
};
```
In `ir.cc` (`ExprTypeName` array):
```cpp
const char* ExprTypeName[] = {
"AtomicFence", // index 0 - should correspond to AtomicLoad
"AtomicLoad", // index 1 - should correspond to AtomicRmw
"AtomicRmw", // index 2 - should correspond to AtomicRmwCmpxchg
"AtomicRmwCmpxchg", // index 3 - should correspond to AtomicStore
"AtomicStore", // index 4 - should correspond to AtomicNotify
"AtomicNotify", // index 5 - should correspond to AtomicFence
"AtomicWait", // index 6 - correct position
// ... rest matches correctly
};
```
The error occurs in these functions:
In `ir.cc`:
```cpp
const char* GetExprTypeName(ExprType type) {
static_assert(WABT_ENUM_COUNT(ExprType) == WABT_ARRAY_SIZE(ExprTypeName),
"Malformed ExprTypeName array");
return ExprTypeName[size_t(type)]; // Returns wrong name due to index mismatch
}
const char* GetExprTypeName(const Expr& expr) {
return GetExprTypeName(expr.type()); // Inherits the same issue
}
```
Fixes: #26311 parent a2657f2 commit c5f3b04
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
0 commit comments