From: Craig Topper Date: Sat, 27 Dec 2014 07:00:08 +0000 (+0000) Subject: [x86] Add range checking to the constant argument of cmpps/pd/ss/sd builtinas. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=785c47f70f19be1abdb5be2ebadcc8d9c29cd627;p=clang [x86] Add range checking to the constant argument of cmpps/pd/ss/sd builtinas. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224880 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 55de70826b..f4e33c6cb0 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -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 index 0000000000..9929e6135c --- /dev/null +++ b/test/Sema/builtins-x86.c @@ -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}} +}