Skip to content

[RISCV][clang] Fix wrong VLS CC detection #130107

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

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

kito-cheng
Copy link
Member

RISCVABIInfo::detectVLSCCEligibleStruct should early exit if VLS calling convention is not used, however the sentinel value was not set to correctly, it should be zero instead of one.

RISCVABIInfo::detectVLSCCEligibleStruct should early exit if VLS calling
convention is not used, however the sentinel value was not set to correctly,
it should be zero instead of one.
@kito-cheng kito-cheng requested review from topperc and 4vtomat March 6, 2025 13:40
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:RISC-V clang:codegen IR generation bugs: mangling, exceptions, etc. labels Mar 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 6, 2025

@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-backend-risc-v

Author: Kito Cheng (kito-cheng)

Changes

RISCVABIInfo::detectVLSCCEligibleStruct should early exit if VLS calling convention is not used, however the sentinel value was not set to correctly, it should be zero instead of one.


Full diff: https://github.com/llvm/llvm-project/pull/130107.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/Targets/RISCV.cpp (+1-1)
  • (added) clang/test/CodeGen/RISCV/pr129995.cc (+24)
diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp
index e350a3589dcaf..7fddde415e7cc 100644
--- a/clang/lib/CodeGen/Targets/RISCV.cpp
+++ b/clang/lib/CodeGen/Targets/RISCV.cpp
@@ -389,7 +389,7 @@ ABIArgInfo RISCVABIInfo::coerceAndExpandFPCCEligibleStruct(
 bool RISCVABIInfo::detectVLSCCEligibleStruct(QualType Ty, unsigned ABIVLen,
                                              llvm::Type *&VLSType) const {
   // No riscv_vls_cc attribute.
-  if (ABIVLen == 1)
+  if (ABIVLen == 0)
     return false;
 
   // Legal struct for VLS calling convention should fulfill following rules:
diff --git a/clang/test/CodeGen/RISCV/pr129995.cc b/clang/test/CodeGen/RISCV/pr129995.cc
new file mode 100644
index 0000000000000..590c6b9fbdf96
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/pr129995.cc
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 triple riscv64 -emit-llvm -target-feature +m -target-feature +v -target-abi lp64d -o /dev/null %s
+
+struct a {
+  using b = char __attribute__((vector_size(sizeof(char))));
+};
+class c {
+  using d = a::b;
+  d e;
+
+public:
+  static c f();
+};
+class g {
+public:
+  template <class h> g(h);
+  friend g operator^(g, g) { c::f; }
+  friend g operator^=(g i, g j) { i ^ j; }
+};
+template <typename, int> using k = g;
+template <typename l> using m = k<l, sizeof(l)>;
+void n() {
+  void o();
+  m<char> p = o ^= p;
+}

@llvmbot
Copy link
Member

llvmbot commented Mar 6, 2025

@llvm/pr-subscribers-clang

Author: Kito Cheng (kito-cheng)

Changes

RISCVABIInfo::detectVLSCCEligibleStruct should early exit if VLS calling convention is not used, however the sentinel value was not set to correctly, it should be zero instead of one.


Full diff: https://github.com/llvm/llvm-project/pull/130107.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/Targets/RISCV.cpp (+1-1)
  • (added) clang/test/CodeGen/RISCV/pr129995.cc (+24)
diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp
index e350a3589dcaf..7fddde415e7cc 100644
--- a/clang/lib/CodeGen/Targets/RISCV.cpp
+++ b/clang/lib/CodeGen/Targets/RISCV.cpp
@@ -389,7 +389,7 @@ ABIArgInfo RISCVABIInfo::coerceAndExpandFPCCEligibleStruct(
 bool RISCVABIInfo::detectVLSCCEligibleStruct(QualType Ty, unsigned ABIVLen,
                                              llvm::Type *&VLSType) const {
   // No riscv_vls_cc attribute.
-  if (ABIVLen == 1)
+  if (ABIVLen == 0)
     return false;
 
   // Legal struct for VLS calling convention should fulfill following rules:
diff --git a/clang/test/CodeGen/RISCV/pr129995.cc b/clang/test/CodeGen/RISCV/pr129995.cc
new file mode 100644
index 0000000000000..590c6b9fbdf96
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/pr129995.cc
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 triple riscv64 -emit-llvm -target-feature +m -target-feature +v -target-abi lp64d -o /dev/null %s
+
+struct a {
+  using b = char __attribute__((vector_size(sizeof(char))));
+};
+class c {
+  using d = a::b;
+  d e;
+
+public:
+  static c f();
+};
+class g {
+public:
+  template <class h> g(h);
+  friend g operator^(g, g) { c::f; }
+  friend g operator^=(g i, g j) { i ^ j; }
+};
+template <typename, int> using k = g;
+template <typename l> using m = k<l, sizeof(l)>;
+void n() {
+  void o();
+  m<char> p = o ^= p;
+}

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kito-cheng kito-cheng merged commit 55f86cf into llvm:main Mar 7, 2025
15 checks passed
@kito-cheng kito-cheng deleted the fix-pr129995 branch March 7, 2025 03:31
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
RISCVABIInfo::detectVLSCCEligibleStruct should early exit if VLS calling
convention is not used, however the sentinel value was not set to
correctly, it should be zero instead of one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:RISC-V clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants