Author: Alex Bradbury
Date: 2022-08-11T18:51:37+01:00
New Revision: d17de5479c6234f9e37fb4deca9e537bf8d3932e

URL: 
https://github.com/llvm/llvm-project/commit/d17de5479c6234f9e37fb4deca9e537bf8d3932e
DIFF: 
https://github.com/llvm/llvm-project/commit/d17de5479c6234f9e37fb4deca9e537bf8d3932e.diff

LOG: [clang][RISCV][test] Add test that shows incorrect ABI lowering

As reported in <https://github.com/llvm/llvm-project/issues/57084>,
under hard float ABIs there are issues with lowering structs that
inherit from other structs.

See <https://reviews.llvm.org/D131677> for a fix.

Added: 
    clang/test/CodeGen/RISCV/riscv-abi.cpp

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/clang/test/CodeGen/RISCV/riscv-abi.cpp 
b/clang/test/CodeGen/RISCV/riscv-abi.cpp
new file mode 100644
index 0000000000000..ba9e61bbbe7db
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/riscv-abi.cpp
@@ -0,0 +1,88 @@
+// RUN: %clang_cc1 -triple riscv32 -emit-llvm -x c++ %s -o - \
+// RUN:   | FileCheck -check-prefixes=ILP32,ILP32-ILP32F,ILP32-ILP32F-ILP32D %s
+// RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-abi ilp32f 
-emit-llvm -x c++ %s -o - \
+// RUN:   | FileCheck 
-check-prefixes=ILP32F,ILP32-ILP32F,ILP32F-ILP32D,ILP32-ILP32F-ILP32D %s
+// RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-feature +d 
-target-abi ilp32d -emit-llvm %s -x c++ -o - \
+// RUN:   | FileCheck -check-prefixes=ILP32D,ILP32F-ILP32D,ILP32-ILP32F-ILP32D 
%s
+
+// RUN: %clang_cc1 -triple riscv64 -emit-llvm -x c++ %s -o - \
+// RUN:   | FileCheck -check-prefixes=LP64,LP64-LP64F,LP64-LP64F-LP64D %s
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-abi lp64f 
-emit-llvm -x c++ %s -o - \
+// RUN:   | FileCheck 
-check-prefixes=LP64F,LP64-LP64F,LP64F-LP64D,LP64-LP64F-LP64D %s
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d 
-target-abi lp64d -emit-llvm %s -x c++ -o - \
+// RUN:   | FileCheck -check-prefixes=LP64D,LP64F-LP64D,LP64-LP64F-LP64D %s
+
+#include <stdint.h>
+
+// Ensure that fields inherited from a parent struct are treated in the same
+// way as fields directly in the child for the purposes of RISC-V ABI rules.
+
+struct parent1_int32_s {
+  int32_t i1;
+};
+
+struct child1_int32_s : parent1_int32_s {
+  int32_t i2;
+};
+
+// ILP32-ILP32F-ILP32D-LABEL: define{{.*}} [2 x i32] 
@_Z30int32_int32_struct_inheritance14child1_int32_s([2 x i32] %a.coerce)
+// LP64-LP64F-LP64D-LABEL: define{{.*}} i64 
@_Z30int32_int32_struct_inheritance14child1_int32_s(i64 %a.coerce)
+struct child1_int32_s int32_int32_struct_inheritance(struct child1_int32_s a) {
+  return a;
+}
+
+struct parent2_int32_s {
+  int32_t i1;
+};
+
+struct child2_float_s : parent2_int32_s {
+  float f1;
+};
+
+// TODO: Fix incorrect lowering for hard-float ABIs.
+
+// ILP32: define{{.*}} [2 x i32] 
@_Z30int32_float_struct_inheritance14child2_float_s([2 x i32] %a.coerce)
+// ILP32F-ILP32D: define{{.*}} float 
@_Z30int32_float_struct_inheritance14child2_float_s(float %0)
+// LP64: define{{.*}} i64 
@_Z30int32_float_struct_inheritance14child2_float_s(i64 %a.coerce)
+// LP64F-LP64D: define{{.*}} float 
@_Z30int32_float_struct_inheritance14child2_float_s(float %0)
+struct child2_float_s int32_float_struct_inheritance(struct child2_float_s a) {
+  return a;
+}
+
+struct parent3_float_s {
+  float f1;
+};
+
+struct child3_int64_s : parent3_float_s {
+  int64_t i1;
+};
+
+// TODO: Fix incorrect lowering for lp64f/lp64d ABIs.
+
+// ILP32-ILP32F-ILP32D-LABEL: define{{.*}} void 
@_Z30float_int64_struct_inheritance14child3_int64_s(ptr noalias 
sret(%struct.child3_int64_s)
+// LP64-LP64F-LP64D-LABEL: define{{.*}} [2 x i64] 
@_Z30float_int64_struct_inheritance14child3_int64_s([2 x i64] %a.coerce)
+struct child3_int64_s float_int64_struct_inheritance(struct child3_int64_s a) {
+  return a;
+}
+
+struct parent4_double_s {
+  double d1;
+};
+
+struct child4_double_s : parent4_double_s {
+  double d1;
+};
+
+// TODO: Fix incorrect lowering for ilp32d/lp64d ABIs.
+
+// ILP32-ILP32F-LABEL: define{{.*}} void 
@_Z32double_double_struct_inheritance15child4_double_s(ptr noalias 
sret(%struct.child4_double_s)
+// ILP32D-LABEL: define{{.*}} double 
@_Z32double_double_struct_inheritance15child4_double_s(double %0)
+// LP64-LP64F-LABEL: define{{.*}} [2 x i64] 
@_Z32double_double_struct_inheritance15child4_double_s([2 x i64] %a.coerce)
+// LP64D-LABEL: define{{.*}} double 
@_Z32double_double_struct_inheritance15child4_double_s(double %0)
+struct child4_double_s double_double_struct_inheritance(struct child4_double_s 
a) {
+  return a;
+}
+
+// NOTE: These prefixes are unused. Do not add tests below this line:
+// ILP32F: {{.*}}
+// LP64F: {{.*}}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to