r224880 - [x86] Add range checking to the constant argument of cmpps/pd/ss/sd builtinas.
Craig Topper
craig.topper at gmail.com
Fri Dec 26 23:00:09 PST 2014
Author: ctopper
Date: Sat Dec 27 01:00:08 2014
New Revision: 224880
URL: http://llvm.org/viewvc/llvm-project?rev=224880&view=rev
Log:
[x86] Add range checking to the constant argument of cmpps/pd/ss/sd builtinas.
Added:
cfe/trunk/test/Sema/builtins-x86.c
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=224880&r1=224879&r2=224880&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Sat Dec 27 01:00:08 2014
@@ -836,12 +836,16 @@ bool Sema::CheckMipsBuiltinFunctionCall(
}
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
Added: cfe/trunk/test/Sema/builtins-x86.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtins-x86.c?rev=224880&view=auto
==============================================================================
--- cfe/trunk/test/Sema/builtins-x86.c (added)
+++ cfe/trunk/test/Sema/builtins-x86.c Sat Dec 27 01:00:08 2014
@@ -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}}
+}
More information about the cfe-commits
mailing list