[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-06-11 Thread Chris Copeland via cfe-commits

chrisnc wrote:

Ping @DavidSpickett @jthackray 

https://github.com/llvm/llvm-project/pull/91870
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-11 Thread Chris Copeland via cfe-commits

https://github.com/chrisnc created 
https://github.com/llvm/llvm-project/pull/91870

This warning has two issues:
 - The interrupt attribute doesn't only change how volatile registers
   are treated; it also 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 the 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.
 - 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 both issues. Rather than check that the callee has
the interrupt attribute, check that it uses the soft-float feature,
which will prevent use of VFP state. The warning is also given its own
diagnostic group.


>From 62052b274264c1c69be4bb1579a8627b63eaa380 Mon Sep 17 00:00:00 2001
From: Chris Copeland 
Date: Sat, 11 May 2024 00:15:50 -0700
Subject: [PATCH] [ARM][clang] Fix warning for VFP function calls from
 interrupts.

This warning has two issues:
 - The interrupt attribute doesn't only change how volatile registers
   are treated; it also 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 the 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.
 - 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 both issues. Rather than check that the callee has
the interrupt attribute, check that it uses the soft-float feature,
which will prevent use of VFP state. The warning is also given its own
diagnostic group.
---
 clang/docs/ReleaseNotes.rst   | 11 +++
 clang/include/clang/Basic/Attr.td |  7 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 ---
 clang/lib/Sema/SemaExpr.cpp   | 19 ++-
 clang/test/Sema/arm-interrupt-attr.c  |  6 +++---
 5 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7c5dcc59c7016..3f9f81bc2bfac 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -352,6 +352,10 @@ Modified Compiler Flags
   evaluating to ``true`` and an empty body such as ``while(1);``)
   are considered infinite, even when the ``-ffinite-loop`` flag is set.
 
+- Removed "arm interrupt calling convention" warning that was included in
+  ``-Wextra`` but did not have its own flag. Added
+  ``-Warm-interrupt-vfp-clobber`` that enables the modified warning.
+
 Removed Compiler Flags
 -
 
@@ -484,6 +488,13 @@ Improvements to Clang's diagnostics
}
  };
 
+- On ARM, Clang no longer suggests adding ``__attribute__((interrupt))`` to 
normal
+  functions that are called from interrupt handlers to prevent clobbering VFP
+  registers as part of ``-Wextra``. Following this suggestion leads to
+  unpredictable behavior. Instead, ``-Warm-interrupt-vfp-clobber`` can now be
+  used to detect calling functions that don't have VFP disabled with
+  ``__attribute((target("soft-float")))`` from an interrupt handler.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52552ba488560..04e3b8f949992 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3090,6 +3090,13 @@ def Target : Inhe

[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Chris Copeland (chrisnc)


Changes

This warning has two issues:
 - The interrupt attribute doesn't only change how volatile registers
   are treated; it also 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 the 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.
 - 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 both issues. Rather than check that the callee has
the interrupt attribute, check that it uses the soft-float feature,
which will prevent use of VFP state. The warning is also given its own
diagnostic group.


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


5 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+11) 
- (modified) clang/include/clang/Basic/Attr.td (+7) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4-3) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+10-9) 
- (modified) clang/test/Sema/arm-interrupt-attr.c (+3-3) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7c5dcc59c7016..3f9f81bc2bfac 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -352,6 +352,10 @@ Modified Compiler Flags
   evaluating to ``true`` and an empty body such as ``while(1);``)
   are considered infinite, even when the ``-ffinite-loop`` flag is set.
 
+- Removed "arm interrupt calling convention" warning that was included in
+  ``-Wextra`` but did not have its own flag. Added
+  ``-Warm-interrupt-vfp-clobber`` that enables the modified warning.
+
 Removed Compiler Flags
 -
 
@@ -484,6 +488,13 @@ Improvements to Clang's diagnostics
}
  };
 
+- On ARM, Clang no longer suggests adding ``__attribute__((interrupt))`` to 
normal
+  functions that are called from interrupt handlers to prevent clobbering VFP
+  registers as part of ``-Wextra``. Following this suggestion leads to
+  unpredictable behavior. Instead, ``-Warm-interrupt-vfp-clobber`` can now be
+  used to detect calling functions that don't have VFP disabled with
+  ``__attribute((target("soft-float")))`` from an interrupt handler.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52552ba488560..04e3b8f949992 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3090,6 +3090,13 @@ def Target : InheritableAttr {
   }
 }
 
