Skip to content

fix mismatch between ExprTypeName and ExprType#2632

Merged
sbc100 merged 4 commits into
WebAssembly:mainfrom
Inginnng:fix/mismatch_between_ExprTypeName_and_ExprType
Sep 16, 2025
Merged

fix mismatch between ExprTypeName and ExprType#2632
sbc100 merged 4 commits into
WebAssembly:mainfrom
Inginnng:fix/mismatch_between_ExprTypeName_and_ExprType

Conversation

@Inginnng

@Inginnng Inginnng commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

#2631 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):

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):

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:

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
}

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

I guess we don't have any tests that cover this?

@sbc100

sbc100 commented Sep 15, 2025

Copy link
Copy Markdown
Member

Looking into the CI issues here: #2633

@Inginnng

Copy link
Copy Markdown
Contributor Author

fine, I found a timeout issue after uploading yesterday. I conducted three local tests, and the timeout error did not occur in any of them. and, I am not using macOS. so I didn't find the error in macOS build. thx for answering the CI issues.

@sbc100 sbc100 merged commit c5f3b04 into WebAssembly:main Sep 16, 2025
15 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants