Rust-GCC / Rust-GCC/gccrs

Evaluation order in struct expressions can be incorrect

Open
#4,445 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

Summary

https://doc.rust-lang.org/reference/expressions.html#r-expr.operand-order

GCCRS appears to evaluate child expressions of struct expressions in field definition order, not left to right inside the expression.

Reproducer
#![no_core]

extern "C" {
    fn first_call() -> i32;
    fn second_call() -> i32;
}

pub fn get_0() -> i32 {
    struct S {
        a: i32,
        b: i32
    };

    let x = unsafe {
        S { b: first_call (), a: second_call () }
    };

    x.a
}
Does the code make use of any (1.49) nightly feature ?
  • Nightly
Godbolt link

https://godbolt.org/z/9hEoM8YGd

Actual behavior

second_call is called first

Expected behavior

first_call is called first

GCC Version

308bc94241b95066f12818dc63b9f7b26c0b07f8

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust Reference section on operand order and reproduce the issue using the provided Rust example or Godbolt link. Trace how gccrs evaluates child expressions in struct expressions, then verify that the reproducer calls first_call before second_call as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.