+bool hasFeature(StringRef Feature) const {
+  StringRef Features = getFeaturesStr();
+  SmallVector AttrFeatures;
+  Features.split(AttrFeatures, ",");
+  return Features.contains(Feature);
+}
+
 bool isDefaultVersion() const { return getFeaturesStr() == "default"; }
   }];
 }
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d6863f90edb6e..1c5f5ffb03dc5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -336,9 +336,10 @@ def warn_anyx86_excessive_regsave : Warning<
   " with attribute 'no_caller_saved_registers'"
   " or be compiled with '-mgeneral-regs-only'">,
   InGroup>;
-def warn_arm_interrupt_calling_convention : Warning<
-   "call to function without interrupt attribute could clobber interruptee's 
VFP registers">,
-   InGroup;
+def warn_arm_interrupt_vfp_clobber : Warning<
+   "calling a VFP-enabled function from an interrupt could clobber the "
+   "interruptee's VFP registers">,
+   InGroup>;
 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">,
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index c688cb21f2364..c514820bd899c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6942,22 +6942,23 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, 
NamedDecl *NDecl,
 return ExprError();
   }
 
-  

[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-11 Thread Chris Copeland via cfe-commits

chrisnc wrote:

Here is an example of the existing warning in action. 
https://godbolt.org/z/9e84EfeYP
It warns for calling a normal function, but the same function with an interrupt 
attribute does not warn. The `subs pc, lr, 4` in `bar_irq` goes back to `bl 
bar_irq`, creating an infinite loop, where the second `subs pc, lr, 4` from 
`bar_irq` is also unpredictable, because the processor mode will most likely be 
system/user.

https://github.com/llvm/llvm-project/pull/91870
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-11 Thread Chris Copeland via cfe-commits

https://github.com/chrisnc updated 
https://github.com/llvm/llvm-project/pull/91870

>From ef08eb6e2526c5d4f97dbcc42715ae5daf74de3d Mon Sep 17 00:00:00 2001
From: Chris Copeland 
Date: Sat, 11 May 2024 00:15:50 -0700
Subject: [PATCH] [ARM][clang] Fix warning for VFP function calls from
 interrupts.

This warning has two issues:
 - The interrupt attribute doesn't only change how volatile registers
   are treated; it also 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 the 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.
 - 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 both issues. Rather than check that the callee has
the interrupt attribute, check that it uses the soft-float feature,
which will prevent use of VFP state. The warning is also given its own
diagnostic group.
---
 clang/docs/ReleaseNotes.rst   | 11 +++
 clang/include/clang/Basic/Attr.td |  7 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 ---
 clang/lib/Sema/SemaExpr.cpp   | 19 ++-
 clang/test/Sema/arm-interrupt-attr.c  |  6 +++---
 5 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7c5dcc59c7016..ebf26c3ab4deb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -352,6 +352,10 @@ Modified Compiler Flags
   evaluating to ``true`` and an empty body such as ``while(1);``)
   are considered infinite, even when the ``-ffinite-loop`` flag is set.
 
+- Removed "arm interrupt calling convention" warning that was included in
+  ``-Wextra`` but did not have its own flag. Added
+  ``-Warm-interrupt-vfp-clobber`` that enables the modified warning.
+
 Removed Compiler Flags
 -
 
@@ -484,6 +488,13 @@ Improvements to Clang's diagnostics
}
  };
 
+- On ARM, Clang no longer suggests adding ``__attribute__((interrupt))`` to 
normal
+  functions that are called from interrupt handlers to prevent clobbering VFP
+  registers as part of ``-Wextra``. Following this suggestion leads to
+  unpredictable behavior. Instead, ``-Warm-interrupt-vfp-clobber`` can now be
+  used to detect calling functions that don't have VFP disabled with
+  ``__attribute__((target("soft-float")))`` from an interrupt handler.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52552ba488560..04e3b8f949992 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3090,6 +3090,13 @@ def Target : InheritableAttr {
   }
 }
 
