Skip to content

x86 backend compile bug: error(x86_64_encoder): no encoding found for: none vsubss xmm0 xmm0 r32 none #20955

Description

@Saladiator

Zig Version

0.14.0-dev.839+a931bfada

Steps to Reproduce and Observed Behavior

Cannot compile this program:

const std = @import("std");

pub fn main() !void {
    const bug = Bug {
        .x = 100,
        .y = 200,
    };
    // does not work
    std.log.info("value: {d}", .{ bug.bug() });

    // calling a non-self fn works:
    //std.log.info("value: {d}", .{ no_bug(bug.x, bug.y) });
}

const Bug = struct {
    x: f32,
    y: ?f32,

    const Self = @This();

    fn bug(self: *const Self) f32 {
        return if (self.y) |y| self.x - y else 0.0;
    }    
};

fn no_bug(x: f32, y: ?f32) f32 {
    return if (y) |y_| x - y_ else 0.0;
}
zig run -fno-llvm -fno-lld src/main.zig

zig run -fno-llvm -fno-lld src/main.zig
error(x86_64_encoder): no encoding found for: none vsubss xmm0 xmm0 r32 none
src/main.zig:21:5: error: CodeGen failed to find a viable instruction. This is a bug in the Zig compiler.
    fn bug(self: *const Self) f32 {
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expected Behavior

It should print -100 when calling bug.bug().

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-x86_6464-bit x86backend-self-hostedbugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions