Skip to content
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

Merged
merged 3 commits into from
Mar 22, 2025
Merged

Conversation

benshi001
Copy link
Member

fixes #131967

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. labels Mar 19, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 19, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Ben Shi (benshi001)

Changes

fixes #131967


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

2 Files Affected:

  • (modified) clang/lib/CodeGen/Targets/AVR.cpp (+4-3)
  • (modified) clang/test/CodeGen/avr/argument.c (+10)
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;
+}

@benshi001 benshi001 requested a review from efriedma-quic March 20, 2025 00:36
Copy link
Contributor

@jacquesguan jacquesguan left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@efriedma-quic efriedma-quic left a comment

Choose a reason for hiding this comment

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

LGTM

@benshi001 benshi001 merged commit 597accf into llvm:main Mar 22, 2025
11 checks passed
@benshi001 benshi001 deleted the avr-fix branch March 22, 2025 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

[AVR] clang crashed with simple cpp code
5 participants