+bool hasFeature(StringRef Feature) const {
+  StringRef Features = getFeaturesStr();
+  SmallVector AttrFeatures;
+  Features.split(AttrFeatures, ",");
+  return Features.contains(Feature);
+}
+
 bool isDefaultVersion() const { return getFeaturesStr() == "default"; }
   }];
 }
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d6863f90edb6e..1c5f5ffb03dc5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -336,9 +336,10 @@ def warn_anyx86_excessive_regsave : Warning<
   " with attribute 'no_caller_saved_registers'"
   " or be compiled with '-mgeneral-regs-only'">,
   InGroup>;
-def warn_arm_interrupt_calling_convention : Warning<
-   "call to function without interrupt attribute could clobber interruptee's 
VFP registers">,
-   InGroup;
+def warn_arm_interrupt_vfp_clobber : Warning<
+   "calling a VFP-enabled function from an interrupt could clobber the "
+   "interruptee's VFP registers">,
+   InGroup>;
 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">,
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index c688cb21f2364..c514820bd899c 10064

[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-12 Thread Chris Copeland via cfe-commits

https://github.com/chrisnc updated 
https://github.com/llvm/llvm-project/pull/91870

>From b72b63c51b1859e1a7e792eda20549ef93c8d6c0 Mon Sep 17 00:00:00 2001
From: Chris Copeland 
Date: Sat, 11 May 2024 00:15:50 -0700
Subject: [PATCH] [ARM][clang] Fix warning for VFP function calls from
 interrupts.

This warning has two issues:
 - The interrupt attribute doesn't only change how volatile registers
   are treated; it also 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 the 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.
 - 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 both issues. Rather than check that the callee has
the interrupt attribute, check that it uses the soft-float feature,
which will prevent use of VFP state. The warning is also given its own
diagnostic group.

Closes #34876.
---
 clang/docs/ReleaseNotes.rst   | 11 +++
 clang/include/clang/Basic/Attr.td |  7 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 ---
 clang/lib/Sema/SemaExpr.cpp   | 19 ++-
 clang/test/Sema/arm-interrupt-attr.c  |  6 +++---
 5 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7c5dcc59c7016..ebf26c3ab4deb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -352,6 +352,10 @@ Modified Compiler Flags
   evaluating to ``true`` and an empty body such as ``while(1);``)
   are considered infinite, even when the ``-ffinite-loop`` flag is set.
 
+- Removed "arm interrupt calling convention" warning that was included in
+  ``-Wextra`` but did not have its own flag. Added
+  ``-Warm-interrupt-vfp-clobber`` that enables the modified warning.
+
 Removed Compiler Flags
 -
 
@@ -484,6 +488,13 @@ Improvements to Clang's diagnostics
}
  };
 
+- On ARM, Clang no longer suggests adding ``__attribute__((interrupt))`` to 
normal
+  functions that are called from interrupt handlers to prevent clobbering VFP
+  registers as part of ``-Wextra``. Following this suggestion leads to
+  unpredictable behavior. Instead, ``-Warm-interrupt-vfp-clobber`` can now be
+  used to detect calling functions that don't have VFP disabled with
+  ``__attribute__((target("soft-float")))`` from an interrupt handler.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52552ba488560..04e3b8f949992 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3090,6 +3090,13 @@ def Target : InheritableAttr {
   }
 }
 
+bool hasFeature(StringRef Feature) const {
+  StringRef Features = getFeaturesStr();
+  SmallVector AttrFeatures;
+  Features.split(AttrFeatures, ",");
+  return Features.contains(Feature);
+}
+
 bool isDefaultVersion() const { return getFeaturesStr() == "default"; }
   }];
 }
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d6863f90edb6e..1c5f5ffb03dc5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -336,9 +336,10 @@ def warn_anyx86_excessive_regsave : Warning<
   " with attribute 'no_caller_saved_registers'"
   " or be compiled with '-mgeneral-regs-only'">,
   InGroup>;
-def warn_arm_interrupt_calling_convention : Warning<
-   "call to function without interrupt attribute could clobber interruptee's 
VFP registers">,
-   InGroup;
+def warn_arm_interrupt_vfp_clobber : Warning<
+   "calling a VFP-enabled function from an interrupt could clobber the "
+   "interruptee's VFP registers">,
+   InGroup>;
 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">,
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index c688cb21f2364..c51

