This is an archive of the discontinued LLVM Phabricator instance.

[PATCH] [Sema][X86] Don't allow floating-point return types when SSE is disabled
AbandonedPublic

Authored by thegameg on Dec 1 2016, 8:53 AM.

Details

Summary

The following program hits a fatal_error in the X86 backend, when the
program is compiled with -mno-sse or -mno-sse2, which is understandable
due to the calling convention:

float f() { return 0.5f; };

since the error occurs in the backend, there are stack traces and bug
report messages that are generated.

This patch allows the compiler to avoid crashing and check in advance if
the code can be generated properly.

  • include/clang/Basic/DiagnosticSemaKinds.td: Add the error.
  • lib/Sema/SemaChecking.cpp: Check if the function returns a floating-point type.

Diff Detail

Event Timeline

thegameg updated this revision to Diff 79914.Dec 1 2016, 8:53 AM
thegameg retitled this revision from to [PATCH] [Sema][X86] Don't allow floating-point return types when SSE is disabled.
thegameg updated this object.
thegameg added reviewers: craig.topper, majnemer.
thegameg added a subscriber: cfe-commits.
joerg added a subscriber: joerg.Dec 1 2016, 9:56 AM

I think this is the absolutely wrong place to put such logic. It really can not be anywhere but the backend.

I think this is the absolutely wrong place to put such logic. It really can not be anywhere but the backend.

I am aware of this. But the way the backend informs the Diagnostics looks like a crash, and asks for a bug report.

Are there any proper ways to inform the frontend about backend errors?

I think this is the absolutely wrong place to put such logic. It really can not be anywhere but the backend.

I am aware of this. But the way the backend informs the Diagnostics looks like a crash, and asks for a bug report.

Are there any proper ways to inform the frontend about backend errors?

Yes. Look at how we report inline asm errors, etc. grep for DiagnosticInfoStackSize (used in PEI) or DiagnosticInfoResourceLimit (used by the AMDGPU backend).

I think this is the absolutely wrong place to put such logic. It really can not be anywhere but the backend.

I am aware of this. But the way the backend informs the Diagnostics looks like a crash, and asks for a bug report.

Are there any proper ways to inform the frontend about backend errors?

Instead of checking the return type in SemaChecking.cpp, is defining a virtual function in TargetInfo and overriding it in X86TargetInfo an option?

The logic to compute whether a calling convention uses SSE registers does exist in clang/lib/CodeGen/TargetInfo.cpp, so it might be possible to reuse that... but I'm not sure that's better than just detecting it in the backend.

joerg added a comment.Dec 1 2016, 1:34 PM

The frontend is the wrong place as it doesn't even know if the register is ever going to be used. E.g. if it is a static function, all instances could be inlined away.

RKSimon added a subscriber: RKSimon.Dec 1 2016, 2:43 PM

https://llvm.org/bugs/show_bug.cgi?id=30426#c3

On PR30426 the proposal was that we should just not accept x86_64 triples with no-sse/no-sse2 at the command line parsing level - we just have no way to guess what the coder was expecting and performing the check later on is just delaying the (almost) inevitable.

Also, please remember to include context in the diff.

joerg added a comment.Dec 4 2016, 10:02 AM

Rejecting -mno-sse2 for x86_64 is even worse. Dynamic linkers e.g. in FreeBSD and NetBSD depend on that. They also don't contain floating point code, but that's a separate question. Similar constraints exist for the kernels.

mkuper edited edge metadata.Dec 5 2016, 11:34 AM

If there are real-life usecases, then GCC-compatible behavior is probably better than just rejecting it outright, so I'm retracting my comment from PR30426.

(I would probably have liked x86_64 with -mno-sse2 and no -msoft-float to be an error, but I would also like a pony, so...)

thegameg abandoned this revision.Dec 23 2016, 4:06 AM