r282227 - [X86] Split up the single switch statement in Sema::CheckX86BuiltinFunctionCall into different switches or ifs for each type of check.

Craig Topper via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 22 21:48:28 PDT 2016


Author: ctopper
Date: Thu Sep 22 23:48:27 2016
New Revision: 282227

URL: http://llvm.org/viewvc/llvm-project?rev=282227&view=rev
Log:
[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.

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=282227&r1=282226&r2=282227&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Sep 22 23:48:27 2016
@@ -1590,15 +1590,9 @@ static bool SemaBuiltinCpuSupports(Sema
   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(u
   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:




More information about the cfe-commits mailing list