[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-12 Thread Chris Copeland via cfe-commits

https://github.com/chrisnc edited 
https://github.com/llvm/llvm-project/pull/91870
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-12 Thread Chris Copeland via cfe-commits

chrisnc wrote:

I'd like to also address #47815, but I wasn't able to find the right path to 
answer "is this M-profile" from `TargetInfo`. Would appreciate any suggestions 
on that. I think it may require `dynamic_cast`-ing the `TargetInfo` to an 
`ARMTargetInfo`, and then change one of the methods in there to be public...

https://github.com/llvm/llvm-project/pull/91870
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-15 Thread Chris Copeland via cfe-commits

chrisnc wrote:

ping @ostannard @smithp35 

https://github.com/llvm/llvm-project/pull/91870
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-22 Thread Chris Copeland via cfe-commits

https://github.com/chrisnc updated 
https://github.com/llvm/llvm-project/pull/91870

>From b9aae83e94aab9ebed9b3dc3fe23bee4bd3c0756 Mon Sep 17 00:00:00 2001
From: Chris Copeland 
Date: Sat, 11 May 2024 00:15:50 -0700
Subject: [PATCH] [ARM][clang] Fix warning for VFP function calls from
 interrupts.

This warning has two issues:
 - The interrupt attribute doesn't only change how volatile registers
   are treated; it also 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 the 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.
 - 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 both issues. Rather than check that the callee has
the interrupt attribute, check that it uses the soft-float feature,
which will prevent use of VFP state. The warning is also given its own
diagnostic group.

Closes #34876.
---
 clang/docs/ReleaseNotes.rst   | 11 +++
 clang/include/clang/Basic/Attr.td |  7 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 ---
 clang/lib/Sema/SemaExpr.cpp   | 19 ++-
 clang/test/Sema/arm-interrupt-attr.c  | 14 +++---
 5 files changed, 39 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c4a343b70009..73bf7eb8c411a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -379,6 +379,10 @@ Modified Compiler Flags
   evaluating to ``true`` and an empty body such as ``while(1);``)
   are considered infinite, even when the ``-ffinite-loop`` flag is set.
 
+- Removed "arm interrupt calling convention" warning that was included in
+  ``-Wextra`` but did not have its own flag. Added
+  ``-Warm-interrupt-vfp-clobber`` that enables the modified warning.
+
 Removed Compiler Flags
 -
 
@@ -518,6 +522,13 @@ Improvements to Clang's diagnostics
 - Clang emits a ``-Wparentheses`` warning for expressions with consecutive 
comparisons like ``x < y < z``.
   Fixes #GH20456.
 
+- On ARM, Clang no longer suggests adding ``__attribute__((interrupt))`` to
+  normal functions that are called from interrupt handlers to prevent
+  clobbering VFP registers as part of ``-Wextra``. Following this suggestion
+  leads to unpredictable behavior. Instead, ``-Warm-interrupt-vfp-clobber`` can
+  now be used to detect calling functions that don't have VFP disabled with
+  ``__attribute__((target("soft-float")))`` from an interrupt handler.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index a2c8cc42195fd..d68d4a7d3c69c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3118,6 +3118,13 @@ def Target : InheritableAttr {
   }
 }
 
+bool hasFeature(StringRef Feature) const {
+  StringRef Features = getFeaturesStr();
+  SmallVector AttrFeatures;
+  Features.split(AttrFeatures, ",");
+  return Features.contains(Feature);
+}
+
 bool isDefaultVersion() const { return getFeaturesStr() == "default"; }
   }];
 }
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index cc402182687f3..5a3d361ffeb12 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -336,9 +336,10 @@ def warn_anyx86_excessive_regsave : Warning<
   " with attribute 'no_caller_saved_registers'"
   " or be compiled with '-mgeneral-regs-only'">,
   InGroup>;
-def warn_arm_interrupt_calling_convention : Warning<
-   "call to function without interrupt attribute could clobber interruptee's 
VFP registers">,
-   InGroup;
+def warn_arm_interrupt_vfp_clobber : Warning<
+   "calling a VFP-enabled function from an interrupt could clobber the "
+   "interruptee's VFP registers">,
+   InGroup>;
 def warn_interrupt_attribute_invalid : Warning<
