This is an archive of the discontinued LLVM Phabricator instance.

[clang][X86] Update excessive register save diagnostic to more closely follow the interrupt attribute spec
ClosedPublic

Authored by antangelo on Aug 28 2023, 11:51 PM.

Details

Summary

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)

Diff Detail

Event Timeline

antangelo created this revision.Aug 28 2023, 11:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 28 2023, 11:51 PM
antangelo requested review of this revision.Aug 28 2023, 11:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 28 2023, 11:51 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman edited reviewers, added: pengfei; removed: mibintc.Aug 29 2023, 5:46 AM

Changing the reviewers up a bit; the changes generally seem reasonable to me, but I'd appreciate some x86 reviewer viewpoints.

clang/include/clang/Basic/DiagnosticSemaKinds.td
317

Can you add a test case showing that -mgeneral-regs-only causes the diagnostic to be silenced?

pengfei added inline comments.Aug 29 2023, 6:42 AM
clang/include/clang/Basic/DiagnosticSemaKinds.td
317

It's a driver only option. I think we are not suggested to invoke %clang out of driver testsing, right?

aaron.ballman added inline comments.Aug 29 2023, 6:46 AM
clang/include/clang/Basic/DiagnosticSemaKinds.td
317

Oh! I hadn't realized this was a driver-only option. Looking at it harder, I see that for x86, setting the driver option removes the x87, mmx, and sse features which we do have test coverage for. Thanks @pengfei for pointing that out, my request was already covered!

pengfei accepted this revision.Aug 29 2023, 6:56 AM

I don't have prior experience about interrupt diagnostic but know something about mgeneral-regs-only. I think the diagnostic great.

This revision is now accepted and ready to land.Aug 29 2023, 6:56 AM

Thank you for the quick reviews! I don't have currently have commit access to commit the changes myself, is it possible for someone to commit on my behalf? My name and email are:

Name: Antonio Abbatangelo
Email: contact@antangelo.com