-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][Sema] Emit warnings about incorrect AVR interrupt/signal handlers #125997
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
benshi001
commented
Feb 6, 2025
- interrupt/signal handlers can not have parameters
- interrupt/signal handlers must be 'void' type
…lers 1. interrupt/signal handlers can not have parameters 2. interrupt/signal handlers must be 'void' type
@llvm/pr-subscribers-backend-risc-v @llvm/pr-subscribers-clang Author: Ben Shi (benshi001) Changes
Full diff: https://github.com/llvm/llvm-project/pull/125997.diff 8 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 7b3b932c482baa2..3f732938d6b6b3a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -351,8 +351,8 @@ def warn_arm_interrupt_vfp_clobber : Warning<
def err_arm_interrupt_called : Error<
"interrupt service routine cannot be called directly">;
def warn_interrupt_attribute_invalid : Warning<
- "%select{MIPS|MSP430|RISC-V}0 'interrupt' attribute only applies to "
- "functions that have %select{no parameters|a 'void' return type}1">,
+ "%select{MIPS|MSP430|RISC-V|AVR}0 '%1' attribute only applies to "
+ "functions that have %select{no parameters|a 'void' return type}2">,
InGroup<IgnoredAttributes>;
def warn_riscv_repeated_interrupt_attribute : Warning<
"repeated RISC-V 'interrupt' attribute">, InGroup<IgnoredAttributes>;
diff --git a/clang/lib/Sema/SemaAVR.cpp b/clang/lib/Sema/SemaAVR.cpp
index 47368780b620379..ff79fc89f827d16 100644
--- a/clang/lib/Sema/SemaAVR.cpp
+++ b/clang/lib/Sema/SemaAVR.cpp
@@ -30,6 +30,18 @@ void SemaAVR::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
if (!AL.checkExactlyNumArgs(SemaRef, 0))
return;
+ // AVR interrupt handlers must have no parameter and be void type.
+ if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
+ Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+ << /*AVR*/ 3 << "interrupt" << 0;
+ return;
+ }
+ if (!getFunctionOrMethodResultType(D)->isVoidType()) {
+ Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+ << /*AVR*/ 3 << "interrupt" << 1;
+ return;
+ }
+
handleSimpleAttribute<AVRInterruptAttr>(*this, D, AL);
}
@@ -43,6 +55,18 @@ void SemaAVR::handleSignalAttr(Decl *D, const ParsedAttr &AL) {
if (!AL.checkExactlyNumArgs(SemaRef, 0))
return;
+ // AVR signal handlers must have no parameter and be void type.
+ if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
+ Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+ << /*AVR*/ 3 << "signal" << 0;
+ return;
+ }
+ if (!getFunctionOrMethodResultType(D)->isVoidType()) {
+ Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
+ << /*AVR*/ 3 << "signal" << 1;
+ return;
+ }
+
handleSimpleAttribute<AVRSignalAttr>(*this, D, AL);
}
diff --git a/clang/lib/Sema/SemaMIPS.cpp b/clang/lib/Sema/SemaMIPS.cpp
index 50d210e5b381405..2717c93e8c265c7 100644
--- a/clang/lib/Sema/SemaMIPS.cpp
+++ b/clang/lib/Sema/SemaMIPS.cpp
@@ -272,13 +272,13 @@ void SemaMIPS::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
- << /*MIPS*/ 0 << 0;
+ << /*MIPS*/ 0 << "interrupt" << 0;
return;
}
if (!getFunctionOrMethodResultType(D)->isVoidType()) {
Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
- << /*MIPS*/ 0 << 1;
+ << /*MIPS*/ 0 << "interrupt" << 1;
return;
}
diff --git a/clang/lib/Sema/SemaMSP430.cpp b/clang/lib/Sema/SemaMSP430.cpp
index 4038a1ff61d63ce..2b9e4769f06f0be 100644
--- a/clang/lib/Sema/SemaMSP430.cpp
+++ b/clang/lib/Sema/SemaMSP430.cpp
@@ -33,13 +33,13 @@ void SemaMSP430::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
- << /*MSP430*/ 1 << 0;
+ << /*MSP430*/ 1 << "interrupt" << 0;
return;
}
if (!getFunctionOrMethodResultType(D)->isVoidType()) {
Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
- << /*MSP430*/ 1 << 1;
+ << /*MSP430*/ 1 << "interrupt" << 1;
return;
}
diff --git a/clang/lib/Sema/SemaRISCV.cpp b/clang/lib/Sema/SemaRISCV.cpp
index 163f7129a7b42bb..51bca305f5690b3 100644
--- a/clang/lib/Sema/SemaRISCV.cpp
+++ b/clang/lib/Sema/SemaRISCV.cpp
@@ -1458,13 +1458,13 @@ void SemaRISCV::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
if (hasFunctionProto(D) && getFunctionOrMethodNumParams(D) != 0) {
Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
- << /*RISC-V*/ 2 << 0;
+ << /*RISC-V*/ 2 << "interrupt" << 0;
return;
}
if (!getFunctionOrMethodResultType(D)->isVoidType()) {
Diag(D->getLocation(), diag::warn_interrupt_attribute_invalid)
- << /*RISC-V*/ 2 << 1;
+ << /*RISC-V*/ 2 << "interrupt" << 1;
return;
}
diff --git a/clang/test/Sema/avr-interript-signal-attr.c b/clang/test/Sema/avr-interript-signal-attr.c
new file mode 100644
index 000000000000000..7360dbdedb695ca
--- /dev/null
+++ b/clang/test/Sema/avr-interript-signal-attr.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 %s -triple avr-unknown-unknown -verify -fsyntax-only
+struct a { int b; };
+
+struct a test __attribute__((interrupt)); // expected-warning {{'interrupt' attribute only applies to functions}}
+
+__attribute__((interrupt(12))) void foo(void) { } // expected-error {{'interrupt' attribute takes no arguments}}
+
+__attribute__((interrupt)) int fooa(void) { return 0; } // expected-warning {{'interrupt' attribute only applies to functions that have a 'void' return type}}
+
+__attribute__((interrupt)) void foob(int a) {} // expected-warning {{'interrupt' attribute only applies to functions that have no parameters}}
+
+__attribute__((signal)) int fooc(void) { return 0; } // expected-warning {{'signal' attribute only applies to functions that have a 'void' return type}}
+
+__attribute__((signal)) void food(int a) {} // expected-warning {{'signal' attribute only applies to functions that have no parameters}}
+
+__attribute__((interrupt)) void fooe(void) {}
+
+__attribute__((interrupt)) void foof() {}
+
+__attribute__((signal)) void foog(void) {}
+
+__attribute__((signal)) void fooh() {}
diff --git a/clang/test/Sema/avr-interrupt-attr.c b/clang/test/Sema/avr-interrupt-attr.c
deleted file mode 100644
index 7aee7babcbe16a8..000000000000000
--- a/clang/test/Sema/avr-interrupt-attr.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: %clang_cc1 %s -triple avr-unknown-unknown -verify -fsyntax-only
-struct a { int b; };
-
-struct a test __attribute__((interrupt)); // expected-warning {{'interrupt' attribute only applies to functions}}
-
-__attribute__((interrupt(12))) void foo(void) { } // expected-error {{'interrupt' attribute takes no arguments}}
-
-__attribute__((interrupt)) void food(void) {}
diff --git a/clang/test/Sema/avr-signal-attr.c b/clang/test/Sema/avr-signal-attr.c
deleted file mode 100644
index 1ec36c74a25ebbc..000000000000000
--- a/clang/test/Sema/avr-signal-attr.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: %clang_cc1 %s -triple avr-unknown-unknown -verify -fsyntax-only
-struct a { int b; };
-
-struct a test __attribute__((signal)); // expected-warning {{'signal' attribute only applies to functions}}
-
-__attribute__((signal(12))) void foo(void) { } // expected-error {{'signal' attribute takes no arguments}}
-
-__attribute__((signal)) void food(void) {}
|
jacquesguan
reviewed
Feb 6, 2025
Patryk27
approved these changes
Feb 6, 2025
jacquesguan
approved these changes
Feb 7, 2025
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
Icohedron
pushed a commit
to Icohedron/llvm-project
that referenced
this pull request
Feb 11, 2025
…lers (llvm#125997) 1. interrupt/signal handlers can not have parameters 2. interrupt/signal handlers must be 'void' type
joaosaffran
pushed a commit
to joaosaffran/llvm-project
that referenced
this pull request
Feb 14, 2025
…lers (llvm#125997) 1. interrupt/signal handlers can not have parameters 2. interrupt/signal handlers must be 'void' type
sivan-shani
pushed a commit
to sivan-shani/llvm-project
that referenced
this pull request
Feb 24, 2025
…lers (llvm#125997) 1. interrupt/signal handlers can not have parameters 2. interrupt/signal handlers must be 'void' type
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
backend:RISC-V
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.