"%select{MIPS|MSP430|RISC-V}0 'interrupt' attribute only applies to "
"functions that have %select{no parameters|a 'vo

[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-22 Thread Chris Copeland via cfe-commits

chrisnc wrote:

Rebased and fixed conflict in release notes.

https://github.com/llvm/llvm-project/pull/91870
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-29 Thread Chris Copeland via cfe-commits

https://github.com/chrisnc updated 
https://github.com/llvm/llvm-project/pull/91870

>From 846d22ff9d96c64c9b73f0270f49724b7ee1cb70 Mon Sep 17 00:00:00 2001
From: Chris Copeland 
Date: Sat, 11 May 2024 00:15:50 -0700
Subject: [PATCH] [ARM][clang] Fix warning for VFP function calls from
 interrupts.

This warning has two issues:
 - The interrupt attribute doesn't only change how volatile registers
   are treated; it also 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 the 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.
 - 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 both issues. Rather than check that the callee has
the interrupt attribute, check that it uses the soft-float feature,
which will prevent use of VFP state. The warning is also given its own
diagnostic group.

Closes #34876.
---
 clang/docs/ReleaseNotes.rst   | 12 
 clang/include/clang/Basic/Attr.td |  7 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 ---
 clang/lib/Sema/SemaExpr.cpp   | 19 ++-
 clang/test/Sema/arm-interrupt-attr.c  | 14 +++---
 5 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bd92818f0c09d..6b27f5af97039 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -384,6 +384,10 @@ Modified Compiler Flags
   evaluating to ``true`` and an empty body such as ``while(1);``)
   are considered infinite, even when the ``-ffinite-loop`` flag is set.
 
+- Removed "arm interrupt calling convention" warning that was included in
+  ``-Wextra`` but did not have its own flag. Added
+  ``-Warm-interrupt-vfp-clobber`` that enables the modified warning.
+
 Removed Compiler Flags
 -
 
@@ -544,6 +548,14 @@ Improvements to Clang's diagnostics
 - Clang no longer emits a "declared here" note for a builtin function that has 
no declaration in source.
   Fixes #GH93369.
 
+- On ARM, Clang no longer suggests adding ``__attribute__((interrupt))`` to
+  normal functions that are called from interrupt handlers to prevent
+  clobbering VFP registers as part of ``-Wextra`` (#GH34876). Following this
+  suggestion leads to unpredictable behavior. Instead,
+  ``-Warm-interrupt-vfp-clobber`` can now be used to detect calling functions
+  that don't have VFP disabled with ``__attribute__((target("soft-float")))``
+  from an interrupt handler.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index ef9df1e9d8b4a..6bb64e46c7c3e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3122,6 +3122,13 @@ def Target : InheritableAttr {
   }
 }
 
+bool hasFeature(StringRef Feature) const {
+  StringRef Features = getFeaturesStr();
+  SmallVector AttrFeatures;
+  Features.split(AttrFeatures, ",");
+  return Features.contains(Feature);
+}
+
 bool isDefaultVersion() const { return getFeaturesStr() == "default"; }
   }];
 }
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f15cba63624ea..bf98c431a2b17 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -336,9 +336,10 @@ def warn_anyx86_excessive_regsave : Warning<
   " with attribute 'no_caller_saved_registers'"
   " or be compiled with '-mgeneral-regs-only'">,
   InGroup>;
-def warn_arm_interrupt_calling_convention : Warning<
-   "call to function without interrupt attribute could clobber interruptee's 
VFP registers">,
-   InGroup;
+def warn_arm_interrupt_vfp_clobber : Warning<
+   "calling a VFP-enabled function from an interrupt could clobber the "
+   "interruptee's VFP registers">,
+   InGroup>;
 def warn_interrupt_attribute_invalid : Warning<
"%select{MIPS|MSP430|RISC-V}0 'interrupt' attribute only applies to "
"functions that have %select{no par

[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-05-29 Thread Chris Copeland via cfe-commits

chrisnc wrote:

ping (rebased and fixed another release notes conflict)

https://github.com/llvm/llvm-project/pull/91870
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)

2024-06-04 Thread Chris Copeland via cfe-commits

chrisnc wrote:

Ping

https://github.com/llvm/llvm-project/pull/91870
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits