This is an archive of the discontinued LLVM Phabricator instance.

[ARM][Driver] Warn if -mhard-float is incompatible
ClosedPublic

Authored by michaelplatings on May 18 2023, 12:48 PM.

Details

Summary

Mixing -mfloat-abi=hard with a CPU that doesn't have floating point
registers is an error in GCC:

cc1: error: '-mfloat-abi=hard': selected processor lacks an FPU

Since there is code in the wild (including in clang tests) that relies
on Clang's current behaviour, emit a warning instead of an error.

Unlike the GCC error, the new warning refers to floating point
registers instead of an FPU. This is because -mfloat-abi=hard and
-march=armv8.1-m.main+mve+nofp are compatible - in that case floating
point registers are required, but an FPU is not required.

My initial thought was to use the floating point ABI calculated by
arm::getARMFloatABI() but in invalid cases which error for other
reasons the ABI is miscalculated and the warning would cause confusion.
Therefore only warn if the user specifies the float ABI explicitly.

Fixes part of https://github.com/llvm/llvm-project/issues/55755

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2023, 12:48 PM
michaelplatings requested review of this revision.May 18 2023, 12:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2023, 12:48 PM

Tweak tests to use -### to run faster.

simon_tatham added inline comments.
clang/lib/Driver/ToolChains/Arch/ARM.cpp
151

This whole patch hinges on the unspoken assumption that this is a correct way to test for the absence of FP registers, i.e. that "-fpregs" will always appear in Features if there are no FP registers.

Could you add a comment stating that assumption explicitly and explaining why it's valid? In particular, why you're confident that the absence of FP registers might not sometimes be signalled by the lack of either "-fpregs" or "+fpregs" in that list.

(In a quick look at the code I think you're right, but I'm not 100% confident, and if you show your working then people will be able to work out what went wrong later if things change.)

Add variable specifically for the purpose of specifying whether or not FP regs are available.

michaelplatings marked an inline comment as done.Jun 5 2023, 8:42 AM
michaelplatings added inline comments.
clang/lib/Driver/ToolChains/Arch/ARM.cpp
151

That code was relying on implementation details of the function that called it. I've now changed checkARMFloatABI to require that the caller specifies whether or not FP regs are available, and made that calculation clear in the calling function.

michaelplatings marked an inline comment as done.

Restore tweak to tests to use -### to run faster.

simon_tatham accepted this revision.Jun 5 2023, 8:53 AM

Thanks, that's much clearer. LGTM.

This revision is now accepted and ready to land.Jun 5 2023, 8:53 AM
This revision was landed with ongoing or failed builds.Jun 6 2023, 1:09 AM
This revision was automatically updated to reflect the committed changes.
TWeaver added a subscriber: TWeaver.Jun 6 2023, 2:38 AM

Good morning from the UK!

I believe this change has caused the following buildbot to start failing:

https://lab.llvm.org/buildbot/#/builders/139/builds/42214

Is anyone able to take a look?

Much obliged,
Tom W

Thanks Tom, I'll work on it now.

Thanks for the speedy reply and action!

Relanded with the warning in the "OptionIgnored" group which fixes the test failure.

MaskRay added inline comments.Jun 6 2023, 8:56 AM
clang/test/Driver/arm-no-float-regs.c
23

For future changes like this, consider preferring NOWARN-NOT: warning: so that the test is slightly stricter (also assert that no other warning is emitted).

I suspect that // REQUIRES: arm-registered-target is unneeded (test a build that removes ARM from LLVM_TARGETS_TO_BUILD) since you use -### for all clang invocations.