thegameg created this revision. thegameg added reviewers: craig.topper, majnemer. thegameg added a subscriber: cfe-commits.
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. https://reviews.llvm.org/D27304 Files: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaChecking.cpp Index: lib/Sema/SemaChecking.cpp =================================================================== --- lib/Sema/SemaChecking.cpp +++ lib/Sema/SemaChecking.cpp @@ -2474,6 +2474,17 @@ CheckArgumentWithTypeTag(I, Args.data()); } } + + // Don't allow calls returning floating point scalars when + // target == x86_64 && SSE disabled. + if (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86_64 && + (!Context.getTargetInfo().hasFeature("sse") || + !Context.getTargetInfo().hasFeature("sse2"))) { + if (auto *ResultType = Proto->getReturnType().getTypePtrOrNull()) { + if (ResultType->isRealFloatingType()) + Diag(Loc, diag::err_x86_sse_register); + } + } } /// CheckConstructorCall - Check a constructor call for correctness and safety Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -7840,6 +7840,8 @@ "this builtin is only available on x86-64 targets">; def err_x86_builtin_invalid_rounding : Error< "invalid rounding argument">; +def err_x86_sse_register : Error< + "SSE register return with SSE disabled">; def err_builtin_longjmp_unsupported : Error< "__builtin_longjmp is not supported for the current target">;
Index: lib/Sema/SemaChecking.cpp =================================================================== --- lib/Sema/SemaChecking.cpp +++ lib/Sema/SemaChecking.cpp @@ -2474,6 +2474,17 @@ CheckArgumentWithTypeTag(I, Args.data()); } } + + // Don't allow calls returning floating point scalars when + // target == x86_64 && SSE disabled. + if (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86_64 && + (!Context.getTargetInfo().hasFeature("sse") || + !Context.getTargetInfo().hasFeature("sse2"))) { + if (auto *ResultType = Proto->getReturnType().getTypePtrOrNull()) { + if (ResultType->isRealFloatingType()) + Diag(Loc, diag::err_x86_sse_register); + } + } } /// CheckConstructorCall - Check a constructor call for correctness and safety Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -7840,6 +7840,8 @@ "this builtin is only available on x86-64 targets">; def err_x86_builtin_invalid_rounding : Error< "invalid rounding argument">; +def err_x86_sse_register : Error< + "SSE register return with SSE disabled">; def err_builtin_longjmp_unsupported : Error< "__builtin_longjmp is not supported for the current target">;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits