From: Craig Topper Date: Thu, 21 Jul 2016 07:38:43 +0000 (+0000) Subject: [Sema,X86] Add explicit check to ensure that builtins that require x86-64 target... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fe22d59a8424dd63184fa834f5915f9fdf2ec4ec;p=platform%2Fupstream%2Fllvm.git [Sema,X86] Add explicit check to ensure that builtins that require x86-64 target throw an error if used on 32-bit target. If these builtins are allowed to go through on a 32-bit target they will fire assertions in the backend. Fixes PR28635. llvm-svn: 276250 --- diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 6a4f65a..8ae0cbe 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1597,6 +1597,56 @@ bool Sema::CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { return SemaBuiltinCpuSupports(*this, TheCall); case X86::BI__builtin_ms_va_start: return SemaBuiltinMSVAStart(TheCall); + case X86::BI__builtin_ia32_addcarryx_u64: + case X86::BI__builtin_ia32_addcarry_u64: + case X86::BI__builtin_ia32_subborrow_u64: + case X86::BI__builtin_ia32_readeflags_u64: + case X86::BI__builtin_ia32_writeeflags_u64: + case X86::BI__builtin_ia32_bextr_u64: + case X86::BI__builtin_ia32_bextri_u64: + case X86::BI__builtin_ia32_bzhi_di: + case X86::BI__builtin_ia32_pdep_di: + case X86::BI__builtin_ia32_pext_di: + case X86::BI__builtin_ia32_crc32di: + case X86::BI__builtin_ia32_fxsave64: + case X86::BI__builtin_ia32_fxrstor64: + case X86::BI__builtin_ia32_xsave64: + case X86::BI__builtin_ia32_xrstor64: + case X86::BI__builtin_ia32_xsaveopt64: + case X86::BI__builtin_ia32_xrstors64: + case X86::BI__builtin_ia32_xsavec64: + case X86::BI__builtin_ia32_xsaves64: + case X86::BI__builtin_ia32_rdfsbase64: + case X86::BI__builtin_ia32_rdgsbase64: + case X86::BI__builtin_ia32_wrfsbase64: + case X86::BI__builtin_ia32_wrgsbase64: + case X86::BI__builtin_ia32_pbroadcastb512_gpr_mask: + case X86::BI__builtin_ia32_pbroadcastb256_gpr_mask: + case X86::BI__builtin_ia32_pbroadcastb128_gpr_mask: + case X86::BI__builtin_ia32_vcvtsd2si64: + case X86::BI__builtin_ia32_vcvtsd2usi64: + case X86::BI__builtin_ia32_vcvtss2si64: + case X86::BI__builtin_ia32_vcvtss2usi64: + case X86::BI__builtin_ia32_vcvttsd2si64: + case X86::BI__builtin_ia32_vcvttsd2usi64: + case X86::BI__builtin_ia32_vcvttss2si64: + case X86::BI__builtin_ia32_vcvttss2usi64: + case X86::BI__builtin_ia32_cvtss2si64: + case X86::BI__builtin_ia32_cvttss2si64: + case X86::BI__builtin_ia32_cvtsd2si64: + case X86::BI__builtin_ia32_cvttsd2si64: + case X86::BI__builtin_ia32_cvtsi2sd64: + case X86::BI__builtin_ia32_cvtsi2ss64: + case X86::BI__builtin_ia32_cvtusi2sd64: + case X86::BI__builtin_ia32_cvtusi2ss64: + case X86::BI__builtin_ia32_rdseed64_step: { + // These builtins only work on x86-64 targets. + const llvm::Triple &TT = Context.getTargetInfo().getTriple(); + if (TT.getArch() != llvm::Triple::x86_64) + return Diag(TheCall->getCallee()->getLocStart(), + diag::err_x86_builtin_32_bit_tgt); + return false; + } case X86::BI__builtin_ia32_extractf64x4_mask: case X86::BI__builtin_ia32_extracti64x4_mask: case X86::BI__builtin_ia32_extractf32x8_mask: diff --git a/clang/test/CodeGen/builtins-x86-disabled.c b/clang/test/CodeGen/builtins-x86-disabled.c new file mode 100644 index 0000000..a024336 --- /dev/null +++ b/clang/test/CodeGen/builtins-x86-disabled.c @@ -0,0 +1,22 @@ +// REQUIRES: x86-registered-target +// RUN: not %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - 2>&1 | FileCheck %s + +void call_x86_64_builtins(void) +{ + unsigned long long a = __builtin_ia32_crc32di(0, 0); + unsigned long long b; + unsigned int c = __builtin_ia32_rdseed64_step (&b); + unsigned long long d = __builtin_ia32_bextr_u64 (0, 0); + unsigned long long e = __builtin_ia32_pdep_di(0, 0); + unsigned long long f = __builtin_ia32_pext_di(0, 0); + unsigned long long g = __builtin_ia32_bzhi_di(0, 0); + unsigned long long h; + unsigned long long i = __builtin_ia32_addcarryx_u64(0, 0, 0, &h); + unsigned long long j; + unsigned long long k = __builtin_ia32_addcarry_u64(0, 0, 0, &j); + unsigned long long l; + unsigned long long m = __builtin_ia32_subborrow_u64(0, 0, 0, &l); +} + +// CHECK: error: this builtin is only available on x86-64 targets +// CHECK: __builtin_ia32_crc32di