Skip to content

Commit c5f3b04

Browse files
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: #2631
1 parent a2657f2 commit c5f3b04

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/ir.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
namespace {
2626

2727
const char* ExprTypeName[] = {
28-
"AtomicFence",
2928
"AtomicLoad",
3029
"AtomicRmw",
3130
"AtomicRmwCmpxchg",
3231
"AtomicStore",
3332
"AtomicNotify",
33+
"AtomicFence",
3434
"AtomicWait",
3535
"Binary",
3636
"Block",

0 commit comments

Comments
 (0)