Skip to content

[backend] bad gimple output in HIR::WhileLoopExpr #4521

@Islam-Imad

Description

@Islam-Imad
#![feature(no_core)]
#![no_core]
extern "C" {
    fn puts(s: *const i8);
}
extern "C" {
    fn printf(s: *const i8, ...);
}
fn dump(message: &str) {
    unsafe {
        let b = message as *const str;
        let c = b as *const i8;
        puts(c);
    }
}
fn dump_number(num: i32) {
    unsafe {
        let a = "%i\n\0";
        let b = a as *const str;
        let c = b as *const i8;
        printf(c, num);
    }
}

fn play(b: i32) -> i32 {
    let mut res = 0;
    let mut i = 0;
    'calculation: while i < b {
            res += i;
            i += 1;
            if res + i >= 99 {
                break 'calculation;
            }
        }
    res
}

fn main() {
    let a :  i32 = play(111); // <= 99
    dump_number(a);
}
__attribute__((cdecl))
i32 rust::play (const i32 b)
{
  complex int D.1590;
  complex int D.1593;
  complex int D.1596;
  i32 D.1601;
  i32 i;
  i32 res;

  res = 0;
  i = 0;
  calculation:
  <D.1587>:
  {
    <D.150>:
    if (i >= b) goto <D.1588>; else goto <D.1589>;
    <D.1589>:
    {
      D.1590 = .ADD_OVERFLOW (res, i);
      _1 = REALPART_EXPR <D.1590>;
      RUSTTMP.5 = _1;
      _2 = IMAGPART_EXPR <D.1590>;
      _3 = (bool) _2;
      if (_3 != 0) goto <D.1591>; else goto <D.1592>;
      <D.1591>:
      __builtin_abort ();
      <D.1592>:
      res = RUSTTMP.5;
      D.1593 = .ADD_OVERFLOW (i, 1);
      _4 = REALPART_EXPR <D.1593>;
      RUSTTMP.6 = _4;
      _5 = IMAGPART_EXPR <D.1593>;
      _6 = (bool) _5;
      if (_6 != 0) goto <D.1594>; else goto <D.1595>;
      <D.1594>:
      __builtin_abort ();
      <D.1595>:
      i = RUSTTMP.6;
      D.1596 = .ADD_OVERFLOW (res, i);
      _7 = REALPART_EXPR <D.1596>;
      RUSTTMP.7 = _7;
      _8 = IMAGPART_EXPR <D.1596>;
      _9 = (bool) _8;
      if (_9 != 0) goto <D.1597>; else goto <D.1598>;
      <D.1597>:
      __builtin_abort ();
      <D.1598>:
      RUSTTMP.9_10 = RUSTTMP.7;
      if (RUSTTMP.9_10 > 98) goto <D.1599>; else goto <D.1600>;
      <D.1599>:
      {
        goto calculation;
      }
      <D.1600>:
    }
  }
  goto <D.1587>;
  <D.1588>:
  D.1601 = res;
  return D.1601;
}

gccrs-output : 6105
rustc-output : 91
problem : the label and goto is not ordered properly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions