[clang] [clang][CodeGen][AVR] Fix a crash in AVRABIInfo (PR #131976)
Ben Shi via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 20 21:56:39 PDT 2025
https://github.com/benshi001 updated https://github.com/llvm/llvm-project/pull/131976
>From 163c73d21af736c94f1bb8f8c63caf96e127aba5 Mon Sep 17 00:00:00 2001
From: Ben Shi <bennshi at tencent.com>
Date: Wed, 19 Mar 2025 13:21:48 +0800
Subject: [PATCH 1/3] [clang][CodeGen][AVR] Fix a crash in AVRABIInfo
fixes https://github.com/llvm/llvm-project/issues/131967
---
clang/lib/CodeGen/Targets/AVR.cpp | 7 ++++---
clang/test/CodeGen/avr/argument.c | 10 ++++++++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/clang/lib/CodeGen/Targets/AVR.cpp b/clang/lib/CodeGen/Targets/AVR.cpp
index 26e2a22f14d1e..d0def86376f89 100644
--- a/clang/lib/CodeGen/Targets/AVR.cpp
+++ b/clang/lib/CodeGen/Targets/AVR.cpp
@@ -59,7 +59,7 @@ class AVRABIInfo : public DefaultABIInfo {
unsigned TySize = getContext().getTypeSize(Ty);
// An int8 type argument always costs two registers like an int16.
- if (TySize == 8 && NumRegs >= 2) {
+ if (TySize == 8 && NumRegs >= 2 && Ty->isIntegralOrEnumerationType()) {
NumRegs -= 2;
return ABIArgInfo::getExtend(Ty);
}
@@ -135,7 +135,8 @@ class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
if (GV->isDeclaration())
return;
const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
- if (!FD) return;
+ if (!FD)
+ return;
auto *Fn = cast<llvm::Function>(GV);
if (FD->getAttr<AVRInterruptAttr>())
@@ -145,7 +146,7 @@ class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
Fn->addFnAttr("signal");
}
};
-}
+} // namespace
std::unique_ptr<TargetCodeGenInfo>
CodeGen::createAVRTargetCodeGenInfo(CodeGenModule &CGM, unsigned NPR,
diff --git a/clang/test/CodeGen/avr/argument.c b/clang/test/CodeGen/avr/argument.c
index 31bf678c05a54..5f4b300f350ae 100644
--- a/clang/test/CodeGen/avr/argument.c
+++ b/clang/test/CodeGen/avr/argument.c
@@ -114,3 +114,13 @@ struct s15 fooa(char a, char b) {
x.arr[1] = b;
return x;
}
+
+struct s8_t {
+ char a;
+};
+
+// AVR-NOT: {{.*}} signext
+// TINY-NOT: {{.*}} signext
+char foob(struct s8_t a) {
+ return a.a + 1;
+}
>From db000cf7c012ebe8d7fb30e47089b61b7ad9c045 Mon Sep 17 00:00:00 2001
From: Ben Shi <bennshi at tencent.com>
Date: Thu, 20 Mar 2025 09:02:21 +0800
Subject: [PATCH 2/3] [clang][CodeGen][AVR] Fix a crash in AVRABIInfo
fixes https://github.com/llvm/llvm-project/issues/131967
---
clang/lib/CodeGen/Targets/AVR.cpp | 5 ++---
clang/test/CodeGen/avr/argument.c | 4 ++--
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/clang/lib/CodeGen/Targets/AVR.cpp b/clang/lib/CodeGen/Targets/AVR.cpp
index d0def86376f89..5399d12f7ce80 100644
--- a/clang/lib/CodeGen/Targets/AVR.cpp
+++ b/clang/lib/CodeGen/Targets/AVR.cpp
@@ -135,8 +135,7 @@ class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
if (GV->isDeclaration())
return;
const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
- if (!FD)
- return;
+ if (!FD) return;
auto *Fn = cast<llvm::Function>(GV);
if (FD->getAttr<AVRInterruptAttr>())
@@ -146,7 +145,7 @@ class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
Fn->addFnAttr("signal");
}
};
-} // namespace
+}
std::unique_ptr<TargetCodeGenInfo>
CodeGen::createAVRTargetCodeGenInfo(CodeGenModule &CGM, unsigned NPR,
diff --git a/clang/test/CodeGen/avr/argument.c b/clang/test/CodeGen/avr/argument.c
index 5f4b300f350ae..a7682f4ed6299 100644
--- a/clang/test/CodeGen/avr/argument.c
+++ b/clang/test/CodeGen/avr/argument.c
@@ -119,8 +119,8 @@ struct s8_t {
char a;
};
-// AVR-NOT: {{.*}} signext
-// TINY-NOT: {{.*}} signext
+// AVR: define {{.*}} i8 @foob(i8 {{.*}})
+// TINY define {{.*}} i8 @foob(i8 {{.*}})
char foob(struct s8_t a) {
return a.a + 1;
}
>From 3864ab2200c5cf8107c9fe29c3d4092d90b80c30 Mon Sep 17 00:00:00 2001
From: Ben Shi <bennshi at tencent.com>
Date: Fri, 21 Mar 2025 12:56:11 +0800
Subject: [PATCH 3/3] fix test
---
clang/test/CodeGen/avr/argument.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/CodeGen/avr/argument.c b/clang/test/CodeGen/avr/argument.c
index a7682f4ed6299..1776cd7cf2c01 100644
--- a/clang/test/CodeGen/avr/argument.c
+++ b/clang/test/CodeGen/avr/argument.c
@@ -120,7 +120,7 @@ struct s8_t {
};
// AVR: define {{.*}} i8 @foob(i8 {{.*}})
-// TINY define {{.*}} i8 @foob(i8 {{.*}})
+// TINY: define {{.*}} i8 @foob(i8 {{.*}})
char foob(struct s8_t a) {
return a.a + 1;
}
More information about the cfe-commits
mailing list