]> granicus.if.org Git - clang/commitdiff
[x86] Add range checking to the constant argument of cmpps/pd/ss/sd builtinas.
authorCraig Topper <craig.topper@gmail.com>
Sat, 27 Dec 2014 07:00:08 +0000 (07:00 +0000)
committerCraig Topper <craig.topper@gmail.com>
Sat, 27 Dec 2014 07:00:08 +0000 (07:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224880 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/Sema/builtins-x86.c [new file with mode: 0644]

index 55de70826bcf118ba116b04994108ee4798b93a9..f4e33c6cb09b010a4c91a569bdea214edeede00e 100644 (file)
@@ -836,12 +836,16 @@ bool Sema::CheckMipsBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
 }
 
 bool Sema::CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
+  unsigned i = 0, l = 0, u = 0;
   switch (BuiltinID) {
-  case X86::BI_mm_prefetch:
-    // This is declared to take (const char*, int)
-    return SemaBuiltinConstantArgRange(TheCall, 1, 0, 3);
+  default: return false;
+  case X86::BI_mm_prefetch: i = 1; l = 0; u = 3; break;
+  case X86::BI__builtin_ia32_cmpps:
+  case X86::BI__builtin_ia32_cmpss:
+  case X86::BI__builtin_ia32_cmppd:
+  case X86::BI__builtin_ia32_cmpsd: i = 2; l = 0; u = 31; break;
   }
-  return false;
+  return SemaBuiltinConstantArgRange(TheCall, i, l, u);
 }
 
 /// Given a FunctionDecl's FormatAttr, attempts to populate the FomatStringInfo
diff --git a/test/Sema/builtins-x86.c b/test/Sema/builtins-x86.c
new file mode 100644 (file)
index 0000000..9929e61
--- /dev/null
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsyntax-only -verify %s
+
+typedef float __m128 __attribute__((__vector_size__(16)));
+typedef double __m128d __attribute__((__vector_size__(16)));
+
+__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}}
+}
+
+__m128d test__builtin_ia32_cmppd(__m128d __a, __m128d __b) {
+  __builtin_ia32_cmppd(__a, __b, 32); // expected-error {{argument should be a value from 0 to 31}}
+}
+
+__m128 test__builtin_ia32_cmpss(__m128 __a, __m128 __b) {
+  __builtin_ia32_cmpss(__a, __b, 32); // expected-error {{argument should be a value from 0 to 31}}
+}
+
+__m128d test__builtin_ia32_cmpsd(__m128d __a, __m128d __b) {
+  __builtin_ia32_cmpsd(__a, __b, 32); // expected-error {{argument should be a value from 0 to 31}}
+}