[flang-commits] [flang] [flang] Inherit target specific code for BIND(C) types on Windows (PR #129579)

Eli Friedman via flang-commits flang-commits at lists.llvm.org
Thu Mar 6 14:46:00 PST 2025


efriedma-quic wrote:

> why clang does not set the byval attribute when passing the struct in memory (like it is done for linux)?

"byval" is weird: it actually allocates memory on the stack, as part of the argument list, then copies the argument into that memory.  Old targets sometimes pass memory like this.  The designers for more modern ABIs have recognized that passing around large values like that isn't a good idea, so they don't do that; they pass a pointer to a temporary allocated on the stack.  Try looking at the assembly on x86_64-linux-gnu vs. x86_64-windows-msvc for `struct S { int x[100]; }; void f(struct S); void g() { f((struct S){}); }` if you're confused.

> should the alignment of struct in memory be 16 like required when passing arguments, or the default alignment for the type?

The "caller-allocated temporary memory must be 16-byte aligned" specifically only applies to calls; in other contexts, normal alignment rules apply.

https://github.com/llvm/llvm-project/pull/129579


More information about the flang-commits mailing list