Skip to content

cmd/compile: miscompilation of some arithmetic and conditionals on arm #42876

@zx2c4

Description

@zx2c4

@FiloSottile suggested that a recent mailing list post be moved to an issue, so here goes:

Jan Mercl reports that this code will miscompile on ARM:

package main

import "fmt"

var x = [4]int32{((-0x7fffffff - 1) / 2), 0x7fffffff, 2, 4} /* 20041210-1.c:5:5 */

func main() { /* 20041210-1.c:8:1: */
        if x[0] < x[1] {
                if x[2]&x[3] < 0 {
                        panic(fmt.Errorf("%v & %v = %v, < 0 ? %v", x[2], x[3], x[2]&x[3], x[2]&x[3] < 0))
                }
        }
}

Running the same code on 386 vs arm shows success on 386 and panics on arm. I've confirmed this is the case with 1.15.5, and Meng Zhuo confirmed it to be happening on 1.13, so it is at least a somewhat oldish bug.

The current issue title is vague because I haven't looked into what's actually happening yet. And I haven't yet assessed the security implications, either, but one can start imagining worrisome corner cases.

CC @rsc @cherrymui @ianlancetaylor @aclements

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.arch-armIssues solely affecting the 32-bit arm architecture.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions