-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarification of rules for flattening structs containing arrays of empty records #358
Comments
However zero-sized arrays of empty records are ignored by both g++ and gcc for flattening (thanks @luismarques for the suggestion to check that case!). I'm attempting to align Clang/LLVM with this behaviour in https://reviews.llvm.org/D142327 |
My interpretation is that I'm not sure it is helpful to this discussion, but I believe that empty structs are a GNU C extension, while being (standard) C++; additionally, zero-length arrays are a GNU C/C++ extension. It's not clear to me what our psABI is expected to say about language extensions. |
ack, I plan to dig more deeper on lang spec in next few days, and seems |
Fix #358 The key point of this issue is C and C++ having different type size for array of empty struct or union, size of empty struct or union is 0 for C, and 1 for C++, and the size of array is type size multiplied by the length of the array. Also checked AArch64 code gen, they also generated different code between C and C++, and ABI isn't explicitly describe this but has describe the size of array is type * length.
Fix #358 The key point of this issue is C and C++ having different type size for array of empty struct or union, size of empty struct or union is 0 for C, and 1 for C++, and the size of array is type size multiplied by the length of the array. Also checked AArch64 code gen, they also generated different code between C and C++, and ABI isn't explicitly describe this but has describe the size of array is type * length.
Fix #358 The key point of this issue is C and C++ having different type size for array of empty struct or union, size of empty struct or union is 0 for C, and 1 for C++, and the size of array is type size multiplied by the length of the array. Also checked AArch64 code gen, they also generated different code between C and C++, and ABI isn't explicitly describe this but has describe the size of array is type * length.
Fix #358 The key point of this issue is C and C++ having different type size for array of empty struct or union, size of empty struct or union is 0 for C, and 1 for C++, and the size of array is type size multiplied by the length of the array. Also checked AArch64 code gen, they also generated different code between C and C++, and ABI isn't explicitly describe this but has describe the size of array is type * length.
Fix #358 The key point of this issue is C and C++ having different type size for array of empty struct or union, size of empty struct or union is 0 for C, and 1 for C++, and the size of array is type size multiplied by the length of the array. Also checked AArch64 code gen, they also generated different code between C and C++, and ABI isn't explicitly describe this but has describe the size of array is type * length.
Fix #358 The key point of this issue is C and C++ having different type size for array of empty struct or union, size of empty struct or union is 0 for C, and 1 for C++, and the size of array is type size multiplied by the length of the array. Also checked AArch64 code gen, they also generated different code between C and C++, and ABI isn't explicitly describe this but has describe the size of array is type * length.
… conventions in C++ As reported in <#58929>, Clang's handling of empty structs in the case of small structs that may be eligible to be passed using the hard FP calling convention doesn't match g++. In general, C++ record fields are never empty unless [[no_unique_address]] is used, but the RISC-V FP ABI overrides this. After this patch, fields of structs that contain empty records will be ignored, even in C++, when considering eligibility for the FP calling convention ('flattening'). See also the relevant psABI issue <riscv-non-isa/riscv-elf-psabi-doc#358> which seeks to clarify the documentation. Fixes #58929 Differential Revision: https://reviews.llvm.org/D142327
…calling conventions in C++ As reported in <#58929>, Clang's handling of empty structs in the case of small structs that may be eligible to be passed using the hard FP calling convention doesn't match g++. In general, C++ record fields are never empty unless [[no_unique_address]] is used, but the RISC-V FP ABI overrides this. After this patch, fields of structs that contain empty records will be ignored, even in C++, when considering eligibility for the FP calling convention ('flattening'). It isn't explicitly noted in the RISC-V psABI, but arrays of empty records will disqualify a struct for consideration of using the FP calling convention in g++. This patch matches that behaviour. The psABI issue <riscv-non-isa/riscv-elf-psabi-doc#358> seeks to clarify this. This patch was previously committed but reverted after a bug was found. This recommit adds additional logic to prevent that bug (adding an extra check for when a candidate from detectFPCCEligibleStructHelper may not be valid). Differential Revision: https://reviews.llvm.org/D142327
…calling conventions in C++ As reported in <llvm/llvm-project#58929>, Clang's handling of empty structs in the case of small structs that may be eligible to be passed using the hard FP calling convention doesn't match g++. In general, C++ record fields are never empty unless [[no_unique_address]] is used, but the RISC-V FP ABI overrides this. After this patch, fields of structs that contain empty records will be ignored, even in C++, when considering eligibility for the FP calling convention ('flattening'). It isn't explicitly noted in the RISC-V psABI, but arrays of empty records will disqualify a struct for consideration of using the FP calling convention in g++. This patch matches that behaviour. The psABI issue <riscv-non-isa/riscv-elf-psabi-doc#358> seeks to clarify this. This patch was previously committed but reverted after a bug was found. This recommit adds additional logic to prevent that bug (adding an extra check for when a candidate from detectFPCCEligibleStructHelper may not be valid). Differential Revision: https://reviews.llvm.org/D142327
…calling conventions in C++ As reported in <llvm/llvm-project#58929>, Clang's handling of empty structs in the case of small structs that may be eligible to be passed using the hard FP calling convention doesn't match g++. In general, C++ record fields are never empty unless [[no_unique_address]] is used, but the RISC-V FP ABI overrides this. After this patch, fields of structs that contain empty records will be ignored, even in C++, when considering eligibility for the FP calling convention ('flattening'). It isn't explicitly noted in the RISC-V psABI, but arrays of empty records will disqualify a struct for consideration of using the FP calling convention in g++. This patch matches that behaviour. The psABI issue <riscv-non-isa/riscv-elf-psabi-doc#358> seeks to clarify this. This patch was previously committed but reverted after a bug was found. This recommit adds additional logic to prevent that bug (adding an extra check for when a candidate from detectFPCCEligibleStructHelper may not be valid). Differential Revision: https://reviews.llvm.org/D142327
… conventions in C++ As reported in <llvm/llvm-project#58929>, Clang's handling of empty structs in the case of small structs that may be eligible to be passed using the hard FP calling convention doesn't match g++. In general, C++ record fields are never empty unless [[no_unique_address]] is used, but the RISC-V FP ABI overrides this. After this patch, fields of structs that contain empty records will be ignored, even in C++, when considering eligibility for the FP calling convention ('flattening'). See also the relevant psABI issue <riscv-non-isa/riscv-elf-psabi-doc#358> which seeks to clarify the documentation. Fixes llvm/llvm-project#58929 Differential Revision: https://reviews.llvm.org/D142327
The hard FP calling convention currently states "Fields containing empty structs or unions are ignored while flattening, even in C++, unless they have nontrivial copy constructors or destructors." It appears that g++ doesn't ignore an array of empty records in a struct. If this is indeed the desired behaviour, it would be good to document it.
In the above example, the float is passed in a0 with g++ but fa0 with gcc.
The text was updated successfully, but these errors were encountered: