-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
[clang][CodeGen][AVR] Fix a crash in AVRABIInfo #131976
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: Ben Shi (benshi001) Changesfixes #131967 Full diff: https://github.com/llvm/llvm-project/pull/131976.diff 2 Files Affected:
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;
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
fixes #131967