[PATCH] D46132: [X86] Make __builtin_ia32_readeflags_u32 and __builtin_ia32_writeeflags_u32 only available on 32-bit targets.
Craig Topper via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 26 09:45:44 PDT 2018
craig.topper created this revision.
craig.topper added reviewers: rnk, echristo, chandlerc.
These builtins can't be handled by the backend on 64-bit targets. So error up front instead of throwing an isel error.
Fixes PR37225
Repository:
rC Clang
https://reviews.llvm.org/D46132
Files:
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaChecking.cpp
test/Sema/builtins-x86.c
Index: test/Sema/builtins-x86.c
===================================================================
--- test/Sema/builtins-x86.c
+++ test/Sema/builtins-x86.c
@@ -16,6 +16,11 @@
typedef unsigned short __mmask16;
typedef unsigned int __mmask32;
+void call_x86_32_builtins(void) {
+ (void)__builtin_ia32_readeflags_u32(); // expected-error{{this builtin is only available on 32-bit targets}}
+ (void)__builtin_ia32_writeeflags_u32(4); // expected-error{{this builtin is only available on 32-bit targets}}
+}
+
__m128 test__builtin_ia32_cmpps(__m128 __a, __m128 __b) {
__builtin_ia32_cmpps(__a, __b, 32); // expected-error {{argument should be a value from 0 to 31}}
}
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -2309,13 +2309,30 @@
<< Arg->getSourceRange();
}
+static bool isX86_32Builtin(unsigned BuiltinID) {
+ // These builtins only work on x86-32 targets.
+ switch (BuiltinID) {
+ case X86::BI__builtin_ia32_readeflags_u32:
+ case X86::BI__builtin_ia32_writeeflags_u32:
+ return true;
+ }
+
+ return false;
+}
+
bool Sema::CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
if (BuiltinID == X86::BI__builtin_cpu_supports)
return SemaBuiltinCpuSupports(*this, TheCall);
if (BuiltinID == X86::BI__builtin_cpu_is)
return SemaBuiltinCpuIs(*this, TheCall);
+ // Check for 32-bit only builtins on a 64-bit target.
+ const llvm::Triple &TT = Context.getTargetInfo().getTriple();
+ if (TT.getArch() != llvm::Triple::x86 && isX86_32Builtin(BuiltinID))
+ return Diag(TheCall->getCallee()->getLocStart(),
+ diag::err_32_bit_builtin_64_bit_tgt);
+
// If the intrinsic has rounding or SAE make sure its valid.
if (CheckX86BuiltinRoundingOrSAE(BuiltinID, TheCall))
return true;
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -8251,6 +8251,8 @@
"invalid transaction abort code">;
def err_64_bit_builtin_32_bit_tgt : Error<
"this builtin is only available on 64-bit targets">;
+def err_32_bit_builtin_64_bit_tgt : Error<
+ "this builtin is only available on 32-bit targets">;
def err_builtin_x64_aarch64_only : Error<
"this builtin is only available on x86-64 and aarch64 targets">;
def err_ppc_builtin_only_on_pwr7 : Error<
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46132.144145.patch
Type: text/x-patch
Size: 2565 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180426/0851fe8c/attachment.bin>
More information about the cfe-commits
mailing list