xhd2015/xgo

Bug: test kubernetes: mismatched types uint32 and int

xhd2015 opened this issue · 1 comments

Detailed message from CI [nightly-test]:

2024-06-01T02:07:26.8432659Z # k8s.io/kubernetes/pkg/kubelet/userns [k8s.io/kubernetes/pkg/kubelet/userns.test]
2024-06-01T02:07:26.8456085Z ##[error]pkg/kubelet/userns/userns_manager_test.go:127:31: invalid operation: allocated <= minimumMappingUID + mappingLen - int(__xgo_userNsLength_127_60) (mismatched types uint32 and int)
2024-06-01T02:07:30.3090737Z FAIL	k8s.io/kubernetes/pkg/kubelet/userns [build failed]

Reproducing:

const userNsLength = (1 << 16)
const (
	// skip the first block
	minimumMappingUID = userNsLength
	// allocate enough space for 2000 user namespaces
	mappingLen = userNsLength * 2000
)

func TestArrayPointer(t *testing.T) {
	var allocated uint32

	if allocated <= minimumMappingUID+mappingLen-userNsLength {

	}
}
$ go run -tags dev ./cmd/xgo test --project-dir runtime/test/debug
        # github.com/xhd2015/xgo/runtime/test/debug [github.com/xhd2015/xgo/runtime/test/debug.test]
./debug_test.go:26:18: invalid operation: allocated <= minimumMappingUID + mappingLen - int(__xgo_userNsLength_26_47) (mismatched types uint32 and int)
FAIL    github.com/xhd2015/xgo/runtime/test/debug [build failed]
exit status 1
exit status 1

Reason: since minimumMappingUID and mappingLen were const exprs, currently xgo cannot figure out their types.
And the expr minimumMappingUID+mappingLen-userNsLength is splited into 2 parts:

  • minimumMappingUID + mappingLen --> A
  • A - userNsLength

Since A is not correctly recognized as a const node, it makes userNsLength follow A's type, which is int, which turns out to be a mismatch with allocated(uint32).

Solution: when xgo cannot determine a const expr's type, it should mark it a 'const unknown type', and will bypass the following conversion mechanism.