================
@@ -0,0 +1,145 @@
+// RUN: %clang_cc1 -triple aarch64-windows-msvc -std=c++20 -emit-llvm -o - %s 
| FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-windows-msvc -std=c++20 
-fexperimental-abi-lowering -emit-llvm -o - %s 2>&1 | FileCheck %s 
--implicit-check-not="not yet implemented"
+
+// Each record holds 16 bytes of doubles. An HFA is passed as [2 x double] and
+// a record that MSVC does not treat as an HFA is passed as [2 x i64].
+
+struct Empty {};
+struct ZeroLength {
+  int arr[0];
+};
+struct DoubleBase {
+  double a;
+};
+
+extern "C" {
+
+struct Pod {
+  double a, b;
+};
+void arg_pod(Pod s) {}
+// CHECK: define{{.*}} void @arg_pod([2 x double] %{{.*}})
+
+struct TrivialCopyAssign {
+  double a, b;
+  TrivialCopyAssign &operator=(const TrivialCopyAssign &) = default;
+};
+void arg_trivial_copy_assign(TrivialCopyAssign s) {}
+// CHECK: define{{.*}} void @arg_trivial_copy_assign([2 x double] %{{.*}})
+
+struct NonTrivialCopyAssign {
+  double a, b;
+  NonTrivialCopyAssign &operator=(const NonTrivialCopyAssign &);
+};
+void arg_non_trivial_copy_assign(NonTrivialCopyAssign s) {}
+// CHECK: define{{.*}} void @arg_non_trivial_copy_assign([2 x i64] %{{.*}})
+
+struct NonDefaultCtor {
+  double a, b;
+  NonDefaultCtor(int);
+};
+void arg_non_default_ctor(NonDefaultCtor s) {}
+// CHECK: define{{.*}} void @arg_non_default_ctor([2 x double] %{{.*}})
+
+struct UserDefaultCtor {
+  double a, b;
+  UserDefaultCtor();
+};
+void arg_user_default_ctor(UserDefaultCtor s) {}
+// CHECK: define{{.*}} void @arg_user_default_ctor([2 x i64] %{{.*}})
+
+struct MemberInit {
+  double a = 1.0;
+  double b;
+};
+void arg_member_init(MemberInit s) {}
+// CHECK: define{{.*}} void @arg_member_init([2 x i64] %{{.*}})
+
+struct TrivialDtor {
+  double a, b;
+  ~TrivialDtor() = default;
+};
+void arg_trivial_dtor(TrivialDtor s) {}
+// CHECK: define{{.*}} void @arg_trivial_dtor([2 x double] %{{.*}})
+
+struct NonTrivialDtor {
+  double a, b;
+  ~NonTrivialDtor();
+};
+void arg_non_trivial_dtor(NonTrivialDtor s) {}
+// CHECK: define{{.*}} void @arg_non_trivial_dtor([2 x i64] %{{.*}})
+
+struct PrivateMember {
+  double a;
+
+private:
+  double b;
+};
+void arg_private_member(PrivateMember s) {}
+// CHECK: define{{.*}} void @arg_private_member([2 x double] %{{.*}})
+
+// A non-empty base contributes members, but an empty base disqualifies the
+// derived record.
+struct NonEmptyBase : DoubleBase {
+  double b;
+};
+void arg_non_empty_base(NonEmptyBase s) {}
+// CHECK: define{{.*}} void @arg_non_empty_base([2 x double] %{{.*}})
+
+struct EmptyBase : Empty {
+  double a, b;
+};
+void arg_empty_base(EmptyBase s) {}
+// CHECK: define{{.*}} void @arg_empty_base([2 x i64] %{{.*}})
+
+struct IndirectEmptyBase : EmptyBase {};
+void arg_indirect_empty_base(IndirectEmptyBase s) {}
+// CHECK: define{{.*}} void @arg_indirect_empty_base([2 x i64] %{{.*}})
+
+// The rules also apply to the record type of each field, including array
+// elements and union members.
+struct PodField {
+  Pod p;
+};
+void arg_pod_field(PodField s) {}
+// CHECK: define{{.*}} void @arg_pod_field([2 x double] %{{.*}})
+
+struct EmptyBaseField {
+  EmptyBase e;
+};
+void arg_empty_base_field(EmptyBaseField s) {}
+// CHECK: define{{.*}} void @arg_empty_base_field([2 x i64] %{{.*}})
+
+struct EmptyBaseArrayField {
+  EmptyBase e[1];
+};
+void arg_empty_base_array_field(EmptyBaseArrayField s) {}
+// CHECK: define{{.*}} void @arg_empty_base_array_field([2 x i64] %{{.*}})
----------------
madhur13490 wrote:

Could you add an empty field that takes no space? Neither path checks fields 
here; both rely on the padding check to reject empty fields (the comment in 
`MicrosoftCXXABI::isPermittedToBeHomogeneousAggregate` says as much). With 
`[[msvc::no_unique_address]]` there is no padding, so both paths treat the 
record as an HFA:

```cpp
struct NoUniqueAddressEmpty {
  [[msvc::no_unique_address]] Empty e;
  double a, b;
};
void arg_no_unique_address_empty(NoUniqueAddressEmpty s) {}
// CHECK: define{{.*}} void @arg_no_unique_address_empty([2 x double] %{{.*}})
```

Having this under both RUN lines would catch either path changing how it 
handles this case.

https://github.com/llvm/llvm-project/pull/239846
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to