Skip to content

Weird behavior of padding of -target-abi experimental-mv #146528

Open
@yhx-12243

Description

@yhx-12243

When compiling WebAssembly using -target-abi experimental-mv, the struct with padding will result in a very weird padding result: Use a lot of i32 to waste with. For example:

1.cpp:

struct Unit {};

struct A {
	int x;
	Unit c;
};

A foo() {
	return {};
}

Compiling command: clang++ 1.cpp -S -O3 --target=wasm32-unknown-unknown -Xclang -target-abi -Xclang experimental-mv

Result 1.s:

	.file	"1.cpp"
	.functype	_Z3foov () -> (i32, i32, i32, i32, i32)
	.section	.text._Z3foov,"",@
	.hidden	_Z3foov                         # -- Begin function _Z3foov
	.globl	_Z3foov
	.type	_Z3foov,@function
_Z3foov:                                # @_Z3foov
	.functype	_Z3foov () -> (i32, i32, i32, i32, i32)
	.local  	i32
# %bb.0:
	i32.const	0
	local.get	0
	local.get	0
	local.get	0
	local.get	0
                                        # fallthrough-return
	end_function
                                        # -- End function

Godbolt link: https://gcc.godbolt.org/z/s5Tb84qMz

However, if I change Unit into char, the behavior is as we expected.

I think it is a bug of experimental-mv ABI.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions