Skip to content

infinite loop optimized away unless function is exported #1658

Closed
@numsim1415

Description

@numsim1415
export fn square(num: u8) u8 {
             
             //while(true){} // would generate loop
             return eternity(123); 
}

pub fn eternity(bla:u8) u8 {
  while(true)// is optimized away completely
  {}
}

See asm output on goldbold.
As you said during live coding, it seems like the eternal loop is considered to have no side effects and is thus removed.

Expected behaviour would be to refuse compilation

  • as there is no return of an u8
  • as in case of eternity being declared as returning void, an implicit return; at the end of the function cannot be reached

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend-llvmThe LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behaviorupstreamAn issue with a third party project that Zig uses.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions