From: Craig Topper Date: Fri, 23 Sep 2016 04:48:27 +0000 (+0000) Subject: [X86] Split up the single switch statement in Sema::CheckX86BuiltinFunctionCall into... X-Git-Tag: llvmorg-4.0.0-rc1~9090 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f0ddc898f113b7ed14d8e92a112905574f89775f;p=platform%2Fupstream%2Fllvm.git [X86] Split up the single switch statement in Sema::CheckX86BuiltinFunctionCall into different switches or ifs for each type of check. This in preparation for a new check that will check some of the builtins that already had the immediate range check. llvm-svn: 282227 --- diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 119fe8c..437c779 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1590,15 +1590,9 @@ static bool SemaBuiltinCpuSupports(Sema &S, CallExpr *TheCall) { return false; } -bool Sema::CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { - int i = 0, l = 0, u = 0; +static bool isX86_64Builtin(unsigned BuiltinID) { + // These builtins only work on x86-64 targets. switch (BuiltinID) { - default: - return false; - case X86::BI__builtin_cpu_supports: - 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: @@ -1641,14 +1635,32 @@ bool Sema::CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { 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_rdseed64_step: + 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_ms_va_start) + return SemaBuiltinMSVAStart(TheCall); + + // Check for 64-bit only builtins on a 32-bit target. + const llvm::Triple &TT = Context.getTargetInfo().getTriple(); + if (TT.getArch() != llvm::Triple::x86_64 && isX86_64Builtin(BuiltinID)) + return Diag(TheCall->getCallee()->getLocStart(), + diag::err_x86_builtin_32_bit_tgt); + + // For intrinsics which take an immediate value as part of the instruction, + // range check them here. + int i = 0, l = 0, u = 0; + switch (BuiltinID) { + default: + return false; case X86::BI__builtin_ia32_extractf64x4_mask: case X86::BI__builtin_ia32_extracti64x4_mask: case X86::BI__builtin_ia32_extractf32x8_mask: