[all-commits] [llvm/llvm-project] fa1dc0: [clang][X86] Update excessive register save diagno...

antangelo via All-commits all-commits at lists.llvm.org
Tue Aug 29 20:52:21 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: fa1dc06a1b3997f025b0d81539c31a74e6b6ec79
      https://github.com/llvm/llvm-project/commit/fa1dc06a1b3997f025b0d81539c31a74e6b6ec79
  Author: Antonio Abbatangelo <contact at antangelo.com>
  Date:   2023-08-30 (Wed, 30 Aug 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/AttrDocs.td
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/Sema/SemaExpr.cpp
    M clang/test/Sema/attr-x86-interrupt.c
    A clang/test/Sema/x86-diag-excessive-regsave.c

  Log Message:
  -----------
  [clang][X86] Update excessive register save diagnostic to more closely follow the interrupt attribute spec

The original diagnostic does not cover all cases according to my reading
of the spec.

For the interrupt attribute, the spec indicates that if the compiler
does not support saving SSE, MMX, or x87 then the function should
be compiled with '-mgeneral-regs-only' (GCC requires this).
Alternatively, calling functions with the `no_caller_saved_registers`
attribute will not clobber state and can be done without disabling
these features.

The warning as implemented in upstream only detects the latter case but
does not consider that disabling the above features also solves the issue
of these register saves being undesirable due to inefficiency.

For the no_caller_saved_registers attribute, the interrupt spec also
indicates that in the absence of saving SSE, MMX and x87 state, these
functions should be compiled with '-mgeneral-regs-only' (also required
by GCC). It does not make any statements about calling other functions
with the attribute, but by extension the result is the same as with the
interrupt attribute (in clang, at least).

This patch handles the remaining cases by adjusting the diagnostic to:

1. Not be shown if the function is compiled without the SSE, MMX or x87
   features enabled (i.e. with '-mgeneral-regs-only')
2. Also be shown for functions with the 'no_caller_saved_registers'
   attribute
3. In addition to advising that the function should only call functions
   with the `no_caller_saved_registers` attribute, the text also suggests
   compiling with `-mgeneral-regs-only` as an alternative.

The interrupt spec is available at https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=5ed3cc7b66af4758f7849ed6f65f4365be8223be
and was taken from the issue that resulted in this diagnostic being
added (#26787)

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D159068




More information about the All-commits mailing list