Skip to content

[clang][ARM] Add a warning for calling an __attribute__((interrupt)) function #95359

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

Closed
chrisnc opened this issue Jun 13, 2024 · 0 comments · Fixed by #91870
Closed

[clang][ARM] Add a warning for calling an __attribute__((interrupt)) function #95359

chrisnc opened this issue Jun 13, 2024 · 0 comments · Fixed by #91870
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@chrisnc
Copy link
Contributor

chrisnc commented Jun 13, 2024

#91870 fixes a warning that's existed for a while for bare-metal Arm targets which encourages calling interrupt handlers from other interrupt handlers. Doing this leads to unpredictable behavior and/or infinite loops due to how Arm exception returns are defined: #91870 (comment). clang should instead warn when you try to call an interrupt handler from anywhere.

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Jun 13, 2024
@chrisnc chrisnc changed the title [ARM][clang] Add a warning for calling an __attribute__((interrupt)) function [ARM][clang] Add a warning for calling an __attribute__((interrupt)) function Jun 13, 2024
@chrisnc chrisnc changed the title [ARM][clang] Add a warning for calling an __attribute__((interrupt)) function [clang][ARM] Add a warning for calling an __attribute__((interrupt)) function Jun 13, 2024
@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed clang Clang issues not falling into any other category labels Jun 13, 2024
chrisnc added a commit to chrisnc/llvm-project that referenced this issue Jun 14, 2024
chrisnc added a commit to chrisnc/llvm-project that referenced this issue Jun 23, 2024
chrisnc added a commit to chrisnc/llvm-project that referenced this issue Jun 28, 2024
chrisnc added a commit to chrisnc/llvm-project that referenced this issue Jul 2, 2024
chrisnc added a commit to chrisnc/llvm-project that referenced this issue Jul 9, 2024
chrisnc added a commit to chrisnc/llvm-project that referenced this issue Jul 10, 2024
chrisnc added a commit to chrisnc/llvm-project that referenced this issue Jul 10, 2024
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this issue Jul 14, 2024
[clang][ARM] Fix warning for using VFP from interrupts.

This warning has three issues:
- The interrupt attribute causes the function to return using an
exception
   return instruction. This warning allows calls from one function with
   the interrupt attribute to another, and the diagnostic text suggests
   that not having the attribute on the callee is a problem. Actually
   making such a call will lead to a double exception return, which is
   unpredictable according to the ARM architecture manual section
   B9.1.1, "Restrictions on exception return instructions". Even on
   machines where an exception return from user/system mode is
   tolerated, if the callee's interrupt type is anything other than a
   supervisor call or secure monitor call, it will also return to a
   different address than a normal function would. For example,
   returning from an "IRQ" handler will return to lr - 4, which will
   generally result in calling the same function again.
 - The interrupt attribute currently does not cause caller-saved VFP
   registers to be saved and restored if they are used, so putting
   __attribute__((interrupt)) on a called function doesn't prevent it
   from clobbering VFP state.
 - It is part of the -Wextra diagnostic group and can't be individually
   disabled when using -Wextra, which also means the diagnostic text of
   this specific warning appears in the documentation of -Wextra.

This change addresses all three issues by instead generating a warning
for any interrupt handler where the vfp feature is enabled. The warning
is
also given its own diagnostic group.

Closes llvm#34876.

[clang][ARM] Emit an error when an interrupt handler is called.

Closes llvm#95359.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants