[clang] [clang][CodeGen][AVR] Fix a crash in AVRABIInfo (PR #131976)
Ben Shi via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 18 22:58:21 PDT 2025
https://github.com/benshi001 created https://github.com/llvm/llvm-project/pull/131976
fixes https://github.com/llvm/llvm-project/issues/131967
>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] [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;
+}
More information about the cfe-commits
mailing list