Bug Summary

File:include/llvm/ADT/SmallBitVector.h
Warning:line 125, column 3
Potential memory leak

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name SemaChecking.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-8/lib/clang/8.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/clang/lib/Sema -I /build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema -I /build/llvm-toolchain-snapshot-8~svn345461/tools/clang/include -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn345461/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/8.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/clang/lib/Sema -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-10-27-211344-32123-1 -x c++ /build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp -faddrsig

/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp

1//===- SemaChecking.cpp - Extra Semantic Checking -------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements extra semantic analysis beyond what is enforced
11// by the C type system.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/AST/APValue.h"
16#include "clang/AST/ASTContext.h"
17#include "clang/AST/Attr.h"
18#include "clang/AST/AttrIterator.h"
19#include "clang/AST/CharUnits.h"
20#include "clang/AST/Decl.h"
21#include "clang/AST/DeclBase.h"
22#include "clang/AST/DeclCXX.h"
23#include "clang/AST/DeclObjC.h"
24#include "clang/AST/DeclarationName.h"
25#include "clang/AST/EvaluatedExprVisitor.h"
26#include "clang/AST/Expr.h"
27#include "clang/AST/ExprCXX.h"
28#include "clang/AST/ExprObjC.h"
29#include "clang/AST/ExprOpenMP.h"
30#include "clang/AST/NSAPI.h"
31#include "clang/AST/NonTrivialTypeVisitor.h"
32#include "clang/AST/OperationKinds.h"
33#include "clang/AST/Stmt.h"
34#include "clang/AST/TemplateBase.h"
35#include "clang/AST/Type.h"
36#include "clang/AST/TypeLoc.h"
37#include "clang/AST/UnresolvedSet.h"
38#include "clang/Analysis/Analyses/FormatString.h"
39#include "clang/Basic/AddressSpaces.h"
40#include "clang/Basic/CharInfo.h"
41#include "clang/Basic/Diagnostic.h"
42#include "clang/Basic/IdentifierTable.h"
43#include "clang/Basic/LLVM.h"
44#include "clang/Basic/LangOptions.h"
45#include "clang/Basic/OpenCLOptions.h"
46#include "clang/Basic/OperatorKinds.h"
47#include "clang/Basic/PartialDiagnostic.h"
48#include "clang/Basic/SourceLocation.h"
49#include "clang/Basic/SourceManager.h"
50#include "clang/Basic/Specifiers.h"
51#include "clang/Basic/SyncScope.h"
52#include "clang/Basic/TargetBuiltins.h"
53#include "clang/Basic/TargetCXXABI.h"
54#include "clang/Basic/TargetInfo.h"
55#include "clang/Basic/TypeTraits.h"
56#include "clang/Lex/Lexer.h" // TODO: Extract static functions to fix layering.
57#include "clang/Sema/Initialization.h"
58#include "clang/Sema/Lookup.h"
59#include "clang/Sema/Ownership.h"
60#include "clang/Sema/Scope.h"
61#include "clang/Sema/ScopeInfo.h"
62#include "clang/Sema/Sema.h"
63#include "clang/Sema/SemaInternal.h"
64#include "llvm/ADT/APFloat.h"
65#include "llvm/ADT/APInt.h"
66#include "llvm/ADT/APSInt.h"
67#include "llvm/ADT/ArrayRef.h"
68#include "llvm/ADT/DenseMap.h"
69#include "llvm/ADT/FoldingSet.h"
70#include "llvm/ADT/None.h"
71#include "llvm/ADT/Optional.h"
72#include "llvm/ADT/STLExtras.h"
73#include "llvm/ADT/SmallBitVector.h"
74#include "llvm/ADT/SmallPtrSet.h"
75#include "llvm/ADT/SmallString.h"
76#include "llvm/ADT/SmallVector.h"
77#include "llvm/ADT/StringRef.h"
78#include "llvm/ADT/StringSwitch.h"
79#include "llvm/ADT/Triple.h"
80#include "llvm/Support/AtomicOrdering.h"
81#include "llvm/Support/Casting.h"
82#include "llvm/Support/Compiler.h"
83#include "llvm/Support/ConvertUTF.h"
84#include "llvm/Support/ErrorHandling.h"
85#include "llvm/Support/Format.h"
86#include "llvm/Support/Locale.h"
87#include "llvm/Support/MathExtras.h"
88#include "llvm/Support/raw_ostream.h"
89#include <algorithm>
90#include <cassert>
91#include <cstddef>
92#include <cstdint>
93#include <functional>
94#include <limits>
95#include <string>
96#include <tuple>
97#include <utility>
98
99using namespace clang;
100using namespace sema;
101
102SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
103 unsigned ByteNo) const {
104 return SL->getLocationOfByte(ByteNo, getSourceManager(), LangOpts,
105 Context.getTargetInfo());
106}
107
108/// Checks that a call expression's argument count is the desired number.
109/// This is useful when doing custom type-checking. Returns true on error.
110static bool checkArgCount(Sema &S, CallExpr *call, unsigned desiredArgCount) {
111 unsigned argCount = call->getNumArgs();
112 if (argCount == desiredArgCount) return false;
113
114 if (argCount < desiredArgCount)
115 return S.Diag(call->getEndLoc(), diag::err_typecheck_call_too_few_args)
116 << 0 /*function call*/ << desiredArgCount << argCount
117 << call->getSourceRange();
118
119 // Highlight all the excess arguments.
120 SourceRange range(call->getArg(desiredArgCount)->getBeginLoc(),
121 call->getArg(argCount - 1)->getEndLoc());
122
123 return S.Diag(range.getBegin(), diag::err_typecheck_call_too_many_args)
124 << 0 /*function call*/ << desiredArgCount << argCount
125 << call->getArg(1)->getSourceRange();
126}
127
128/// Check that the first argument to __builtin_annotation is an integer
129/// and the second argument is a non-wide string literal.
130static bool SemaBuiltinAnnotation(Sema &S, CallExpr *TheCall) {
131 if (checkArgCount(S, TheCall, 2))
132 return true;
133
134 // First argument should be an integer.
135 Expr *ValArg = TheCall->getArg(0);
136 QualType Ty = ValArg->getType();
137 if (!Ty->isIntegerType()) {
138 S.Diag(ValArg->getBeginLoc(), diag::err_builtin_annotation_first_arg)
139 << ValArg->getSourceRange();
140 return true;
141 }
142
143 // Second argument should be a constant string.
144 Expr *StrArg = TheCall->getArg(1)->IgnoreParenCasts();
145 StringLiteral *Literal = dyn_cast<StringLiteral>(StrArg);
146 if (!Literal || !Literal->isAscii()) {
147 S.Diag(StrArg->getBeginLoc(), diag::err_builtin_annotation_second_arg)
148 << StrArg->getSourceRange();
149 return true;
150 }
151
152 TheCall->setType(Ty);
153 return false;
154}
155
156static bool SemaBuiltinMSVCAnnotation(Sema &S, CallExpr *TheCall) {
157 // We need at least one argument.
158 if (TheCall->getNumArgs() < 1) {
159 S.Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args_at_least)
160 << 0 << 1 << TheCall->getNumArgs()
161 << TheCall->getCallee()->getSourceRange();
162 return true;
163 }
164
165 // All arguments should be wide string literals.
166 for (Expr *Arg : TheCall->arguments()) {
167 auto *Literal = dyn_cast<StringLiteral>(Arg->IgnoreParenCasts());
168 if (!Literal || !Literal->isWide()) {
169 S.Diag(Arg->getBeginLoc(), diag::err_msvc_annotation_wide_str)
170 << Arg->getSourceRange();
171 return true;
172 }
173 }
174
175 return false;
176}
177
178/// Check that the argument to __builtin_addressof is a glvalue, and set the
179/// result type to the corresponding pointer type.
180static bool SemaBuiltinAddressof(Sema &S, CallExpr *TheCall) {
181 if (checkArgCount(S, TheCall, 1))
182 return true;
183
184 ExprResult Arg(TheCall->getArg(0));
185 QualType ResultType = S.CheckAddressOfOperand(Arg, TheCall->getBeginLoc());
186 if (ResultType.isNull())
187 return true;
188
189 TheCall->setArg(0, Arg.get());
190 TheCall->setType(ResultType);
191 return false;
192}
193
194static bool SemaBuiltinOverflow(Sema &S, CallExpr *TheCall) {
195 if (checkArgCount(S, TheCall, 3))
196 return true;
197
198 // First two arguments should be integers.
199 for (unsigned I = 0; I < 2; ++I) {
200 ExprResult Arg = TheCall->getArg(I);
201 QualType Ty = Arg.get()->getType();
202 if (!Ty->isIntegerType()) {
203 S.Diag(Arg.get()->getBeginLoc(), diag::err_overflow_builtin_must_be_int)
204 << Ty << Arg.get()->getSourceRange();
205 return true;
206 }
207 InitializedEntity Entity = InitializedEntity::InitializeParameter(
208 S.getASTContext(), Ty, /*consume*/ false);
209 Arg = S.PerformCopyInitialization(Entity, SourceLocation(), Arg);
210 if (Arg.isInvalid())
211 return true;
212 TheCall->setArg(I, Arg.get());
213 }
214
215 // Third argument should be a pointer to a non-const integer.
216 // IRGen correctly handles volatile, restrict, and address spaces, and
217 // the other qualifiers aren't possible.
218 {
219 ExprResult Arg = TheCall->getArg(2);
220 QualType Ty = Arg.get()->getType();
221 const auto *PtrTy = Ty->getAs<PointerType>();
222 if (!(PtrTy && PtrTy->getPointeeType()->isIntegerType() &&
223 !PtrTy->getPointeeType().isConstQualified())) {
224 S.Diag(Arg.get()->getBeginLoc(),
225 diag::err_overflow_builtin_must_be_ptr_int)
226 << Ty << Arg.get()->getSourceRange();
227 return true;
228 }
229 InitializedEntity Entity = InitializedEntity::InitializeParameter(
230 S.getASTContext(), Ty, /*consume*/ false);
231 Arg = S.PerformCopyInitialization(Entity, SourceLocation(), Arg);
232 if (Arg.isInvalid())
233 return true;
234 TheCall->setArg(2, Arg.get());
235 }
236 return false;
237}
238
239static void SemaBuiltinMemChkCall(Sema &S, FunctionDecl *FDecl,
240 CallExpr *TheCall, unsigned SizeIdx,
241 unsigned DstSizeIdx,
242 StringRef LikelyMacroName) {
243 if (TheCall->getNumArgs() <= SizeIdx ||
244 TheCall->getNumArgs() <= DstSizeIdx)
245 return;
246
247 const Expr *SizeArg = TheCall->getArg(SizeIdx);
248 const Expr *DstSizeArg = TheCall->getArg(DstSizeIdx);
249
250 llvm::APSInt Size, DstSize;
251
252 // find out if both sizes are known at compile time
253 if (!SizeArg->EvaluateAsInt(Size, S.Context) ||
254 !DstSizeArg->EvaluateAsInt(DstSize, S.Context))
255 return;
256
257 if (Size.ule(DstSize))
258 return;
259
260 // Confirmed overflow, so generate the diagnostic.
261 StringRef FunctionName = FDecl->getName();
262 SourceLocation SL = TheCall->getBeginLoc();
263 SourceManager &SM = S.getSourceManager();
264 // If we're in an expansion of a macro whose name corresponds to this builtin,
265 // use the simple macro name and location.
266 if (SL.isMacroID() && Lexer::getImmediateMacroName(SL, SM, S.getLangOpts()) ==
267 LikelyMacroName) {
268 FunctionName = LikelyMacroName;
269 SL = SM.getImmediateMacroCallerLoc(SL);
270 }
271
272 S.Diag(SL, diag::warn_memcpy_chk_overflow)
273 << FunctionName << DstSize.toString(/*Radix=*/10)
274 << Size.toString(/*Radix=*/10);
275}
276
277static bool SemaBuiltinCallWithStaticChain(Sema &S, CallExpr *BuiltinCall) {
278 if (checkArgCount(S, BuiltinCall, 2))
279 return true;
280
281 SourceLocation BuiltinLoc = BuiltinCall->getBeginLoc();
282 Expr *Builtin = BuiltinCall->getCallee()->IgnoreImpCasts();
283 Expr *Call = BuiltinCall->getArg(0);
284 Expr *Chain = BuiltinCall->getArg(1);
285
286 if (Call->getStmtClass() != Stmt::CallExprClass) {
287 S.Diag(BuiltinLoc, diag::err_first_argument_to_cwsc_not_call)
288 << Call->getSourceRange();
289 return true;
290 }
291
292 auto CE = cast<CallExpr>(Call);
293 if (CE->getCallee()->getType()->isBlockPointerType()) {
294 S.Diag(BuiltinLoc, diag::err_first_argument_to_cwsc_block_call)
295 << Call->getSourceRange();
296 return true;
297 }
298
299 const Decl *TargetDecl = CE->getCalleeDecl();
300 if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl))
301 if (FD->getBuiltinID()) {
302 S.Diag(BuiltinLoc, diag::err_first_argument_to_cwsc_builtin_call)
303 << Call->getSourceRange();
304 return true;
305 }
306
307 if (isa<CXXPseudoDestructorExpr>(CE->getCallee()->IgnoreParens())) {
308 S.Diag(BuiltinLoc, diag::err_first_argument_to_cwsc_pdtor_call)
309 << Call->getSourceRange();
310 return true;
311 }
312
313 ExprResult ChainResult = S.UsualUnaryConversions(Chain);
314 if (ChainResult.isInvalid())
315 return true;
316 if (!ChainResult.get()->getType()->isPointerType()) {
317 S.Diag(BuiltinLoc, diag::err_second_argument_to_cwsc_not_pointer)
318 << Chain->getSourceRange();
319 return true;
320 }
321
322 QualType ReturnTy = CE->getCallReturnType(S.Context);
323 QualType ArgTys[2] = { ReturnTy, ChainResult.get()->getType() };
324 QualType BuiltinTy = S.Context.getFunctionType(
325 ReturnTy, ArgTys, FunctionProtoType::ExtProtoInfo());
326 QualType BuiltinPtrTy = S.Context.getPointerType(BuiltinTy);
327
328 Builtin =
329 S.ImpCastExprToType(Builtin, BuiltinPtrTy, CK_BuiltinFnToFnPtr).get();
330
331 BuiltinCall->setType(CE->getType());
332 BuiltinCall->setValueKind(CE->getValueKind());
333 BuiltinCall->setObjectKind(CE->getObjectKind());
334 BuiltinCall->setCallee(Builtin);
335 BuiltinCall->setArg(1, ChainResult.get());
336
337 return false;
338}
339
340static bool SemaBuiltinSEHScopeCheck(Sema &SemaRef, CallExpr *TheCall,
341 Scope::ScopeFlags NeededScopeFlags,
342 unsigned DiagID) {
343 // Scopes aren't available during instantiation. Fortunately, builtin
344 // functions cannot be template args so they cannot be formed through template
345 // instantiation. Therefore checking once during the parse is sufficient.
346 if (SemaRef.inTemplateInstantiation())
347 return false;
348
349 Scope *S = SemaRef.getCurScope();
350 while (S && !S->isSEHExceptScope())
351 S = S->getParent();
352 if (!S || !(S->getFlags() & NeededScopeFlags)) {
353 auto *DRE = cast<DeclRefExpr>(TheCall->getCallee()->IgnoreParenCasts());
354 SemaRef.Diag(TheCall->getExprLoc(), DiagID)
355 << DRE->getDecl()->getIdentifier();
356 return true;
357 }
358
359 return false;
360}
361
362static inline bool isBlockPointer(Expr *Arg) {
363 return Arg->getType()->isBlockPointerType();
364}
365
366/// OpenCL C v2.0, s6.13.17.2 - Checks that the block parameters are all local
367/// void*, which is a requirement of device side enqueue.
368static bool checkOpenCLBlockArgs(Sema &S, Expr *BlockArg) {
369 const BlockPointerType *BPT =
370 cast<BlockPointerType>(BlockArg->getType().getCanonicalType());
371 ArrayRef<QualType> Params =
372 BPT->getPointeeType()->getAs<FunctionProtoType>()->getParamTypes();
373 unsigned ArgCounter = 0;
374 bool IllegalParams = false;
375 // Iterate through the block parameters until either one is found that is not
376 // a local void*, or the block is valid.
377 for (ArrayRef<QualType>::iterator I = Params.begin(), E = Params.end();
378 I != E; ++I, ++ArgCounter) {
379 if (!(*I)->isPointerType() || !(*I)->getPointeeType()->isVoidType() ||
380 (*I)->getPointeeType().getQualifiers().getAddressSpace() !=
381 LangAS::opencl_local) {
382 // Get the location of the error. If a block literal has been passed
383 // (BlockExpr) then we can point straight to the offending argument,
384 // else we just point to the variable reference.
385 SourceLocation ErrorLoc;
386 if (isa<BlockExpr>(BlockArg)) {
387 BlockDecl *BD = cast<BlockExpr>(BlockArg)->getBlockDecl();
388 ErrorLoc = BD->getParamDecl(ArgCounter)->getBeginLoc();
389 } else if (isa<DeclRefExpr>(BlockArg)) {
390 ErrorLoc = cast<DeclRefExpr>(BlockArg)->getBeginLoc();
391 }
392 S.Diag(ErrorLoc,
393 diag::err_opencl_enqueue_kernel_blocks_non_local_void_args);
394 IllegalParams = true;
395 }
396 }
397
398 return IllegalParams;
399}
400
401static bool checkOpenCLSubgroupExt(Sema &S, CallExpr *Call) {
402 if (!S.getOpenCLOptions().isEnabled("cl_khr_subgroups")) {
403 S.Diag(Call->getBeginLoc(), diag::err_opencl_requires_extension)
404 << 1 << Call->getDirectCallee() << "cl_khr_subgroups";
405 return true;
406 }
407 return false;
408}
409
410static bool SemaOpenCLBuiltinNDRangeAndBlock(Sema &S, CallExpr *TheCall) {
411 if (checkArgCount(S, TheCall, 2))
412 return true;
413
414 if (checkOpenCLSubgroupExt(S, TheCall))
415 return true;
416
417 // First argument is an ndrange_t type.
418 Expr *NDRangeArg = TheCall->getArg(0);
419 if (NDRangeArg->getType().getUnqualifiedType().getAsString() != "ndrange_t") {
420 S.Diag(NDRangeArg->getBeginLoc(), diag::err_opencl_builtin_expected_type)
421 << TheCall->getDirectCallee() << "'ndrange_t'";
422 return true;
423 }
424
425 Expr *BlockArg = TheCall->getArg(1);
426 if (!isBlockPointer(BlockArg)) {
427 S.Diag(BlockArg->getBeginLoc(), diag::err_opencl_builtin_expected_type)
428 << TheCall->getDirectCallee() << "block";
429 return true;
430 }
431 return checkOpenCLBlockArgs(S, BlockArg);
432}
433
434/// OpenCL C v2.0, s6.13.17.6 - Check the argument to the
435/// get_kernel_work_group_size
436/// and get_kernel_preferred_work_group_size_multiple builtin functions.
437static bool SemaOpenCLBuiltinKernelWorkGroupSize(Sema &S, CallExpr *TheCall) {
438 if (checkArgCount(S, TheCall, 1))
439 return true;
440
441 Expr *BlockArg = TheCall->getArg(0);
442 if (!isBlockPointer(BlockArg)) {
443 S.Diag(BlockArg->getBeginLoc(), diag::err_opencl_builtin_expected_type)
444 << TheCall->getDirectCallee() << "block";
445 return true;
446 }
447 return checkOpenCLBlockArgs(S, BlockArg);
448}
449
450/// Diagnose integer type and any valid implicit conversion to it.
451static bool checkOpenCLEnqueueIntType(Sema &S, Expr *E,
452 const QualType &IntType);
453
454static bool checkOpenCLEnqueueLocalSizeArgs(Sema &S, CallExpr *TheCall,
455 unsigned Start, unsigned End) {
456 bool IllegalParams = false;
457 for (unsigned I = Start; I <= End; ++I)
458 IllegalParams |= checkOpenCLEnqueueIntType(S, TheCall->getArg(I),
459 S.Context.getSizeType());
460 return IllegalParams;
461}
462
463/// OpenCL v2.0, s6.13.17.1 - Check that sizes are provided for all
464/// 'local void*' parameter of passed block.
465static bool checkOpenCLEnqueueVariadicArgs(Sema &S, CallExpr *TheCall,
466 Expr *BlockArg,
467 unsigned NumNonVarArgs) {
468 const BlockPointerType *BPT =
469 cast<BlockPointerType>(BlockArg->getType().getCanonicalType());
470 unsigned NumBlockParams =
471 BPT->getPointeeType()->getAs<FunctionProtoType>()->getNumParams();
472 unsigned TotalNumArgs = TheCall->getNumArgs();
473
474 // For each argument passed to the block, a corresponding uint needs to
475 // be passed to describe the size of the local memory.
476 if (TotalNumArgs != NumBlockParams + NumNonVarArgs) {
477 S.Diag(TheCall->getBeginLoc(),
478 diag::err_opencl_enqueue_kernel_local_size_args);
479 return true;
480 }
481
482 // Check that the sizes of the local memory are specified by integers.
483 return checkOpenCLEnqueueLocalSizeArgs(S, TheCall, NumNonVarArgs,
484 TotalNumArgs - 1);
485}
486
487/// OpenCL C v2.0, s6.13.17 - Enqueue kernel function contains four different
488/// overload formats specified in Table 6.13.17.1.
489/// int enqueue_kernel(queue_t queue,
490/// kernel_enqueue_flags_t flags,
491/// const ndrange_t ndrange,
492/// void (^block)(void))
493/// int enqueue_kernel(queue_t queue,
494/// kernel_enqueue_flags_t flags,
495/// const ndrange_t ndrange,
496/// uint num_events_in_wait_list,
497/// clk_event_t *event_wait_list,
498/// clk_event_t *event_ret,
499/// void (^block)(void))
500/// int enqueue_kernel(queue_t queue,
501/// kernel_enqueue_flags_t flags,
502/// const ndrange_t ndrange,
503/// void (^block)(local void*, ...),
504/// uint size0, ...)
505/// int enqueue_kernel(queue_t queue,
506/// kernel_enqueue_flags_t flags,
507/// const ndrange_t ndrange,
508/// uint num_events_in_wait_list,
509/// clk_event_t *event_wait_list,
510/// clk_event_t *event_ret,
511/// void (^block)(local void*, ...),
512/// uint size0, ...)
513static bool SemaOpenCLBuiltinEnqueueKernel(Sema &S, CallExpr *TheCall) {
514 unsigned NumArgs = TheCall->getNumArgs();
515
516 if (NumArgs < 4) {
517 S.Diag(TheCall->getBeginLoc(), diag::err_typecheck_call_too_few_args);
518 return true;
519 }
520
521 Expr *Arg0 = TheCall->getArg(0);
522 Expr *Arg1 = TheCall->getArg(1);
523 Expr *Arg2 = TheCall->getArg(2);
524 Expr *Arg3 = TheCall->getArg(3);
525
526 // First argument always needs to be a queue_t type.
527 if (!Arg0->getType()->isQueueT()) {
528 S.Diag(TheCall->getArg(0)->getBeginLoc(),
529 diag::err_opencl_builtin_expected_type)
530 << TheCall->getDirectCallee() << S.Context.OCLQueueTy;
531 return true;
532 }
533
534 // Second argument always needs to be a kernel_enqueue_flags_t enum value.
535 if (!Arg1->getType()->isIntegerType()) {
536 S.Diag(TheCall->getArg(1)->getBeginLoc(),
537 diag::err_opencl_builtin_expected_type)
538 << TheCall->getDirectCallee() << "'kernel_enqueue_flags_t' (i.e. uint)";
539 return true;
540 }
541
542 // Third argument is always an ndrange_t type.
543 if (Arg2->getType().getUnqualifiedType().getAsString() != "ndrange_t") {
544 S.Diag(TheCall->getArg(2)->getBeginLoc(),
545 diag::err_opencl_builtin_expected_type)
546 << TheCall->getDirectCallee() << "'ndrange_t'";
547 return true;
548 }
549
550 // With four arguments, there is only one form that the function could be
551 // called in: no events and no variable arguments.
552 if (NumArgs == 4) {
553 // check that the last argument is the right block type.
554 if (!isBlockPointer(Arg3)) {
555 S.Diag(Arg3->getBeginLoc(), diag::err_opencl_builtin_expected_type)
556 << TheCall->getDirectCallee() << "block";
557 return true;
558 }
559 // we have a block type, check the prototype
560 const BlockPointerType *BPT =
561 cast<BlockPointerType>(Arg3->getType().getCanonicalType());
562 if (BPT->getPointeeType()->getAs<FunctionProtoType>()->getNumParams() > 0) {
563 S.Diag(Arg3->getBeginLoc(),
564 diag::err_opencl_enqueue_kernel_blocks_no_args);
565 return true;
566 }
567 return false;
568 }
569 // we can have block + varargs.
570 if (isBlockPointer(Arg3))
571 return (checkOpenCLBlockArgs(S, Arg3) ||
572 checkOpenCLEnqueueVariadicArgs(S, TheCall, Arg3, 4));
573 // last two cases with either exactly 7 args or 7 args and varargs.
574 if (NumArgs >= 7) {
575 // check common block argument.
576 Expr *Arg6 = TheCall->getArg(6);
577 if (!isBlockPointer(Arg6)) {
578 S.Diag(Arg6->getBeginLoc(), diag::err_opencl_builtin_expected_type)
579 << TheCall->getDirectCallee() << "block";
580 return true;
581 }
582 if (checkOpenCLBlockArgs(S, Arg6))
583 return true;
584
585 // Forth argument has to be any integer type.
586 if (!Arg3->getType()->isIntegerType()) {
587 S.Diag(TheCall->getArg(3)->getBeginLoc(),
588 diag::err_opencl_builtin_expected_type)
589 << TheCall->getDirectCallee() << "integer";
590 return true;
591 }
592 // check remaining common arguments.
593 Expr *Arg4 = TheCall->getArg(4);
594 Expr *Arg5 = TheCall->getArg(5);
595
596 // Fifth argument is always passed as a pointer to clk_event_t.
597 if (!Arg4->isNullPointerConstant(S.Context,
598 Expr::NPC_ValueDependentIsNotNull) &&
599 !Arg4->getType()->getPointeeOrArrayElementType()->isClkEventT()) {
600 S.Diag(TheCall->getArg(4)->getBeginLoc(),
601 diag::err_opencl_builtin_expected_type)
602 << TheCall->getDirectCallee()
603 << S.Context.getPointerType(S.Context.OCLClkEventTy);
604 return true;
605 }
606
607 // Sixth argument is always passed as a pointer to clk_event_t.
608 if (!Arg5->isNullPointerConstant(S.Context,
609 Expr::NPC_ValueDependentIsNotNull) &&
610 !(Arg5->getType()->isPointerType() &&
611 Arg5->getType()->getPointeeType()->isClkEventT())) {
612 S.Diag(TheCall->getArg(5)->getBeginLoc(),
613 diag::err_opencl_builtin_expected_type)
614 << TheCall->getDirectCallee()
615 << S.Context.getPointerType(S.Context.OCLClkEventTy);
616 return true;
617 }
618
619 if (NumArgs == 7)
620 return false;
621
622 return checkOpenCLEnqueueVariadicArgs(S, TheCall, Arg6, 7);
623 }
624
625 // None of the specific case has been detected, give generic error
626 S.Diag(TheCall->getBeginLoc(),
627 diag::err_opencl_enqueue_kernel_incorrect_args);
628 return true;
629}
630
631/// Returns OpenCL access qual.
632static OpenCLAccessAttr *getOpenCLArgAccess(const Decl *D) {
633 return D->getAttr<OpenCLAccessAttr>();
634}
635
636/// Returns true if pipe element type is different from the pointer.
637static bool checkOpenCLPipeArg(Sema &S, CallExpr *Call) {
638 const Expr *Arg0 = Call->getArg(0);
639 // First argument type should always be pipe.
640 if (!Arg0->getType()->isPipeType()) {
641 S.Diag(Call->getBeginLoc(), diag::err_opencl_builtin_pipe_first_arg)
642 << Call->getDirectCallee() << Arg0->getSourceRange();
643 return true;
644 }
645 OpenCLAccessAttr *AccessQual =
646 getOpenCLArgAccess(cast<DeclRefExpr>(Arg0)->getDecl());
647 // Validates the access qualifier is compatible with the call.
648 // OpenCL v2.0 s6.13.16 - The access qualifiers for pipe should only be
649 // read_only and write_only, and assumed to be read_only if no qualifier is
650 // specified.
651 switch (Call->getDirectCallee()->getBuiltinID()) {
652 case Builtin::BIread_pipe:
653 case Builtin::BIreserve_read_pipe:
654 case Builtin::BIcommit_read_pipe:
655 case Builtin::BIwork_group_reserve_read_pipe:
656 case Builtin::BIsub_group_reserve_read_pipe:
657 case Builtin::BIwork_group_commit_read_pipe:
658 case Builtin::BIsub_group_commit_read_pipe:
659 if (!(!AccessQual || AccessQual->isReadOnly())) {
660 S.Diag(Arg0->getBeginLoc(),
661 diag::err_opencl_builtin_pipe_invalid_access_modifier)
662 << "read_only" << Arg0->getSourceRange();
663 return true;
664 }
665 break;
666 case Builtin::BIwrite_pipe:
667 case Builtin::BIreserve_write_pipe:
668 case Builtin::BIcommit_write_pipe:
669 case Builtin::BIwork_group_reserve_write_pipe:
670 case Builtin::BIsub_group_reserve_write_pipe:
671 case Builtin::BIwork_group_commit_write_pipe:
672 case Builtin::BIsub_group_commit_write_pipe:
673 if (!(AccessQual && AccessQual->isWriteOnly())) {
674 S.Diag(Arg0->getBeginLoc(),
675 diag::err_opencl_builtin_pipe_invalid_access_modifier)
676 << "write_only" << Arg0->getSourceRange();
677 return true;
678 }
679 break;
680 default:
681 break;
682 }
683 return false;
684}
685
686/// Returns true if pipe element type is different from the pointer.
687static bool checkOpenCLPipePacketType(Sema &S, CallExpr *Call, unsigned Idx) {
688 const Expr *Arg0 = Call->getArg(0);
689 const Expr *ArgIdx = Call->getArg(Idx);
690 const PipeType *PipeTy = cast<PipeType>(Arg0->getType());
691 const QualType EltTy = PipeTy->getElementType();
692 const PointerType *ArgTy = ArgIdx->getType()->getAs<PointerType>();
693 // The Idx argument should be a pointer and the type of the pointer and
694 // the type of pipe element should also be the same.
695 if (!ArgTy ||
696 !S.Context.hasSameType(
697 EltTy, ArgTy->getPointeeType()->getCanonicalTypeInternal())) {
698 S.Diag(Call->getBeginLoc(), diag::err_opencl_builtin_pipe_invalid_arg)
699 << Call->getDirectCallee() << S.Context.getPointerType(EltTy)
700 << ArgIdx->getType() << ArgIdx->getSourceRange();
701 return true;
702 }
703 return false;
704}
705
706// Performs semantic analysis for the read/write_pipe call.
707// \param S Reference to the semantic analyzer.
708// \param Call A pointer to the builtin call.
709// \return True if a semantic error has been found, false otherwise.
710static bool SemaBuiltinRWPipe(Sema &S, CallExpr *Call) {
711 // OpenCL v2.0 s6.13.16.2 - The built-in read/write
712 // functions have two forms.
713 switch (Call->getNumArgs()) {
714 case 2:
715 if (checkOpenCLPipeArg(S, Call))
716 return true;
717 // The call with 2 arguments should be
718 // read/write_pipe(pipe T, T*).
719 // Check packet type T.
720 if (checkOpenCLPipePacketType(S, Call, 1))
721 return true;
722 break;
723
724 case 4: {
725 if (checkOpenCLPipeArg(S, Call))
726 return true;
727 // The call with 4 arguments should be
728 // read/write_pipe(pipe T, reserve_id_t, uint, T*).
729 // Check reserve_id_t.
730 if (!Call->getArg(1)->getType()->isReserveIDT()) {
731 S.Diag(Call->getBeginLoc(), diag::err_opencl_builtin_pipe_invalid_arg)
732 << Call->getDirectCallee() << S.Context.OCLReserveIDTy
733 << Call->getArg(1)->getType() << Call->getArg(1)->getSourceRange();
734 return true;
735 }
736
737 // Check the index.
738 const Expr *Arg2 = Call->getArg(2);
739 if (!Arg2->getType()->isIntegerType() &&
740 !Arg2->getType()->isUnsignedIntegerType()) {
741 S.Diag(Call->getBeginLoc(), diag::err_opencl_builtin_pipe_invalid_arg)
742 << Call->getDirectCallee() << S.Context.UnsignedIntTy
743 << Arg2->getType() << Arg2->getSourceRange();
744 return true;
745 }
746
747 // Check packet type T.
748 if (checkOpenCLPipePacketType(S, Call, 3))
749 return true;
750 } break;
751 default:
752 S.Diag(Call->getBeginLoc(), diag::err_opencl_builtin_pipe_arg_num)
753 << Call->getDirectCallee() << Call->getSourceRange();
754 return true;
755 }
756
757 return false;
758}
759
760// Performs a semantic analysis on the {work_group_/sub_group_
761// /_}reserve_{read/write}_pipe
762// \param S Reference to the semantic analyzer.
763// \param Call The call to the builtin function to be analyzed.
764// \return True if a semantic error was found, false otherwise.
765static bool SemaBuiltinReserveRWPipe(Sema &S, CallExpr *Call) {
766 if (checkArgCount(S, Call, 2))
767 return true;
768
769 if (checkOpenCLPipeArg(S, Call))
770 return true;
771
772 // Check the reserve size.
773 if (!Call->getArg(1)->getType()->isIntegerType() &&
774 !Call->getArg(1)->getType()->isUnsignedIntegerType()) {
775 S.Diag(Call->getBeginLoc(), diag::err_opencl_builtin_pipe_invalid_arg)
776 << Call->getDirectCallee() << S.Context.UnsignedIntTy
777 << Call->getArg(1)->getType() << Call->getArg(1)->getSourceRange();
778 return true;
779 }
780
781 // Since return type of reserve_read/write_pipe built-in function is
782 // reserve_id_t, which is not defined in the builtin def file , we used int
783 // as return type and need to override the return type of these functions.
784 Call->setType(S.Context.OCLReserveIDTy);
785
786 return false;
787}
788
789// Performs a semantic analysis on {work_group_/sub_group_
790// /_}commit_{read/write}_pipe
791// \param S Reference to the semantic analyzer.
792// \param Call The call to the builtin function to be analyzed.
793// \return True if a semantic error was found, false otherwise.
794static bool SemaBuiltinCommitRWPipe(Sema &S, CallExpr *Call) {
795 if (checkArgCount(S, Call, 2))
796 return true;
797
798 if (checkOpenCLPipeArg(S, Call))
799 return true;
800
801 // Check reserve_id_t.
802 if (!Call->getArg(1)->getType()->isReserveIDT()) {
803 S.Diag(Call->getBeginLoc(), diag::err_opencl_builtin_pipe_invalid_arg)
804 << Call->getDirectCallee() << S.Context.OCLReserveIDTy
805 << Call->getArg(1)->getType() << Call->getArg(1)->getSourceRange();
806 return true;
807 }
808
809 return false;
810}
811
812// Performs a semantic analysis on the call to built-in Pipe
813// Query Functions.
814// \param S Reference to the semantic analyzer.
815// \param Call The call to the builtin function to be analyzed.
816// \return True if a semantic error was found, false otherwise.
817static bool SemaBuiltinPipePackets(Sema &S, CallExpr *Call) {
818 if (checkArgCount(S, Call, 1))
819 return true;
820
821 if (!Call->getArg(0)->getType()->isPipeType()) {
822 S.Diag(Call->getBeginLoc(), diag::err_opencl_builtin_pipe_first_arg)
823 << Call->getDirectCallee() << Call->getArg(0)->getSourceRange();
824 return true;
825 }
826
827 return false;
828}
829
830// OpenCL v2.0 s6.13.9 - Address space qualifier functions.
831// Performs semantic analysis for the to_global/local/private call.
832// \param S Reference to the semantic analyzer.
833// \param BuiltinID ID of the builtin function.
834// \param Call A pointer to the builtin call.
835// \return True if a semantic error has been found, false otherwise.
836static bool SemaOpenCLBuiltinToAddr(Sema &S, unsigned BuiltinID,
837 CallExpr *Call) {
838 if (Call->getNumArgs() != 1) {
839 S.Diag(Call->getBeginLoc(), diag::err_opencl_builtin_to_addr_arg_num)
840 << Call->getDirectCallee() << Call->getSourceRange();
841 return true;
842 }
843
844 auto RT = Call->getArg(0)->getType();
845 if (!RT->isPointerType() || RT->getPointeeType()
846 .getAddressSpace() == LangAS::opencl_constant) {
847 S.Diag(Call->getBeginLoc(), diag::err_opencl_builtin_to_addr_invalid_arg)
848 << Call->getArg(0) << Call->getDirectCallee() << Call->getSourceRange();
849 return true;
850 }
851
852 if (RT->getPointeeType().getAddressSpace() != LangAS::opencl_generic) {
853 S.Diag(Call->getArg(0)->getBeginLoc(),
854 diag::warn_opencl_generic_address_space_arg)
855 << Call->getDirectCallee()->getNameInfo().getAsString()
856 << Call->getArg(0)->getSourceRange();
857 }
858
859 RT = RT->getPointeeType();
860 auto Qual = RT.getQualifiers();
861 switch (BuiltinID) {
862 case Builtin::BIto_global:
863 Qual.setAddressSpace(LangAS::opencl_global);
864 break;
865 case Builtin::BIto_local:
866 Qual.setAddressSpace(LangAS::opencl_local);
867 break;
868 case Builtin::BIto_private:
869 Qual.setAddressSpace(LangAS::opencl_private);
870 break;
871 default:
872 llvm_unreachable("Invalid builtin function")::llvm::llvm_unreachable_internal("Invalid builtin function",
"/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 872)
;
873 }
874 Call->setType(S.Context.getPointerType(S.Context.getQualifiedType(
875 RT.getUnqualifiedType(), Qual)));
876
877 return false;
878}
879
880// Emit an error and return true if the current architecture is not in the list
881// of supported architectures.
882static bool
883CheckBuiltinTargetSupport(Sema &S, unsigned BuiltinID, CallExpr *TheCall,
884 ArrayRef<llvm::Triple::ArchType> SupportedArchs) {
885 llvm::Triple::ArchType CurArch =
886 S.getASTContext().getTargetInfo().getTriple().getArch();
887 if (llvm::is_contained(SupportedArchs, CurArch))
888 return false;
889 S.Diag(TheCall->getBeginLoc(), diag::err_builtin_target_unsupported)
890 << TheCall->getSourceRange();
891 return true;
892}
893
894ExprResult
895Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
896 CallExpr *TheCall) {
897 ExprResult TheCallResult(TheCall);
898
899 // Find out if any arguments are required to be integer constant expressions.
900 unsigned ICEArguments = 0;
901 ASTContext::GetBuiltinTypeError Error;
902 Context.GetBuiltinType(BuiltinID, Error, &ICEArguments);
903 if (Error != ASTContext::GE_None)
904 ICEArguments = 0; // Don't diagnose previously diagnosed errors.
905
906 // If any arguments are required to be ICE's, check and diagnose.
907 for (unsigned ArgNo = 0; ICEArguments != 0; ++ArgNo) {
908 // Skip arguments not required to be ICE's.
909 if ((ICEArguments & (1 << ArgNo)) == 0) continue;
910
911 llvm::APSInt Result;
912 if (SemaBuiltinConstantArg(TheCall, ArgNo, Result))
913 return true;
914 ICEArguments &= ~(1 << ArgNo);
915 }
916
917 switch (BuiltinID) {
918 case Builtin::BI__builtin___CFStringMakeConstantString:
919 assert(TheCall->getNumArgs() == 1 &&((TheCall->getNumArgs() == 1 && "Wrong # arguments to builtin CFStringMakeConstantString"
) ? static_cast<void> (0) : __assert_fail ("TheCall->getNumArgs() == 1 && \"Wrong # arguments to builtin CFStringMakeConstantString\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 920, __PRETTY_FUNCTION__))
920 "Wrong # arguments to builtin CFStringMakeConstantString")((TheCall->getNumArgs() == 1 && "Wrong # arguments to builtin CFStringMakeConstantString"
) ? static_cast<void> (0) : __assert_fail ("TheCall->getNumArgs() == 1 && \"Wrong # arguments to builtin CFStringMakeConstantString\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 920, __PRETTY_FUNCTION__))
;
921 if (CheckObjCString(TheCall->getArg(0)))
922 return ExprError();
923 break;
924 case Builtin::BI__builtin_ms_va_start:
925 case Builtin::BI__builtin_stdarg_start:
926 case Builtin::BI__builtin_va_start:
927 if (SemaBuiltinVAStart(BuiltinID, TheCall))
928 return ExprError();
929 break;
930 case Builtin::BI__va_start: {
931 switch (Context.getTargetInfo().getTriple().getArch()) {
932 case llvm::Triple::aarch64:
933 case llvm::Triple::arm:
934 case llvm::Triple::thumb:
935 if (SemaBuiltinVAStartARMMicrosoft(TheCall))
936 return ExprError();
937 break;
938 default:
939 if (SemaBuiltinVAStart(BuiltinID, TheCall))
940 return ExprError();
941 break;
942 }
943 break;
944 }
945
946 // The acquire, release, and no fence variants are ARM and AArch64 only.
947 case Builtin::BI_interlockedbittestandset_acq:
948 case Builtin::BI_interlockedbittestandset_rel:
949 case Builtin::BI_interlockedbittestandset_nf:
950 case Builtin::BI_interlockedbittestandreset_acq:
951 case Builtin::BI_interlockedbittestandreset_rel:
952 case Builtin::BI_interlockedbittestandreset_nf:
953 if (CheckBuiltinTargetSupport(
954 *this, BuiltinID, TheCall,
955 {llvm::Triple::arm, llvm::Triple::thumb, llvm::Triple::aarch64}))
956 return ExprError();
957 break;
958
959 // The 64-bit bittest variants are x64, ARM, and AArch64 only.
960 case Builtin::BI_bittest64:
961 case Builtin::BI_bittestandcomplement64:
962 case Builtin::BI_bittestandreset64:
963 case Builtin::BI_bittestandset64:
964 case Builtin::BI_interlockedbittestandreset64:
965 case Builtin::BI_interlockedbittestandset64:
966 if (CheckBuiltinTargetSupport(*this, BuiltinID, TheCall,
967 {llvm::Triple::x86_64, llvm::Triple::arm,
968 llvm::Triple::thumb, llvm::Triple::aarch64}))
969 return ExprError();
970 break;
971
972 case Builtin::BI__builtin_isgreater:
973 case Builtin::BI__builtin_isgreaterequal:
974 case Builtin::BI__builtin_isless:
975 case Builtin::BI__builtin_islessequal:
976 case Builtin::BI__builtin_islessgreater:
977 case Builtin::BI__builtin_isunordered:
978 if (SemaBuiltinUnorderedCompare(TheCall))
979 return ExprError();
980 break;
981 case Builtin::BI__builtin_fpclassify:
982 if (SemaBuiltinFPClassification(TheCall, 6))
983 return ExprError();
984 break;
985 case Builtin::BI__builtin_isfinite:
986 case Builtin::BI__builtin_isinf:
987 case Builtin::BI__builtin_isinf_sign:
988 case Builtin::BI__builtin_isnan:
989 case Builtin::BI__builtin_isnormal:
990 case Builtin::BI__builtin_signbit:
991 case Builtin::BI__builtin_signbitf:
992 case Builtin::BI__builtin_signbitl:
993 if (SemaBuiltinFPClassification(TheCall, 1))
994 return ExprError();
995 break;
996 case Builtin::BI__builtin_shufflevector:
997 return SemaBuiltinShuffleVector(TheCall);
998 // TheCall will be freed by the smart pointer here, but that's fine, since
999 // SemaBuiltinShuffleVector guts it, but then doesn't release it.
1000 case Builtin::BI__builtin_prefetch:
1001 if (SemaBuiltinPrefetch(TheCall))
1002 return ExprError();
1003 break;
1004 case Builtin::BI__builtin_alloca_with_align:
1005 if (SemaBuiltinAllocaWithAlign(TheCall))
1006 return ExprError();
1007 break;
1008 case Builtin::BI__assume:
1009 case Builtin::BI__builtin_assume:
1010 if (SemaBuiltinAssume(TheCall))
1011 return ExprError();
1012 break;
1013 case Builtin::BI__builtin_assume_aligned:
1014 if (SemaBuiltinAssumeAligned(TheCall))
1015 return ExprError();
1016 break;
1017 case Builtin::BI__builtin_object_size:
1018 if (SemaBuiltinConstantArgRange(TheCall, 1, 0, 3))
1019 return ExprError();
1020 break;
1021 case Builtin::BI__builtin_longjmp:
1022 if (SemaBuiltinLongjmp(TheCall))
1023 return ExprError();
1024 break;
1025 case Builtin::BI__builtin_setjmp:
1026 if (SemaBuiltinSetjmp(TheCall))
1027 return ExprError();
1028 break;
1029 case Builtin::BI_setjmp:
1030 case Builtin::BI_setjmpex:
1031 if (checkArgCount(*this, TheCall, 1))
1032 return true;
1033 break;
1034 case Builtin::BI__builtin_classify_type:
1035 if (checkArgCount(*this, TheCall, 1)) return true;
1036 TheCall->setType(Context.IntTy);
1037 break;
1038 case Builtin::BI__builtin_constant_p:
1039 if (checkArgCount(*this, TheCall, 1)) return true;
1040 TheCall->setType(Context.IntTy);
1041 break;
1042 case Builtin::BI__sync_fetch_and_add:
1043 case Builtin::BI__sync_fetch_and_add_1:
1044 case Builtin::BI__sync_fetch_and_add_2:
1045 case Builtin::BI__sync_fetch_and_add_4:
1046 case Builtin::BI__sync_fetch_and_add_8:
1047 case Builtin::BI__sync_fetch_and_add_16:
1048 case Builtin::BI__sync_fetch_and_sub:
1049 case Builtin::BI__sync_fetch_and_sub_1:
1050 case Builtin::BI__sync_fetch_and_sub_2:
1051 case Builtin::BI__sync_fetch_and_sub_4:
1052 case Builtin::BI__sync_fetch_and_sub_8:
1053 case Builtin::BI__sync_fetch_and_sub_16:
1054 case Builtin::BI__sync_fetch_and_or:
1055 case Builtin::BI__sync_fetch_and_or_1:
1056 case Builtin::BI__sync_fetch_and_or_2:
1057 case Builtin::BI__sync_fetch_and_or_4:
1058 case Builtin::BI__sync_fetch_and_or_8:
1059 case Builtin::BI__sync_fetch_and_or_16:
1060 case Builtin::BI__sync_fetch_and_and:
1061 case Builtin::BI__sync_fetch_and_and_1:
1062 case Builtin::BI__sync_fetch_and_and_2:
1063 case Builtin::BI__sync_fetch_and_and_4:
1064 case Builtin::BI__sync_fetch_and_and_8:
1065 case Builtin::BI__sync_fetch_and_and_16:
1066 case Builtin::BI__sync_fetch_and_xor:
1067 case Builtin::BI__sync_fetch_and_xor_1:
1068 case Builtin::BI__sync_fetch_and_xor_2:
1069 case Builtin::BI__sync_fetch_and_xor_4:
1070 case Builtin::BI__sync_fetch_and_xor_8:
1071 case Builtin::BI__sync_fetch_and_xor_16:
1072 case Builtin::BI__sync_fetch_and_nand:
1073 case Builtin::BI__sync_fetch_and_nand_1:
1074 case Builtin::BI__sync_fetch_and_nand_2:
1075 case Builtin::BI__sync_fetch_and_nand_4:
1076 case Builtin::BI__sync_fetch_and_nand_8:
1077 case Builtin::BI__sync_fetch_and_nand_16:
1078 case Builtin::BI__sync_add_and_fetch:
1079 case Builtin::BI__sync_add_and_fetch_1:
1080 case Builtin::BI__sync_add_and_fetch_2:
1081 case Builtin::BI__sync_add_and_fetch_4:
1082 case Builtin::BI__sync_add_and_fetch_8:
1083 case Builtin::BI__sync_add_and_fetch_16:
1084 case Builtin::BI__sync_sub_and_fetch:
1085 case Builtin::BI__sync_sub_and_fetch_1:
1086 case Builtin::BI__sync_sub_and_fetch_2:
1087 case Builtin::BI__sync_sub_and_fetch_4:
1088 case Builtin::BI__sync_sub_and_fetch_8:
1089 case Builtin::BI__sync_sub_and_fetch_16:
1090 case Builtin::BI__sync_and_and_fetch:
1091 case Builtin::BI__sync_and_and_fetch_1:
1092 case Builtin::BI__sync_and_and_fetch_2:
1093 case Builtin::BI__sync_and_and_fetch_4:
1094 case Builtin::BI__sync_and_and_fetch_8:
1095 case Builtin::BI__sync_and_and_fetch_16:
1096 case Builtin::BI__sync_or_and_fetch:
1097 case Builtin::BI__sync_or_and_fetch_1:
1098 case Builtin::BI__sync_or_and_fetch_2:
1099 case Builtin::BI__sync_or_and_fetch_4:
1100 case Builtin::BI__sync_or_and_fetch_8:
1101 case Builtin::BI__sync_or_and_fetch_16:
1102 case Builtin::BI__sync_xor_and_fetch:
1103 case Builtin::BI__sync_xor_and_fetch_1:
1104 case Builtin::BI__sync_xor_and_fetch_2:
1105 case Builtin::BI__sync_xor_and_fetch_4:
1106 case Builtin::BI__sync_xor_and_fetch_8:
1107 case Builtin::BI__sync_xor_and_fetch_16:
1108 case Builtin::BI__sync_nand_and_fetch:
1109 case Builtin::BI__sync_nand_and_fetch_1:
1110 case Builtin::BI__sync_nand_and_fetch_2:
1111 case Builtin::BI__sync_nand_and_fetch_4:
1112 case Builtin::BI__sync_nand_and_fetch_8:
1113 case Builtin::BI__sync_nand_and_fetch_16:
1114 case Builtin::BI__sync_val_compare_and_swap:
1115 case Builtin::BI__sync_val_compare_and_swap_1:
1116 case Builtin::BI__sync_val_compare_and_swap_2:
1117 case Builtin::BI__sync_val_compare_and_swap_4:
1118 case Builtin::BI__sync_val_compare_and_swap_8:
1119 case Builtin::BI__sync_val_compare_and_swap_16:
1120 case Builtin::BI__sync_bool_compare_and_swap:
1121 case Builtin::BI__sync_bool_compare_and_swap_1:
1122 case Builtin::BI__sync_bool_compare_and_swap_2:
1123 case Builtin::BI__sync_bool_compare_and_swap_4:
1124 case Builtin::BI__sync_bool_compare_and_swap_8:
1125 case Builtin::BI__sync_bool_compare_and_swap_16:
1126 case Builtin::BI__sync_lock_test_and_set:
1127 case Builtin::BI__sync_lock_test_and_set_1:
1128 case Builtin::BI__sync_lock_test_and_set_2:
1129 case Builtin::BI__sync_lock_test_and_set_4:
1130 case Builtin::BI__sync_lock_test_and_set_8:
1131 case Builtin::BI__sync_lock_test_and_set_16:
1132 case Builtin::BI__sync_lock_release:
1133 case Builtin::BI__sync_lock_release_1:
1134 case Builtin::BI__sync_lock_release_2:
1135 case Builtin::BI__sync_lock_release_4:
1136 case Builtin::BI__sync_lock_release_8:
1137 case Builtin::BI__sync_lock_release_16:
1138 case Builtin::BI__sync_swap:
1139 case Builtin::BI__sync_swap_1:
1140 case Builtin::BI__sync_swap_2:
1141 case Builtin::BI__sync_swap_4:
1142 case Builtin::BI__sync_swap_8:
1143 case Builtin::BI__sync_swap_16:
1144 return SemaBuiltinAtomicOverloaded(TheCallResult);
1145 case Builtin::BI__sync_synchronize:
1146 Diag(TheCall->getBeginLoc(), diag::warn_atomic_implicit_seq_cst)
1147 << TheCall->getCallee()->getSourceRange();
1148 break;
1149 case Builtin::BI__builtin_nontemporal_load:
1150 case Builtin::BI__builtin_nontemporal_store:
1151 return SemaBuiltinNontemporalOverloaded(TheCallResult);
1152#define BUILTIN(ID, TYPE, ATTRS)
1153#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
1154 case Builtin::BI##ID: \
1155 return SemaAtomicOpsOverloaded(TheCallResult, AtomicExpr::AO##ID);
1156#include "clang/Basic/Builtins.def"
1157 case Builtin::BI__annotation:
1158 if (SemaBuiltinMSVCAnnotation(*this, TheCall))
1159 return ExprError();
1160 break;
1161 case Builtin::BI__builtin_annotation:
1162 if (SemaBuiltinAnnotation(*this, TheCall))
1163 return ExprError();
1164 break;
1165 case Builtin::BI__builtin_addressof:
1166 if (SemaBuiltinAddressof(*this, TheCall))
1167 return ExprError();
1168 break;
1169 case Builtin::BI__builtin_add_overflow:
1170 case Builtin::BI__builtin_sub_overflow:
1171 case Builtin::BI__builtin_mul_overflow:
1172 if (SemaBuiltinOverflow(*this, TheCall))
1173 return ExprError();
1174 break;
1175 case Builtin::BI__builtin_operator_new:
1176 case Builtin::BI__builtin_operator_delete: {
1177 bool IsDelete = BuiltinID == Builtin::BI__builtin_operator_delete;
1178 ExprResult Res =
1179 SemaBuiltinOperatorNewDeleteOverloaded(TheCallResult, IsDelete);
1180 if (Res.isInvalid())
1181 CorrectDelayedTyposInExpr(TheCallResult.get());
1182 return Res;
1183 }
1184 case Builtin::BI__builtin_dump_struct: {
1185 // We first want to ensure we are called with 2 arguments
1186 if (checkArgCount(*this, TheCall, 2))
1187 return ExprError();
1188 // Ensure that the first argument is of type 'struct XX *'
1189 const Expr *PtrArg = TheCall->getArg(0)->IgnoreParenImpCasts();
1190 const QualType PtrArgType = PtrArg->getType();
1191 if (!PtrArgType->isPointerType() ||
1192 !PtrArgType->getPointeeType()->isRecordType()) {
1193 Diag(PtrArg->getBeginLoc(), diag::err_typecheck_convert_incompatible)
1194 << PtrArgType << "structure pointer" << 1 << 0 << 3 << 1 << PtrArgType
1195 << "structure pointer";
1196 return ExprError();
1197 }
1198
1199 // Ensure that the second argument is of type 'FunctionType'
1200 const Expr *FnPtrArg = TheCall->getArg(1)->IgnoreImpCasts();
1201 const QualType FnPtrArgType = FnPtrArg->getType();
1202 if (!FnPtrArgType->isPointerType()) {
1203 Diag(FnPtrArg->getBeginLoc(), diag::err_typecheck_convert_incompatible)
1204 << FnPtrArgType << "'int (*)(const char *, ...)'" << 1 << 0 << 3 << 2
1205 << FnPtrArgType << "'int (*)(const char *, ...)'";
1206 return ExprError();
1207 }
1208
1209 const auto *FuncType =
1210 FnPtrArgType->getPointeeType()->getAs<FunctionType>();
1211
1212 if (!FuncType) {
1213 Diag(FnPtrArg->getBeginLoc(), diag::err_typecheck_convert_incompatible)
1214 << FnPtrArgType << "'int (*)(const char *, ...)'" << 1 << 0 << 3 << 2
1215 << FnPtrArgType << "'int (*)(const char *, ...)'";
1216 return ExprError();
1217 }
1218
1219 if (const auto *FT = dyn_cast<FunctionProtoType>(FuncType)) {
1220 if (!FT->getNumParams()) {
1221 Diag(FnPtrArg->getBeginLoc(), diag::err_typecheck_convert_incompatible)
1222 << FnPtrArgType << "'int (*)(const char *, ...)'" << 1 << 0 << 3
1223 << 2 << FnPtrArgType << "'int (*)(const char *, ...)'";
1224 return ExprError();
1225 }
1226 QualType PT = FT->getParamType(0);
1227 if (!FT->isVariadic() || FT->getReturnType() != Context.IntTy ||
1228 !PT->isPointerType() || !PT->getPointeeType()->isCharType() ||
1229 !PT->getPointeeType().isConstQualified()) {
1230 Diag(FnPtrArg->getBeginLoc(), diag::err_typecheck_convert_incompatible)
1231 << FnPtrArgType << "'int (*)(const char *, ...)'" << 1 << 0 << 3
1232 << 2 << FnPtrArgType << "'int (*)(const char *, ...)'";
1233 return ExprError();
1234 }
1235 }
1236
1237 TheCall->setType(Context.IntTy);
1238 break;
1239 }
1240
1241 // check secure string manipulation functions where overflows
1242 // are detectable at compile time
1243 case Builtin::BI__builtin___memcpy_chk:
1244 SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "memcpy");
1245 break;
1246 case Builtin::BI__builtin___memmove_chk:
1247 SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "memmove");
1248 break;
1249 case Builtin::BI__builtin___memset_chk:
1250 SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "memset");
1251 break;
1252/* case Builtin::BI__builtin___strlcat_chk:
1253 SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "strlcat");
1254 break;
1255 case Builtin::BI__builtin___strlcpy_chk:
1256 SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "strlcpy");
1257 break;*/
1258 case Builtin::BI__builtin___strncat_chk:
1259 SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "strncat");
1260 break;
1261 case Builtin::BI__builtin___strncpy_chk:
1262 SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "strncpy");
1263 break;
1264 case Builtin::BI__builtin___stpncpy_chk:
1265 SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "stpncpy");
1266 break;
1267 case Builtin::BI__builtin___memccpy_chk:
1268 SemaBuiltinMemChkCall(*this, FDecl, TheCall, 3, 4, "memccpy");
1269 break;
1270 case Builtin::BI__builtin___snprintf_chk:
1271 SemaBuiltinMemChkCall(*this, FDecl, TheCall, 1, 3, "snprintf");
1272 break;
1273 case Builtin::BI__builtin___vsnprintf_chk:
1274 SemaBuiltinMemChkCall(*this, FDecl, TheCall, 1, 3, "vsnprintf");
1275 break;
1276 case Builtin::BI__builtin_call_with_static_chain:
1277 if (SemaBuiltinCallWithStaticChain(*this, TheCall))
1278 return ExprError();
1279 break;
1280 case Builtin::BI__exception_code:
1281 case Builtin::BI_exception_code:
1282 if (SemaBuiltinSEHScopeCheck(*this, TheCall, Scope::SEHExceptScope,
1283 diag::err_seh___except_block))
1284 return ExprError();
1285 break;
1286 case Builtin::BI__exception_info:
1287 case Builtin::BI_exception_info:
1288 if (SemaBuiltinSEHScopeCheck(*this, TheCall, Scope::SEHFilterScope,
1289 diag::err_seh___except_filter))
1290 return ExprError();
1291 break;
1292 case Builtin::BI__GetExceptionInfo:
1293 if (checkArgCount(*this, TheCall, 1))
1294 return ExprError();
1295
1296 if (CheckCXXThrowOperand(
1297 TheCall->getBeginLoc(),
1298 Context.getExceptionObjectType(FDecl->getParamDecl(0)->getType()),
1299 TheCall))
1300 return ExprError();
1301
1302 TheCall->setType(Context.VoidPtrTy);
1303 break;
1304 // OpenCL v2.0, s6.13.16 - Pipe functions
1305 case Builtin::BIread_pipe:
1306 case Builtin::BIwrite_pipe:
1307 // Since those two functions are declared with var args, we need a semantic
1308 // check for the argument.
1309 if (SemaBuiltinRWPipe(*this, TheCall))
1310 return ExprError();
1311 TheCall->setType(Context.IntTy);
1312 break;
1313 case Builtin::BIreserve_read_pipe:
1314 case Builtin::BIreserve_write_pipe:
1315 case Builtin::BIwork_group_reserve_read_pipe:
1316 case Builtin::BIwork_group_reserve_write_pipe:
1317 if (SemaBuiltinReserveRWPipe(*this, TheCall))
1318 return ExprError();
1319 break;
1320 case Builtin::BIsub_group_reserve_read_pipe:
1321 case Builtin::BIsub_group_reserve_write_pipe:
1322 if (checkOpenCLSubgroupExt(*this, TheCall) ||
1323 SemaBuiltinReserveRWPipe(*this, TheCall))
1324 return ExprError();
1325 break;
1326 case Builtin::BIcommit_read_pipe:
1327 case Builtin::BIcommit_write_pipe:
1328 case Builtin::BIwork_group_commit_read_pipe:
1329 case Builtin::BIwork_group_commit_write_pipe:
1330 if (SemaBuiltinCommitRWPipe(*this, TheCall))
1331 return ExprError();
1332 break;
1333 case Builtin::BIsub_group_commit_read_pipe:
1334 case Builtin::BIsub_group_commit_write_pipe:
1335 if (checkOpenCLSubgroupExt(*this, TheCall) ||
1336 SemaBuiltinCommitRWPipe(*this, TheCall))
1337 return ExprError();
1338 break;
1339 case Builtin::BIget_pipe_num_packets:
1340 case Builtin::BIget_pipe_max_packets:
1341 if (SemaBuiltinPipePackets(*this, TheCall))
1342 return ExprError();
1343 TheCall->setType(Context.UnsignedIntTy);
1344 break;
1345 case Builtin::BIto_global:
1346 case Builtin::BIto_local:
1347 case Builtin::BIto_private:
1348 if (SemaOpenCLBuiltinToAddr(*this, BuiltinID, TheCall))
1349 return ExprError();
1350 break;
1351 // OpenCL v2.0, s6.13.17 - Enqueue kernel functions.
1352 case Builtin::BIenqueue_kernel:
1353 if (SemaOpenCLBuiltinEnqueueKernel(*this, TheCall))
1354 return ExprError();
1355 break;
1356 case Builtin::BIget_kernel_work_group_size:
1357 case Builtin::BIget_kernel_preferred_work_group_size_multiple:
1358 if (SemaOpenCLBuiltinKernelWorkGroupSize(*this, TheCall))
1359 return ExprError();
1360 break;
1361 case Builtin::BIget_kernel_max_sub_group_size_for_ndrange:
1362 case Builtin::BIget_kernel_sub_group_count_for_ndrange:
1363 if (SemaOpenCLBuiltinNDRangeAndBlock(*this, TheCall))
1364 return ExprError();
1365 break;
1366 case Builtin::BI__builtin_os_log_format:
1367 case Builtin::BI__builtin_os_log_format_buffer_size:
1368 if (SemaBuiltinOSLogFormat(TheCall))
1369 return ExprError();
1370 break;
1371 }
1372
1373 // Since the target specific builtins for each arch overlap, only check those
1374 // of the arch we are compiling for.
1375 if (Context.BuiltinInfo.isTSBuiltin(BuiltinID)) {
1376 switch (Context.getTargetInfo().getTriple().getArch()) {
1377 case llvm::Triple::arm:
1378 case llvm::Triple::armeb:
1379 case llvm::Triple::thumb:
1380 case llvm::Triple::thumbeb:
1381 if (CheckARMBuiltinFunctionCall(BuiltinID, TheCall))
1382 return ExprError();
1383 break;
1384 case llvm::Triple::aarch64:
1385 case llvm::Triple::aarch64_be:
1386 if (CheckAArch64BuiltinFunctionCall(BuiltinID, TheCall))
1387 return ExprError();
1388 break;
1389 case llvm::Triple::hexagon:
1390 if (CheckHexagonBuiltinFunctionCall(BuiltinID, TheCall))
1391 return ExprError();
1392 break;
1393 case llvm::Triple::mips:
1394 case llvm::Triple::mipsel:
1395 case llvm::Triple::mips64:
1396 case llvm::Triple::mips64el:
1397 if (CheckMipsBuiltinFunctionCall(BuiltinID, TheCall))
1398 return ExprError();
1399 break;
1400 case llvm::Triple::systemz:
1401 if (CheckSystemZBuiltinFunctionCall(BuiltinID, TheCall))
1402 return ExprError();
1403 break;
1404 case llvm::Triple::x86:
1405 case llvm::Triple::x86_64:
1406 if (CheckX86BuiltinFunctionCall(BuiltinID, TheCall))
1407 return ExprError();
1408 break;
1409 case llvm::Triple::ppc:
1410 case llvm::Triple::ppc64:
1411 case llvm::Triple::ppc64le:
1412 if (CheckPPCBuiltinFunctionCall(BuiltinID, TheCall))
1413 return ExprError();
1414 break;
1415 default:
1416 break;
1417 }
1418 }
1419
1420 return TheCallResult;
1421}
1422
1423// Get the valid immediate range for the specified NEON type code.
1424static unsigned RFT(unsigned t, bool shift = false, bool ForceQuad = false) {
1425 NeonTypeFlags Type(t);
1426 int IsQuad = ForceQuad ? true : Type.isQuad();
1427 switch (Type.getEltType()) {
1428 case NeonTypeFlags::Int8:
1429 case NeonTypeFlags::Poly8:
1430 return shift ? 7 : (8 << IsQuad) - 1;
1431 case NeonTypeFlags::Int16:
1432 case NeonTypeFlags::Poly16:
1433 return shift ? 15 : (4 << IsQuad) - 1;
1434 case NeonTypeFlags::Int32:
1435 return shift ? 31 : (2 << IsQuad) - 1;
1436 case NeonTypeFlags::Int64:
1437 case NeonTypeFlags::Poly64:
1438 return shift ? 63 : (1 << IsQuad) - 1;
1439 case NeonTypeFlags::Poly128:
1440 return shift ? 127 : (1 << IsQuad) - 1;
1441 case NeonTypeFlags::Float16:
1442 assert(!shift && "cannot shift float types!")((!shift && "cannot shift float types!") ? static_cast
<void> (0) : __assert_fail ("!shift && \"cannot shift float types!\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1442, __PRETTY_FUNCTION__))
;
1443 return (4 << IsQuad) - 1;
1444 case NeonTypeFlags::Float32:
1445 assert(!shift && "cannot shift float types!")((!shift && "cannot shift float types!") ? static_cast
<void> (0) : __assert_fail ("!shift && \"cannot shift float types!\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1445, __PRETTY_FUNCTION__))
;
1446 return (2 << IsQuad) - 1;
1447 case NeonTypeFlags::Float64:
1448 assert(!shift && "cannot shift float types!")((!shift && "cannot shift float types!") ? static_cast
<void> (0) : __assert_fail ("!shift && \"cannot shift float types!\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1448, __PRETTY_FUNCTION__))
;
1449 return (1 << IsQuad) - 1;
1450 }
1451 llvm_unreachable("Invalid NeonTypeFlag!")::llvm::llvm_unreachable_internal("Invalid NeonTypeFlag!", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1451)
;
1452}
1453
1454/// getNeonEltType - Return the QualType corresponding to the elements of
1455/// the vector type specified by the NeonTypeFlags. This is used to check
1456/// the pointer arguments for Neon load/store intrinsics.
1457static QualType getNeonEltType(NeonTypeFlags Flags, ASTContext &Context,
1458 bool IsPolyUnsigned, bool IsInt64Long) {
1459 switch (Flags.getEltType()) {
1460 case NeonTypeFlags::Int8:
1461 return Flags.isUnsigned() ? Context.UnsignedCharTy : Context.SignedCharTy;
1462 case NeonTypeFlags::Int16:
1463 return Flags.isUnsigned() ? Context.UnsignedShortTy : Context.ShortTy;
1464 case NeonTypeFlags::Int32:
1465 return Flags.isUnsigned() ? Context.UnsignedIntTy : Context.IntTy;
1466 case NeonTypeFlags::Int64:
1467 if (IsInt64Long)
1468 return Flags.isUnsigned() ? Context.UnsignedLongTy : Context.LongTy;
1469 else
1470 return Flags.isUnsigned() ? Context.UnsignedLongLongTy
1471 : Context.LongLongTy;
1472 case NeonTypeFlags::Poly8:
1473 return IsPolyUnsigned ? Context.UnsignedCharTy : Context.SignedCharTy;
1474 case NeonTypeFlags::Poly16:
1475 return IsPolyUnsigned ? Context.UnsignedShortTy : Context.ShortTy;
1476 case NeonTypeFlags::Poly64:
1477 if (IsInt64Long)
1478 return Context.UnsignedLongTy;
1479 else
1480 return Context.UnsignedLongLongTy;
1481 case NeonTypeFlags::Poly128:
1482 break;
1483 case NeonTypeFlags::Float16:
1484 return Context.HalfTy;
1485 case NeonTypeFlags::Float32:
1486 return Context.FloatTy;
1487 case NeonTypeFlags::Float64:
1488 return Context.DoubleTy;
1489 }
1490 llvm_unreachable("Invalid NeonTypeFlag!")::llvm::llvm_unreachable_internal("Invalid NeonTypeFlag!", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1490)
;
1491}
1492
1493bool Sema::CheckNeonBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
1494 llvm::APSInt Result;
1495 uint64_t mask = 0;
1496 unsigned TV = 0;
1497 int PtrArgNum = -1;
1498 bool HasConstPtr = false;
1499 switch (BuiltinID) {
1500#define GET_NEON_OVERLOAD_CHECK
1501#include "clang/Basic/arm_neon.inc"
1502#include "clang/Basic/arm_fp16.inc"
1503#undef GET_NEON_OVERLOAD_CHECK
1504 }
1505
1506 // For NEON intrinsics which are overloaded on vector element type, validate
1507 // the immediate which specifies which variant to emit.
1508 unsigned ImmArg = TheCall->getNumArgs()-1;
1509 if (mask) {
1510 if (SemaBuiltinConstantArg(TheCall, ImmArg, Result))
1511 return true;
1512
1513 TV = Result.getLimitedValue(64);
1514 if ((TV > 63) || (mask & (1ULL << TV)) == 0)
1515 return Diag(TheCall->getBeginLoc(), diag::err_invalid_neon_type_code)
1516 << TheCall->getArg(ImmArg)->getSourceRange();
1517 }
1518
1519 if (PtrArgNum >= 0) {
1520 // Check that pointer arguments have the specified type.
1521 Expr *Arg = TheCall->getArg(PtrArgNum);
1522 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg))
1523 Arg = ICE->getSubExpr();
1524 ExprResult RHS = DefaultFunctionArrayLvalueConversion(Arg);
1525 QualType RHSTy = RHS.get()->getType();
1526
1527 llvm::Triple::ArchType Arch = Context.getTargetInfo().getTriple().getArch();
1528 bool IsPolyUnsigned = Arch == llvm::Triple::aarch64 ||
1529 Arch == llvm::Triple::aarch64_be;
1530 bool IsInt64Long =
1531 Context.getTargetInfo().getInt64Type() == TargetInfo::SignedLong;
1532 QualType EltTy =
1533 getNeonEltType(NeonTypeFlags(TV), Context, IsPolyUnsigned, IsInt64Long);
1534 if (HasConstPtr)
1535 EltTy = EltTy.withConst();
1536 QualType LHSTy = Context.getPointerType(EltTy);
1537 AssignConvertType ConvTy;
1538 ConvTy = CheckSingleAssignmentConstraints(LHSTy, RHS);
1539 if (RHS.isInvalid())
1540 return true;
1541 if (DiagnoseAssignmentResult(ConvTy, Arg->getBeginLoc(), LHSTy, RHSTy,
1542 RHS.get(), AA_Assigning))
1543 return true;
1544 }
1545
1546 // For NEON intrinsics which take an immediate value as part of the
1547 // instruction, range check them here.
1548 unsigned i = 0, l = 0, u = 0;
1549 switch (BuiltinID) {
1550 default:
1551 return false;
1552 #define GET_NEON_IMMEDIATE_CHECK
1553 #include "clang/Basic/arm_neon.inc"
1554 #include "clang/Basic/arm_fp16.inc"
1555 #undef GET_NEON_IMMEDIATE_CHECK
1556 }
1557
1558 return SemaBuiltinConstantArgRange(TheCall, i, l, u + l);
1559}
1560
1561bool Sema::CheckARMBuiltinExclusiveCall(unsigned BuiltinID, CallExpr *TheCall,
1562 unsigned MaxWidth) {
1563 assert((BuiltinID == ARM::BI__builtin_arm_ldrex ||(((BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM
::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex
|| BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64
::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex
|| BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID ==
AArch64::BI__builtin_arm_stlex) && "unexpected ARM builtin"
) ? static_cast<void> (0) : __assert_fail ("(BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex || BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex || BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID == AArch64::BI__builtin_arm_stlex) && \"unexpected ARM builtin\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1571, __PRETTY_FUNCTION__))
1564 BuiltinID == ARM::BI__builtin_arm_ldaex ||(((BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM
::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex
|| BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64
::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex
|| BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID ==
AArch64::BI__builtin_arm_stlex) && "unexpected ARM builtin"
) ? static_cast<void> (0) : __assert_fail ("(BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex || BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex || BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID == AArch64::BI__builtin_arm_stlex) && \"unexpected ARM builtin\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1571, __PRETTY_FUNCTION__))
1565 BuiltinID == ARM::BI__builtin_arm_strex ||(((BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM
::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex
|| BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64
::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex
|| BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID ==
AArch64::BI__builtin_arm_stlex) && "unexpected ARM builtin"
) ? static_cast<void> (0) : __assert_fail ("(BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex || BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex || BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID == AArch64::BI__builtin_arm_stlex) && \"unexpected ARM builtin\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1571, __PRETTY_FUNCTION__))
1566 BuiltinID == ARM::BI__builtin_arm_stlex ||(((BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM
::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex
|| BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64
::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex
|| BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID ==
AArch64::BI__builtin_arm_stlex) && "unexpected ARM builtin"
) ? static_cast<void> (0) : __assert_fail ("(BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex || BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex || BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID == AArch64::BI__builtin_arm_stlex) && \"unexpected ARM builtin\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1571, __PRETTY_FUNCTION__))
1567 BuiltinID == AArch64::BI__builtin_arm_ldrex ||(((BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM
::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex
|| BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64
::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex
|| BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID ==
AArch64::BI__builtin_arm_stlex) && "unexpected ARM builtin"
) ? static_cast<void> (0) : __assert_fail ("(BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex || BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex || BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID == AArch64::BI__builtin_arm_stlex) && \"unexpected ARM builtin\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1571, __PRETTY_FUNCTION__))
1568 BuiltinID == AArch64::BI__builtin_arm_ldaex ||(((BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM
::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex
|| BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64
::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex
|| BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID ==
AArch64::BI__builtin_arm_stlex) && "unexpected ARM builtin"
) ? static_cast<void> (0) : __assert_fail ("(BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex || BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex || BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID == AArch64::BI__builtin_arm_stlex) && \"unexpected ARM builtin\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1571, __PRETTY_FUNCTION__))
1569 BuiltinID == AArch64::BI__builtin_arm_strex ||(((BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM
::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex
|| BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64
::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex
|| BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID ==
AArch64::BI__builtin_arm_stlex) && "unexpected ARM builtin"
) ? static_cast<void> (0) : __assert_fail ("(BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex || BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex || BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID == AArch64::BI__builtin_arm_stlex) && \"unexpected ARM builtin\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1571, __PRETTY_FUNCTION__))
1570 BuiltinID == AArch64::BI__builtin_arm_stlex) &&(((BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM
::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex
|| BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64
::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex
|| BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID ==
AArch64::BI__builtin_arm_stlex) && "unexpected ARM builtin"
) ? static_cast<void> (0) : __assert_fail ("(BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex || BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex || BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID == AArch64::BI__builtin_arm_stlex) && \"unexpected ARM builtin\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1571, __PRETTY_FUNCTION__))
1571 "unexpected ARM builtin")(((BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM
::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex
|| BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64
::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex
|| BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID ==
AArch64::BI__builtin_arm_stlex) && "unexpected ARM builtin"
) ? static_cast<void> (0) : __assert_fail ("(BuiltinID == ARM::BI__builtin_arm_ldrex || BuiltinID == ARM::BI__builtin_arm_ldaex || BuiltinID == ARM::BI__builtin_arm_strex || BuiltinID == ARM::BI__builtin_arm_stlex || BuiltinID == AArch64::BI__builtin_arm_ldrex || BuiltinID == AArch64::BI__builtin_arm_ldaex || BuiltinID == AArch64::BI__builtin_arm_strex || BuiltinID == AArch64::BI__builtin_arm_stlex) && \"unexpected ARM builtin\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1571, __PRETTY_FUNCTION__))
;
1572 bool IsLdrex = BuiltinID == ARM::BI__builtin_arm_ldrex ||
1573 BuiltinID == ARM::BI__builtin_arm_ldaex ||
1574 BuiltinID == AArch64::BI__builtin_arm_ldrex ||
1575 BuiltinID == AArch64::BI__builtin_arm_ldaex;
1576
1577 DeclRefExpr *DRE =cast<DeclRefExpr>(TheCall->getCallee()->IgnoreParenCasts());
1578
1579 // Ensure that we have the proper number of arguments.
1580 if (checkArgCount(*this, TheCall, IsLdrex ? 1 : 2))
1581 return true;
1582
1583 // Inspect the pointer argument of the atomic builtin. This should always be
1584 // a pointer type, whose element is an integral scalar or pointer type.
1585 // Because it is a pointer type, we don't have to worry about any implicit
1586 // casts here.
1587 Expr *PointerArg = TheCall->getArg(IsLdrex ? 0 : 1);
1588 ExprResult PointerArgRes = DefaultFunctionArrayLvalueConversion(PointerArg);
1589 if (PointerArgRes.isInvalid())
1590 return true;
1591 PointerArg = PointerArgRes.get();
1592
1593 const PointerType *pointerType = PointerArg->getType()->getAs<PointerType>();
1594 if (!pointerType) {
1595 Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_must_be_pointer)
1596 << PointerArg->getType() << PointerArg->getSourceRange();
1597 return true;
1598 }
1599
1600 // ldrex takes a "const volatile T*" and strex takes a "volatile T*". Our next
1601 // task is to insert the appropriate casts into the AST. First work out just
1602 // what the appropriate type is.
1603 QualType ValType = pointerType->getPointeeType();
1604 QualType AddrType = ValType.getUnqualifiedType().withVolatile();
1605 if (IsLdrex)
1606 AddrType.addConst();
1607
1608 // Issue a warning if the cast is dodgy.
1609 CastKind CastNeeded = CK_NoOp;
1610 if (!AddrType.isAtLeastAsQualifiedAs(ValType)) {
1611 CastNeeded = CK_BitCast;
1612 Diag(DRE->getBeginLoc(), diag::ext_typecheck_convert_discards_qualifiers)
1613 << PointerArg->getType() << Context.getPointerType(AddrType)
1614 << AA_Passing << PointerArg->getSourceRange();
1615 }
1616
1617 // Finally, do the cast and replace the argument with the corrected version.
1618 AddrType = Context.getPointerType(AddrType);
1619 PointerArgRes = ImpCastExprToType(PointerArg, AddrType, CastNeeded);
1620 if (PointerArgRes.isInvalid())
1621 return true;
1622 PointerArg = PointerArgRes.get();
1623
1624 TheCall->setArg(IsLdrex ? 0 : 1, PointerArg);
1625
1626 // In general, we allow ints, floats and pointers to be loaded and stored.
1627 if (!ValType->isIntegerType() && !ValType->isAnyPointerType() &&
1628 !ValType->isBlockPointerType() && !ValType->isFloatingType()) {
1629 Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_must_be_pointer_intfltptr)
1630 << PointerArg->getType() << PointerArg->getSourceRange();
1631 return true;
1632 }
1633
1634 // But ARM doesn't have instructions to deal with 128-bit versions.
1635 if (Context.getTypeSize(ValType) > MaxWidth) {
1636 assert(MaxWidth == 64 && "Diagnostic unexpectedly inaccurate")((MaxWidth == 64 && "Diagnostic unexpectedly inaccurate"
) ? static_cast<void> (0) : __assert_fail ("MaxWidth == 64 && \"Diagnostic unexpectedly inaccurate\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 1636, __PRETTY_FUNCTION__))
;
1637 Diag(DRE->getBeginLoc(), diag::err_atomic_exclusive_builtin_pointer_size)
1638 << PointerArg->getType() << PointerArg->getSourceRange();
1639 return true;
1640 }
1641
1642 switch (ValType.getObjCLifetime()) {
1643 case Qualifiers::OCL_None:
1644 case Qualifiers::OCL_ExplicitNone:
1645 // okay
1646 break;
1647
1648 case Qualifiers::OCL_Weak:
1649 case Qualifiers::OCL_Strong:
1650 case Qualifiers::OCL_Autoreleasing:
1651 Diag(DRE->getBeginLoc(), diag::err_arc_atomic_ownership)
1652 << ValType << PointerArg->getSourceRange();
1653 return true;
1654 }
1655
1656 if (IsLdrex) {
1657 TheCall->setType(ValType);
1658 return false;
1659 }
1660
1661 // Initialize the argument to be stored.
1662 ExprResult ValArg = TheCall->getArg(0);
1663 InitializedEntity Entity = InitializedEntity::InitializeParameter(
1664 Context, ValType, /*consume*/ false);
1665 ValArg = PerformCopyInitialization(Entity, SourceLocation(), ValArg);
1666 if (ValArg.isInvalid())
1667 return true;
1668 TheCall->setArg(0, ValArg.get());
1669
1670 // __builtin_arm_strex always returns an int. It's marked as such in the .def,
1671 // but the custom checker bypasses all default analysis.
1672 TheCall->setType(Context.IntTy);
1673 return false;
1674}
1675
1676bool Sema::CheckARMBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
1677 if (BuiltinID == ARM::BI__builtin_arm_ldrex ||
1678 BuiltinID == ARM::BI__builtin_arm_ldaex ||
1679 BuiltinID == ARM::BI__builtin_arm_strex ||
1680 BuiltinID == ARM::BI__builtin_arm_stlex) {
1681 return CheckARMBuiltinExclusiveCall(BuiltinID, TheCall, 64);
1682 }
1683
1684 if (BuiltinID == ARM::BI__builtin_arm_prefetch) {
1685 return SemaBuiltinConstantArgRange(TheCall, 1, 0, 1) ||
1686 SemaBuiltinConstantArgRange(TheCall, 2, 0, 1);
1687 }
1688
1689 if (BuiltinID == ARM::BI__builtin_arm_rsr64 ||
1690 BuiltinID == ARM::BI__builtin_arm_wsr64)
1691 return SemaBuiltinARMSpecialReg(BuiltinID, TheCall, 0, 3, false);
1692
1693 if (BuiltinID == ARM::BI__builtin_arm_rsr ||
1694 BuiltinID == ARM::BI__builtin_arm_rsrp ||
1695 BuiltinID == ARM::BI__builtin_arm_wsr ||
1696 BuiltinID == ARM::BI__builtin_arm_wsrp)
1697 return SemaBuiltinARMSpecialReg(BuiltinID, TheCall, 0, 5, true);
1698
1699 if (CheckNeonBuiltinFunctionCall(BuiltinID, TheCall))
1700 return true;
1701
1702 // For intrinsics which take an immediate value as part of the instruction,
1703 // range check them here.
1704 // FIXME: VFP Intrinsics should error if VFP not present.
1705 switch (BuiltinID) {
1706 default: return false;
1707 case ARM::BI__builtin_arm_ssat:
1708 return SemaBuiltinConstantArgRange(TheCall, 1, 1, 32);
1709 case ARM::BI__builtin_arm_usat:
1710 return SemaBuiltinConstantArgRange(TheCall, 1, 0, 31);
1711 case ARM::BI__builtin_arm_ssat16:
1712 return SemaBuiltinConstantArgRange(TheCall, 1, 1, 16);
1713 case ARM::BI__builtin_arm_usat16:
1714 return SemaBuiltinConstantArgRange(TheCall, 1, 0, 15);
1715 case ARM::BI__builtin_arm_vcvtr_f:
1716 case ARM::BI__builtin_arm_vcvtr_d:
1717 return SemaBuiltinConstantArgRange(TheCall, 1, 0, 1);
1718 case ARM::BI__builtin_arm_dmb:
1719 case ARM::BI__builtin_arm_dsb:
1720 case ARM::BI__builtin_arm_isb:
1721 case ARM::BI__builtin_arm_dbg:
1722 return SemaBuiltinConstantArgRange(TheCall, 0, 0, 15);
1723 }
1724}
1725
1726bool Sema::CheckAArch64BuiltinFunctionCall(unsigned BuiltinID,
1727 CallExpr *TheCall) {
1728 if (BuiltinID == AArch64::BI__builtin_arm_ldrex ||
1729 BuiltinID == AArch64::BI__builtin_arm_ldaex ||
1730 BuiltinID == AArch64::BI__builtin_arm_strex ||
1731 BuiltinID == AArch64::BI__builtin_arm_stlex) {
1732 return CheckARMBuiltinExclusiveCall(BuiltinID, TheCall, 128);
1733 }
1734
1735 if (BuiltinID == AArch64::BI__builtin_arm_prefetch) {
1736 return SemaBuiltinConstantArgRange(TheCall, 1, 0, 1) ||
1737 SemaBuiltinConstantArgRange(TheCall, 2, 0, 2) ||
1738 SemaBuiltinConstantArgRange(TheCall, 3, 0, 1) ||
1739 SemaBuiltinConstantArgRange(TheCall, 4, 0, 1);
1740 }
1741
1742 if (BuiltinID == AArch64::BI__builtin_arm_rsr64 ||
1743 BuiltinID == AArch64::BI__builtin_arm_wsr64)
1744 return SemaBuiltinARMSpecialReg(BuiltinID, TheCall, 0, 5, true);
1745
1746 if (BuiltinID == AArch64::BI__builtin_arm_rsr ||
1747 BuiltinID == AArch64::BI__builtin_arm_rsrp ||
1748 BuiltinID == AArch64::BI__builtin_arm_wsr ||
1749 BuiltinID == AArch64::BI__builtin_arm_wsrp)
1750 return SemaBuiltinARMSpecialReg(BuiltinID, TheCall, 0, 5, true);
1751
1752 // Only check the valid encoding range. Any constant in this range would be
1753 // converted to a register of the form S1_2_C3_C4_5. Let the hardware throw
1754 // an exception for incorrect registers. This matches MSVC behavior.
1755 if (BuiltinID == AArch64::BI_ReadStatusReg ||
1756 BuiltinID == AArch64::BI_WriteStatusReg)
1757 return SemaBuiltinConstantArgRange(TheCall, 0, 0, 0x7fff);
1758
1759 if (BuiltinID == AArch64::BI__getReg)
1760 return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31);
1761
1762 if (CheckNeonBuiltinFunctionCall(BuiltinID, TheCall))
1763 return true;
1764
1765 // For intrinsics which take an immediate value as part of the instruction,
1766 // range check them here.
1767 unsigned i = 0, l = 0, u = 0;
1768 switch (BuiltinID) {
1769 default: return false;
1770 case AArch64::BI__builtin_arm_dmb:
1771 case AArch64::BI__builtin_arm_dsb:
1772 case AArch64::BI__builtin_arm_isb: l = 0; u = 15; break;
1773 }
1774
1775 return SemaBuiltinConstantArgRange(TheCall, i, l, u + l);
1776}
1777
1778bool Sema::CheckHexagonBuiltinCpu(unsigned BuiltinID, CallExpr *TheCall) {
1779 struct BuiltinAndString {
1780 unsigned BuiltinID;
1781 const char *Str;
1782 };
1783
1784 static BuiltinAndString ValidCPU[] = {
1785 { Hexagon::BI__builtin_HEXAGON_A6_vcmpbeq_notany, "v65" },
1786 { Hexagon::BI__builtin_HEXAGON_A6_vminub_RdP, "v62,v65" },
1787 { Hexagon::BI__builtin_HEXAGON_M6_vabsdiffb, "v62,v65" },
1788 { Hexagon::BI__builtin_HEXAGON_M6_vabsdiffub, "v62,v65" },
1789 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_acc, "v60,v62,v65" },
1790 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_and, "v60,v62,v65" },
1791 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_nac, "v60,v62,v65" },
1792 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_or, "v60,v62,v65" },
1793 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p, "v60,v62,v65" },
1794 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_xacc, "v60,v62,v65" },
1795 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_acc, "v60,v62,v65" },
1796 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_and, "v60,v62,v65" },
1797 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_nac, "v60,v62,v65" },
1798 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_or, "v60,v62,v65" },
1799 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r, "v60,v62,v65" },
1800 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_xacc, "v60,v62,v65" },
1801 { Hexagon::BI__builtin_HEXAGON_S6_vsplatrbp, "v62,v65" },
1802 { Hexagon::BI__builtin_HEXAGON_S6_vtrunehb_ppp, "v62,v65" },
1803 { Hexagon::BI__builtin_HEXAGON_S6_vtrunohb_ppp, "v62,v65" },
1804 };
1805
1806 static BuiltinAndString ValidHVX[] = {
1807 { Hexagon::BI__builtin_HEXAGON_V6_extractw, "v60,v62,v65" },
1808 { Hexagon::BI__builtin_HEXAGON_V6_extractw_128B, "v60,v62,v65" },
1809 { Hexagon::BI__builtin_HEXAGON_V6_hi, "v60,v62,v65" },
1810 { Hexagon::BI__builtin_HEXAGON_V6_hi_128B, "v60,v62,v65" },
1811 { Hexagon::BI__builtin_HEXAGON_V6_lo, "v60,v62,v65" },
1812 { Hexagon::BI__builtin_HEXAGON_V6_lo_128B, "v60,v62,v65" },
1813 { Hexagon::BI__builtin_HEXAGON_V6_lvsplatb, "v62,v65" },
1814 { Hexagon::BI__builtin_HEXAGON_V6_lvsplatb_128B, "v62,v65" },
1815 { Hexagon::BI__builtin_HEXAGON_V6_lvsplath, "v62,v65" },
1816 { Hexagon::BI__builtin_HEXAGON_V6_lvsplath_128B, "v62,v65" },
1817 { Hexagon::BI__builtin_HEXAGON_V6_lvsplatw, "v60,v62,v65" },
1818 { Hexagon::BI__builtin_HEXAGON_V6_lvsplatw_128B, "v60,v62,v65" },
1819 { Hexagon::BI__builtin_HEXAGON_V6_pred_and, "v60,v62,v65" },
1820 { Hexagon::BI__builtin_HEXAGON_V6_pred_and_128B, "v60,v62,v65" },
1821 { Hexagon::BI__builtin_HEXAGON_V6_pred_and_n, "v60,v62,v65" },
1822 { Hexagon::BI__builtin_HEXAGON_V6_pred_and_n_128B, "v60,v62,v65" },
1823 { Hexagon::BI__builtin_HEXAGON_V6_pred_not, "v60,v62,v65" },
1824 { Hexagon::BI__builtin_HEXAGON_V6_pred_not_128B, "v60,v62,v65" },
1825 { Hexagon::BI__builtin_HEXAGON_V6_pred_or, "v60,v62,v65" },
1826 { Hexagon::BI__builtin_HEXAGON_V6_pred_or_128B, "v60,v62,v65" },
1827 { Hexagon::BI__builtin_HEXAGON_V6_pred_or_n, "v60,v62,v65" },
1828 { Hexagon::BI__builtin_HEXAGON_V6_pred_or_n_128B, "v60,v62,v65" },
1829 { Hexagon::BI__builtin_HEXAGON_V6_pred_scalar2, "v60,v62,v65" },
1830 { Hexagon::BI__builtin_HEXAGON_V6_pred_scalar2_128B, "v60,v62,v65" },
1831 { Hexagon::BI__builtin_HEXAGON_V6_pred_scalar2v2, "v62,v65" },
1832 { Hexagon::BI__builtin_HEXAGON_V6_pred_scalar2v2_128B, "v62,v65" },
1833 { Hexagon::BI__builtin_HEXAGON_V6_pred_xor, "v60,v62,v65" },
1834 { Hexagon::BI__builtin_HEXAGON_V6_pred_xor_128B, "v60,v62,v65" },
1835 { Hexagon::BI__builtin_HEXAGON_V6_shuffeqh, "v62,v65" },
1836 { Hexagon::BI__builtin_HEXAGON_V6_shuffeqh_128B, "v62,v65" },
1837 { Hexagon::BI__builtin_HEXAGON_V6_shuffeqw, "v62,v65" },
1838 { Hexagon::BI__builtin_HEXAGON_V6_shuffeqw_128B, "v62,v65" },
1839 { Hexagon::BI__builtin_HEXAGON_V6_vabsb, "v65" },
1840 { Hexagon::BI__builtin_HEXAGON_V6_vabsb_128B, "v65" },
1841 { Hexagon::BI__builtin_HEXAGON_V6_vabsb_sat, "v65" },
1842 { Hexagon::BI__builtin_HEXAGON_V6_vabsb_sat_128B, "v65" },
1843 { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffh, "v60,v62,v65" },
1844 { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffh_128B, "v60,v62,v65" },
1845 { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffub, "v60,v62,v65" },
1846 { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffub_128B, "v60,v62,v65" },
1847 { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffuh, "v60,v62,v65" },
1848 { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffuh_128B, "v60,v62,v65" },
1849 { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffw, "v60,v62,v65" },
1850 { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffw_128B, "v60,v62,v65" },
1851 { Hexagon::BI__builtin_HEXAGON_V6_vabsh, "v60,v62,v65" },
1852 { Hexagon::BI__builtin_HEXAGON_V6_vabsh_128B, "v60,v62,v65" },
1853 { Hexagon::BI__builtin_HEXAGON_V6_vabsh_sat, "v60,v62,v65" },
1854 { Hexagon::BI__builtin_HEXAGON_V6_vabsh_sat_128B, "v60,v62,v65" },
1855 { Hexagon::BI__builtin_HEXAGON_V6_vabsw, "v60,v62,v65" },
1856 { Hexagon::BI__builtin_HEXAGON_V6_vabsw_128B, "v60,v62,v65" },
1857 { Hexagon::BI__builtin_HEXAGON_V6_vabsw_sat, "v60,v62,v65" },
1858 { Hexagon::BI__builtin_HEXAGON_V6_vabsw_sat_128B, "v60,v62,v65" },
1859 { Hexagon::BI__builtin_HEXAGON_V6_vaddb, "v60,v62,v65" },
1860 { Hexagon::BI__builtin_HEXAGON_V6_vaddb_128B, "v60,v62,v65" },
1861 { Hexagon::BI__builtin_HEXAGON_V6_vaddb_dv, "v60,v62,v65" },
1862 { Hexagon::BI__builtin_HEXAGON_V6_vaddb_dv_128B, "v60,v62,v65" },
1863 { Hexagon::BI__builtin_HEXAGON_V6_vaddbsat, "v62,v65" },
1864 { Hexagon::BI__builtin_HEXAGON_V6_vaddbsat_128B, "v62,v65" },
1865 { Hexagon::BI__builtin_HEXAGON_V6_vaddbsat_dv, "v62,v65" },
1866 { Hexagon::BI__builtin_HEXAGON_V6_vaddbsat_dv_128B, "v62,v65" },
1867 { Hexagon::BI__builtin_HEXAGON_V6_vaddcarry, "v62,v65" },
1868 { Hexagon::BI__builtin_HEXAGON_V6_vaddcarry_128B, "v62,v65" },
1869 { Hexagon::BI__builtin_HEXAGON_V6_vaddclbh, "v62,v65" },
1870 { Hexagon::BI__builtin_HEXAGON_V6_vaddclbh_128B, "v62,v65" },
1871 { Hexagon::BI__builtin_HEXAGON_V6_vaddclbw, "v62,v65" },
1872 { Hexagon::BI__builtin_HEXAGON_V6_vaddclbw_128B, "v62,v65" },
1873 { Hexagon::BI__builtin_HEXAGON_V6_vaddh, "v60,v62,v65" },
1874 { Hexagon::BI__builtin_HEXAGON_V6_vaddh_128B, "v60,v62,v65" },
1875 { Hexagon::BI__builtin_HEXAGON_V6_vaddh_dv, "v60,v62,v65" },
1876 { Hexagon::BI__builtin_HEXAGON_V6_vaddh_dv_128B, "v60,v62,v65" },
1877 { Hexagon::BI__builtin_HEXAGON_V6_vaddhsat, "v60,v62,v65" },
1878 { Hexagon::BI__builtin_HEXAGON_V6_vaddhsat_128B, "v60,v62,v65" },
1879 { Hexagon::BI__builtin_HEXAGON_V6_vaddhsat_dv, "v60,v62,v65" },
1880 { Hexagon::BI__builtin_HEXAGON_V6_vaddhsat_dv_128B, "v60,v62,v65" },
1881 { Hexagon::BI__builtin_HEXAGON_V6_vaddhw, "v60,v62,v65" },
1882 { Hexagon::BI__builtin_HEXAGON_V6_vaddhw_128B, "v60,v62,v65" },
1883 { Hexagon::BI__builtin_HEXAGON_V6_vaddhw_acc, "v62,v65" },
1884 { Hexagon::BI__builtin_HEXAGON_V6_vaddhw_acc_128B, "v62,v65" },
1885 { Hexagon::BI__builtin_HEXAGON_V6_vaddubh, "v60,v62,v65" },
1886 { Hexagon::BI__builtin_HEXAGON_V6_vaddubh_128B, "v60,v62,v65" },
1887 { Hexagon::BI__builtin_HEXAGON_V6_vaddubh_acc, "v62,v65" },
1888 { Hexagon::BI__builtin_HEXAGON_V6_vaddubh_acc_128B, "v62,v65" },
1889 { Hexagon::BI__builtin_HEXAGON_V6_vaddubsat, "v60,v62,v65" },
1890 { Hexagon::BI__builtin_HEXAGON_V6_vaddubsat_128B, "v60,v62,v65" },
1891 { Hexagon::BI__builtin_HEXAGON_V6_vaddubsat_dv, "v60,v62,v65" },
1892 { Hexagon::BI__builtin_HEXAGON_V6_vaddubsat_dv_128B, "v60,v62,v65" },
1893 { Hexagon::BI__builtin_HEXAGON_V6_vaddububb_sat, "v62,v65" },
1894 { Hexagon::BI__builtin_HEXAGON_V6_vaddububb_sat_128B, "v62,v65" },
1895 { Hexagon::BI__builtin_HEXAGON_V6_vadduhsat, "v60,v62,v65" },
1896 { Hexagon::BI__builtin_HEXAGON_V6_vadduhsat_128B, "v60,v62,v65" },
1897 { Hexagon::BI__builtin_HEXAGON_V6_vadduhsat_dv, "v60,v62,v65" },
1898 { Hexagon::BI__builtin_HEXAGON_V6_vadduhsat_dv_128B, "v60,v62,v65" },
1899 { Hexagon::BI__builtin_HEXAGON_V6_vadduhw, "v60,v62,v65" },
1900 { Hexagon::BI__builtin_HEXAGON_V6_vadduhw_128B, "v60,v62,v65" },
1901 { Hexagon::BI__builtin_HEXAGON_V6_vadduhw_acc, "v62,v65" },
1902 { Hexagon::BI__builtin_HEXAGON_V6_vadduhw_acc_128B, "v62,v65" },
1903 { Hexagon::BI__builtin_HEXAGON_V6_vadduwsat, "v62,v65" },
1904 { Hexagon::BI__builtin_HEXAGON_V6_vadduwsat_128B, "v62,v65" },
1905 { Hexagon::BI__builtin_HEXAGON_V6_vadduwsat_dv, "v62,v65" },
1906 { Hexagon::BI__builtin_HEXAGON_V6_vadduwsat_dv_128B, "v62,v65" },
1907 { Hexagon::BI__builtin_HEXAGON_V6_vaddw, "v60,v62,v65" },
1908 { Hexagon::BI__builtin_HEXAGON_V6_vaddw_128B, "v60,v62,v65" },
1909 { Hexagon::BI__builtin_HEXAGON_V6_vaddw_dv, "v60,v62,v65" },
1910 { Hexagon::BI__builtin_HEXAGON_V6_vaddw_dv_128B, "v60,v62,v65" },
1911 { Hexagon::BI__builtin_HEXAGON_V6_vaddwsat, "v60,v62,v65" },
1912 { Hexagon::BI__builtin_HEXAGON_V6_vaddwsat_128B, "v60,v62,v65" },
1913 { Hexagon::BI__builtin_HEXAGON_V6_vaddwsat_dv, "v60,v62,v65" },
1914 { Hexagon::BI__builtin_HEXAGON_V6_vaddwsat_dv_128B, "v60,v62,v65" },
1915 { Hexagon::BI__builtin_HEXAGON_V6_valignb, "v60,v62,v65" },
1916 { Hexagon::BI__builtin_HEXAGON_V6_valignb_128B, "v60,v62,v65" },
1917 { Hexagon::BI__builtin_HEXAGON_V6_valignbi, "v60,v62,v65" },
1918 { Hexagon::BI__builtin_HEXAGON_V6_valignbi_128B, "v60,v62,v65" },
1919 { Hexagon::BI__builtin_HEXAGON_V6_vand, "v60,v62,v65" },
1920 { Hexagon::BI__builtin_HEXAGON_V6_vand_128B, "v60,v62,v65" },
1921 { Hexagon::BI__builtin_HEXAGON_V6_vandnqrt, "v62,v65" },
1922 { Hexagon::BI__builtin_HEXAGON_V6_vandnqrt_128B, "v62,v65" },
1923 { Hexagon::BI__builtin_HEXAGON_V6_vandnqrt_acc, "v62,v65" },
1924 { Hexagon::BI__builtin_HEXAGON_V6_vandnqrt_acc_128B, "v62,v65" },
1925 { Hexagon::BI__builtin_HEXAGON_V6_vandqrt, "v60,v62,v65" },
1926 { Hexagon::BI__builtin_HEXAGON_V6_vandqrt_128B, "v60,v62,v65" },
1927 { Hexagon::BI__builtin_HEXAGON_V6_vandqrt_acc, "v60,v62,v65" },
1928 { Hexagon::BI__builtin_HEXAGON_V6_vandqrt_acc_128B, "v60,v62,v65" },
1929 { Hexagon::BI__builtin_HEXAGON_V6_vandvnqv, "v62,v65" },
1930 { Hexagon::BI__builtin_HEXAGON_V6_vandvnqv_128B, "v62,v65" },
1931 { Hexagon::BI__builtin_HEXAGON_V6_vandvqv, "v62,v65" },
1932 { Hexagon::BI__builtin_HEXAGON_V6_vandvqv_128B, "v62,v65" },
1933 { Hexagon::BI__builtin_HEXAGON_V6_vandvrt, "v60,v62,v65" },
1934 { Hexagon::BI__builtin_HEXAGON_V6_vandvrt_128B, "v60,v62,v65" },
1935 { Hexagon::BI__builtin_HEXAGON_V6_vandvrt_acc, "v60,v62,v65" },
1936 { Hexagon::BI__builtin_HEXAGON_V6_vandvrt_acc_128B, "v60,v62,v65" },
1937 { Hexagon::BI__builtin_HEXAGON_V6_vaslh, "v60,v62,v65" },
1938 { Hexagon::BI__builtin_HEXAGON_V6_vaslh_128B, "v60,v62,v65" },
1939 { Hexagon::BI__builtin_HEXAGON_V6_vaslh_acc, "v65" },
1940 { Hexagon::BI__builtin_HEXAGON_V6_vaslh_acc_128B, "v65" },
1941 { Hexagon::BI__builtin_HEXAGON_V6_vaslhv, "v60,v62,v65" },
1942 { Hexagon::BI__builtin_HEXAGON_V6_vaslhv_128B, "v60,v62,v65" },
1943 { Hexagon::BI__builtin_HEXAGON_V6_vaslw, "v60,v62,v65" },
1944 { Hexagon::BI__builtin_HEXAGON_V6_vaslw_128B, "v60,v62,v65" },
1945 { Hexagon::BI__builtin_HEXAGON_V6_vaslw_acc, "v60,v62,v65" },
1946 { Hexagon::BI__builtin_HEXAGON_V6_vaslw_acc_128B, "v60,v62,v65" },
1947 { Hexagon::BI__builtin_HEXAGON_V6_vaslwv, "v60,v62,v65" },
1948 { Hexagon::BI__builtin_HEXAGON_V6_vaslwv_128B, "v60,v62,v65" },
1949 { Hexagon::BI__builtin_HEXAGON_V6_vasrh, "v60,v62,v65" },
1950 { Hexagon::BI__builtin_HEXAGON_V6_vasrh_128B, "v60,v62,v65" },
1951 { Hexagon::BI__builtin_HEXAGON_V6_vasrh_acc, "v65" },
1952 { Hexagon::BI__builtin_HEXAGON_V6_vasrh_acc_128B, "v65" },
1953 { Hexagon::BI__builtin_HEXAGON_V6_vasrhbrndsat, "v60,v62,v65" },
1954 { Hexagon::BI__builtin_HEXAGON_V6_vasrhbrndsat_128B, "v60,v62,v65" },
1955 { Hexagon::BI__builtin_HEXAGON_V6_vasrhbsat, "v62,v65" },
1956 { Hexagon::BI__builtin_HEXAGON_V6_vasrhbsat_128B, "v62,v65" },
1957 { Hexagon::BI__builtin_HEXAGON_V6_vasrhubrndsat, "v60,v62,v65" },
1958 { Hexagon::BI__builtin_HEXAGON_V6_vasrhubrndsat_128B, "v60,v62,v65" },
1959 { Hexagon::BI__builtin_HEXAGON_V6_vasrhubsat, "v60,v62,v65" },
1960 { Hexagon::BI__builtin_HEXAGON_V6_vasrhubsat_128B, "v60,v62,v65" },
1961 { Hexagon::BI__builtin_HEXAGON_V6_vasrhv, "v60,v62,v65" },
1962 { Hexagon::BI__builtin_HEXAGON_V6_vasrhv_128B, "v60,v62,v65" },
1963 { Hexagon::BI__builtin_HEXAGON_V6_vasruhubrndsat, "v65" },
1964 { Hexagon::BI__builtin_HEXAGON_V6_vasruhubrndsat_128B, "v65" },
1965 { Hexagon::BI__builtin_HEXAGON_V6_vasruhubsat, "v65" },
1966 { Hexagon::BI__builtin_HEXAGON_V6_vasruhubsat_128B, "v65" },
1967 { Hexagon::BI__builtin_HEXAGON_V6_vasruwuhrndsat, "v62,v65" },
1968 { Hexagon::BI__builtin_HEXAGON_V6_vasruwuhrndsat_128B, "v62,v65" },
1969 { Hexagon::BI__builtin_HEXAGON_V6_vasruwuhsat, "v65" },
1970 { Hexagon::BI__builtin_HEXAGON_V6_vasruwuhsat_128B, "v65" },
1971 { Hexagon::BI__builtin_HEXAGON_V6_vasrw, "v60,v62,v65" },
1972 { Hexagon::BI__builtin_HEXAGON_V6_vasrw_128B, "v60,v62,v65" },
1973 { Hexagon::BI__builtin_HEXAGON_V6_vasrw_acc, "v60,v62,v65" },
1974 { Hexagon::BI__builtin_HEXAGON_V6_vasrw_acc_128B, "v60,v62,v65" },
1975 { Hexagon::BI__builtin_HEXAGON_V6_vasrwh, "v60,v62,v65" },
1976 { Hexagon::BI__builtin_HEXAGON_V6_vasrwh_128B, "v60,v62,v65" },
1977 { Hexagon::BI__builtin_HEXAGON_V6_vasrwhrndsat, "v60,v62,v65" },
1978 { Hexagon::BI__builtin_HEXAGON_V6_vasrwhrndsat_128B, "v60,v62,v65" },
1979 { Hexagon::BI__builtin_HEXAGON_V6_vasrwhsat, "v60,v62,v65" },
1980 { Hexagon::BI__builtin_HEXAGON_V6_vasrwhsat_128B, "v60,v62,v65" },
1981 { Hexagon::BI__builtin_HEXAGON_V6_vasrwuhrndsat, "v62,v65" },
1982 { Hexagon::BI__builtin_HEXAGON_V6_vasrwuhrndsat_128B, "v62,v65" },
1983 { Hexagon::BI__builtin_HEXAGON_V6_vasrwuhsat, "v60,v62,v65" },
1984 { Hexagon::BI__builtin_HEXAGON_V6_vasrwuhsat_128B, "v60,v62,v65" },
1985 { Hexagon::BI__builtin_HEXAGON_V6_vasrwv, "v60,v62,v65" },
1986 { Hexagon::BI__builtin_HEXAGON_V6_vasrwv_128B, "v60,v62,v65" },
1987 { Hexagon::BI__builtin_HEXAGON_V6_vassign, "v60,v62,v65" },
1988 { Hexagon::BI__builtin_HEXAGON_V6_vassign_128B, "v60,v62,v65" },
1989 { Hexagon::BI__builtin_HEXAGON_V6_vassignp, "v60,v62,v65" },
1990 { Hexagon::BI__builtin_HEXAGON_V6_vassignp_128B, "v60,v62,v65" },
1991 { Hexagon::BI__builtin_HEXAGON_V6_vavgb, "v65" },
1992 { Hexagon::BI__builtin_HEXAGON_V6_vavgb_128B, "v65" },
1993 { Hexagon::BI__builtin_HEXAGON_V6_vavgbrnd, "v65" },
1994 { Hexagon::BI__builtin_HEXAGON_V6_vavgbrnd_128B, "v65" },
1995 { Hexagon::BI__builtin_HEXAGON_V6_vavgh, "v60,v62,v65" },
1996 { Hexagon::BI__builtin_HEXAGON_V6_vavgh_128B, "v60,v62,v65" },
1997 { Hexagon::BI__builtin_HEXAGON_V6_vavghrnd, "v60,v62,v65" },
1998 { Hexagon::BI__builtin_HEXAGON_V6_vavghrnd_128B, "v60,v62,v65" },
1999 { Hexagon::BI__builtin_HEXAGON_V6_vavgub, "v60,v62,v65" },
2000 { Hexagon::BI__builtin_HEXAGON_V6_vavgub_128B, "v60,v62,v65" },
2001 { Hexagon::BI__builtin_HEXAGON_V6_vavgubrnd, "v60,v62,v65" },
2002 { Hexagon::BI__builtin_HEXAGON_V6_vavgubrnd_128B, "v60,v62,v65" },
2003 { Hexagon::BI__builtin_HEXAGON_V6_vavguh, "v60,v62,v65" },
2004 { Hexagon::BI__builtin_HEXAGON_V6_vavguh_128B, "v60,v62,v65" },
2005 { Hexagon::BI__builtin_HEXAGON_V6_vavguhrnd, "v60,v62,v65" },
2006 { Hexagon::BI__builtin_HEXAGON_V6_vavguhrnd_128B, "v60,v62,v65" },
2007 { Hexagon::BI__builtin_HEXAGON_V6_vavguw, "v65" },
2008 { Hexagon::BI__builtin_HEXAGON_V6_vavguw_128B, "v65" },
2009 { Hexagon::BI__builtin_HEXAGON_V6_vavguwrnd, "v65" },
2010 { Hexagon::BI__builtin_HEXAGON_V6_vavguwrnd_128B, "v65" },
2011 { Hexagon::BI__builtin_HEXAGON_V6_vavgw, "v60,v62,v65" },
2012 { Hexagon::BI__builtin_HEXAGON_V6_vavgw_128B, "v60,v62,v65" },
2013 { Hexagon::BI__builtin_HEXAGON_V6_vavgwrnd, "v60,v62,v65" },
2014 { Hexagon::BI__builtin_HEXAGON_V6_vavgwrnd_128B, "v60,v62,v65" },
2015 { Hexagon::BI__builtin_HEXAGON_V6_vcl0h, "v60,v62,v65" },
2016 { Hexagon::BI__builtin_HEXAGON_V6_vcl0h_128B, "v60,v62,v65" },
2017 { Hexagon::BI__builtin_HEXAGON_V6_vcl0w, "v60,v62,v65" },
2018 { Hexagon::BI__builtin_HEXAGON_V6_vcl0w_128B, "v60,v62,v65" },
2019 { Hexagon::BI__builtin_HEXAGON_V6_vcombine, "v60,v62,v65" },
2020 { Hexagon::BI__builtin_HEXAGON_V6_vcombine_128B, "v60,v62,v65" },
2021 { Hexagon::BI__builtin_HEXAGON_V6_vd0, "v60,v62,v65" },
2022 { Hexagon::BI__builtin_HEXAGON_V6_vd0_128B, "v60,v62,v65" },
2023 { Hexagon::BI__builtin_HEXAGON_V6_vdd0, "v65" },
2024 { Hexagon::BI__builtin_HEXAGON_V6_vdd0_128B, "v65" },
2025 { Hexagon::BI__builtin_HEXAGON_V6_vdealb, "v60,v62,v65" },
2026 { Hexagon::BI__builtin_HEXAGON_V6_vdealb_128B, "v60,v62,v65" },
2027 { Hexagon::BI__builtin_HEXAGON_V6_vdealb4w, "v60,v62,v65" },
2028 { Hexagon::BI__builtin_HEXAGON_V6_vdealb4w_128B, "v60,v62,v65" },
2029 { Hexagon::BI__builtin_HEXAGON_V6_vdealh, "v60,v62,v65" },
2030 { Hexagon::BI__builtin_HEXAGON_V6_vdealh_128B, "v60,v62,v65" },
2031 { Hexagon::BI__builtin_HEXAGON_V6_vdealvdd, "v60,v62,v65" },
2032 { Hexagon::BI__builtin_HEXAGON_V6_vdealvdd_128B, "v60,v62,v65" },
2033 { Hexagon::BI__builtin_HEXAGON_V6_vdelta, "v60,v62,v65" },
2034 { Hexagon::BI__builtin_HEXAGON_V6_vdelta_128B, "v60,v62,v65" },
2035 { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus, "v60,v62,v65" },
2036 { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus_128B, "v60,v62,v65" },
2037 { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus_acc, "v60,v62,v65" },
2038 { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus_acc_128B, "v60,v62,v65" },
2039 { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus_dv, "v60,v62,v65" },
2040 { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus_dv_128B, "v60,v62,v65" },
2041 { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus_dv_acc, "v60,v62,v65" },
2042 { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus_dv_acc_128B, "v60,v62,v65" },
2043 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb, "v60,v62,v65" },
2044 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb_128B, "v60,v62,v65" },
2045 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb_acc, "v60,v62,v65" },
2046 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb_acc_128B, "v60,v62,v65" },
2047 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb_dv, "v60,v62,v65" },
2048 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb_dv_128B, "v60,v62,v65" },
2049 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb_dv_acc, "v60,v62,v65" },
2050 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb_dv_acc_128B, "v60,v62,v65" },
2051 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhisat, "v60,v62,v65" },
2052 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhisat_128B, "v60,v62,v65" },
2053 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhisat_acc, "v60,v62,v65" },
2054 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhisat_acc_128B, "v60,v62,v65" },
2055 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsat, "v60,v62,v65" },
2056 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsat_128B, "v60,v62,v65" },
2057 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsat_acc, "v60,v62,v65" },
2058 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsat_acc_128B, "v60,v62,v65" },
2059 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsuisat, "v60,v62,v65" },
2060 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsuisat_128B, "v60,v62,v65" },
2061 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsuisat_acc, "v60,v62,v65" },
2062 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsuisat_acc_128B, "v60,v62,v65" },
2063 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsusat, "v60,v62,v65" },
2064 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsusat_128B, "v60,v62,v65" },
2065 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsusat_acc, "v60,v62,v65" },
2066 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsusat_acc_128B, "v60,v62,v65" },
2067 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhvsat, "v60,v62,v65" },
2068 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhvsat_128B, "v60,v62,v65" },
2069 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhvsat_acc, "v60,v62,v65" },
2070 { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhvsat_acc_128B, "v60,v62,v65" },
2071 { Hexagon::BI__builtin_HEXAGON_V6_vdsaduh, "v60,v62,v65" },
2072 { Hexagon::BI__builtin_HEXAGON_V6_vdsaduh_128B, "v60,v62,v65" },
2073 { Hexagon::BI__builtin_HEXAGON_V6_vdsaduh_acc, "v60,v62,v65" },
2074 { Hexagon::BI__builtin_HEXAGON_V6_vdsaduh_acc_128B, "v60,v62,v65" },
2075 { Hexagon::BI__builtin_HEXAGON_V6_veqb, "v60,v62,v65" },
2076 { Hexagon::BI__builtin_HEXAGON_V6_veqb_128B, "v60,v62,v65" },
2077 { Hexagon::BI__builtin_HEXAGON_V6_veqb_and, "v60,v62,v65" },
2078 { Hexagon::BI__builtin_HEXAGON_V6_veqb_and_128B, "v60,v62,v65" },
2079 { Hexagon::BI__builtin_HEXAGON_V6_veqb_or, "v60,v62,v65" },
2080 { Hexagon::BI__builtin_HEXAGON_V6_veqb_or_128B, "v60,v62,v65" },
2081 { Hexagon::BI__builtin_HEXAGON_V6_veqb_xor, "v60,v62,v65" },
2082 { Hexagon::BI__builtin_HEXAGON_V6_veqb_xor_128B, "v60,v62,v65" },
2083 { Hexagon::BI__builtin_HEXAGON_V6_veqh, "v60,v62,v65" },
2084 { Hexagon::BI__builtin_HEXAGON_V6_veqh_128B, "v60,v62,v65" },
2085 { Hexagon::BI__builtin_HEXAGON_V6_veqh_and, "v60,v62,v65" },
2086 { Hexagon::BI__builtin_HEXAGON_V6_veqh_and_128B, "v60,v62,v65" },
2087 { Hexagon::BI__builtin_HEXAGON_V6_veqh_or, "v60,v62,v65" },
2088 { Hexagon::BI__builtin_HEXAGON_V6_veqh_or_128B, "v60,v62,v65" },
2089 { Hexagon::BI__builtin_HEXAGON_V6_veqh_xor, "v60,v62,v65" },
2090 { Hexagon::BI__builtin_HEXAGON_V6_veqh_xor_128B, "v60,v62,v65" },
2091 { Hexagon::BI__builtin_HEXAGON_V6_veqw, "v60,v62,v65" },
2092 { Hexagon::BI__builtin_HEXAGON_V6_veqw_128B, "v60,v62,v65" },
2093 { Hexagon::BI__builtin_HEXAGON_V6_veqw_and, "v60,v62,v65" },
2094 { Hexagon::BI__builtin_HEXAGON_V6_veqw_and_128B, "v60,v62,v65" },
2095 { Hexagon::BI__builtin_HEXAGON_V6_veqw_or, "v60,v62,v65" },
2096 { Hexagon::BI__builtin_HEXAGON_V6_veqw_or_128B, "v60,v62,v65" },
2097 { Hexagon::BI__builtin_HEXAGON_V6_veqw_xor, "v60,v62,v65" },
2098 { Hexagon::BI__builtin_HEXAGON_V6_veqw_xor_128B, "v60,v62,v65" },
2099 { Hexagon::BI__builtin_HEXAGON_V6_vgtb, "v60,v62,v65" },
2100 { Hexagon::BI__builtin_HEXAGON_V6_vgtb_128B, "v60,v62,v65" },
2101 { Hexagon::BI__builtin_HEXAGON_V6_vgtb_and, "v60,v62,v65" },
2102 { Hexagon::BI__builtin_HEXAGON_V6_vgtb_and_128B, "v60,v62,v65" },
2103 { Hexagon::BI__builtin_HEXAGON_V6_vgtb_or, "v60,v62,v65" },
2104 { Hexagon::BI__builtin_HEXAGON_V6_vgtb_or_128B, "v60,v62,v65" },
2105 { Hexagon::BI__builtin_HEXAGON_V6_vgtb_xor, "v60,v62,v65" },
2106 { Hexagon::BI__builtin_HEXAGON_V6_vgtb_xor_128B, "v60,v62,v65" },
2107 { Hexagon::BI__builtin_HEXAGON_V6_vgth, "v60,v62,v65" },
2108 { Hexagon::BI__builtin_HEXAGON_V6_vgth_128B, "v60,v62,v65" },
2109 { Hexagon::BI__builtin_HEXAGON_V6_vgth_and, "v60,v62,v65" },
2110 { Hexagon::BI__builtin_HEXAGON_V6_vgth_and_128B, "v60,v62,v65" },
2111 { Hexagon::BI__builtin_HEXAGON_V6_vgth_or, "v60,v62,v65" },
2112 { Hexagon::BI__builtin_HEXAGON_V6_vgth_or_128B, "v60,v62,v65" },
2113 { Hexagon::BI__builtin_HEXAGON_V6_vgth_xor, "v60,v62,v65" },
2114 { Hexagon::BI__builtin_HEXAGON_V6_vgth_xor_128B, "v60,v62,v65" },
2115 { Hexagon::BI__builtin_HEXAGON_V6_vgtub, "v60,v62,v65" },
2116 { Hexagon::BI__builtin_HEXAGON_V6_vgtub_128B, "v60,v62,v65" },
2117 { Hexagon::BI__builtin_HEXAGON_V6_vgtub_and, "v60,v62,v65" },
2118 { Hexagon::BI__builtin_HEXAGON_V6_vgtub_and_128B, "v60,v62,v65" },
2119 { Hexagon::BI__builtin_HEXAGON_V6_vgtub_or, "v60,v62,v65" },
2120 { Hexagon::BI__builtin_HEXAGON_V6_vgtub_or_128B, "v60,v62,v65" },
2121 { Hexagon::BI__builtin_HEXAGON_V6_vgtub_xor, "v60,v62,v65" },
2122 { Hexagon::BI__builtin_HEXAGON_V6_vgtub_xor_128B, "v60,v62,v65" },
2123 { Hexagon::BI__builtin_HEXAGON_V6_vgtuh, "v60,v62,v65" },
2124 { Hexagon::BI__builtin_HEXAGON_V6_vgtuh_128B, "v60,v62,v65" },
2125 { Hexagon::BI__builtin_HEXAGON_V6_vgtuh_and, "v60,v62,v65" },
2126 { Hexagon::BI__builtin_HEXAGON_V6_vgtuh_and_128B, "v60,v62,v65" },
2127 { Hexagon::BI__builtin_HEXAGON_V6_vgtuh_or, "v60,v62,v65" },
2128 { Hexagon::BI__builtin_HEXAGON_V6_vgtuh_or_128B, "v60,v62,v65" },
2129 { Hexagon::BI__builtin_HEXAGON_V6_vgtuh_xor, "v60,v62,v65" },
2130 { Hexagon::BI__builtin_HEXAGON_V6_vgtuh_xor_128B, "v60,v62,v65" },
2131 { Hexagon::BI__builtin_HEXAGON_V6_vgtuw, "v60,v62,v65" },
2132 { Hexagon::BI__builtin_HEXAGON_V6_vgtuw_128B, "v60,v62,v65" },
2133 { Hexagon::BI__builtin_HEXAGON_V6_vgtuw_and, "v60,v62,v65" },
2134 { Hexagon::BI__builtin_HEXAGON_V6_vgtuw_and_128B, "v60,v62,v65" },
2135 { Hexagon::BI__builtin_HEXAGON_V6_vgtuw_or, "v60,v62,v65" },
2136 { Hexagon::BI__builtin_HEXAGON_V6_vgtuw_or_128B, "v60,v62,v65" },
2137 { Hexagon::BI__builtin_HEXAGON_V6_vgtuw_xor, "v60,v62,v65" },
2138 { Hexagon::BI__builtin_HEXAGON_V6_vgtuw_xor_128B, "v60,v62,v65" },
2139 { Hexagon::BI__builtin_HEXAGON_V6_vgtw, "v60,v62,v65" },
2140 { Hexagon::BI__builtin_HEXAGON_V6_vgtw_128B, "v60,v62,v65" },
2141 { Hexagon::BI__builtin_HEXAGON_V6_vgtw_and, "v60,v62,v65" },
2142 { Hexagon::BI__builtin_HEXAGON_V6_vgtw_and_128B, "v60,v62,v65" },
2143 { Hexagon::BI__builtin_HEXAGON_V6_vgtw_or, "v60,v62,v65" },
2144 { Hexagon::BI__builtin_HEXAGON_V6_vgtw_or_128B, "v60,v62,v65" },
2145 { Hexagon::BI__builtin_HEXAGON_V6_vgtw_xor, "v60,v62,v65" },
2146 { Hexagon::BI__builtin_HEXAGON_V6_vgtw_xor_128B, "v60,v62,v65" },
2147 { Hexagon::BI__builtin_HEXAGON_V6_vinsertwr, "v60,v62,v65" },
2148 { Hexagon::BI__builtin_HEXAGON_V6_vinsertwr_128B, "v60,v62,v65" },
2149 { Hexagon::BI__builtin_HEXAGON_V6_vlalignb, "v60,v62,v65" },
2150 { Hexagon::BI__builtin_HEXAGON_V6_vlalignb_128B, "v60,v62,v65" },
2151 { Hexagon::BI__builtin_HEXAGON_V6_vlalignbi, "v60,v62,v65" },
2152 { Hexagon::BI__builtin_HEXAGON_V6_vlalignbi_128B, "v60,v62,v65" },
2153 { Hexagon::BI__builtin_HEXAGON_V6_vlsrb, "v62,v65" },
2154 { Hexagon::BI__builtin_HEXAGON_V6_vlsrb_128B, "v62,v65" },
2155 { Hexagon::BI__builtin_HEXAGON_V6_vlsrh, "v60,v62,v65" },
2156 { Hexagon::BI__builtin_HEXAGON_V6_vlsrh_128B, "v60,v62,v65" },
2157 { Hexagon::BI__builtin_HEXAGON_V6_vlsrhv, "v60,v62,v65" },
2158 { Hexagon::BI__builtin_HEXAGON_V6_vlsrhv_128B, "v60,v62,v65" },
2159 { Hexagon::BI__builtin_HEXAGON_V6_vlsrw, "v60,v62,v65" },
2160 { Hexagon::BI__builtin_HEXAGON_V6_vlsrw_128B, "v60,v62,v65" },
2161 { Hexagon::BI__builtin_HEXAGON_V6_vlsrwv, "v60,v62,v65" },
2162 { Hexagon::BI__builtin_HEXAGON_V6_vlsrwv_128B, "v60,v62,v65" },
2163 { Hexagon::BI__builtin_HEXAGON_V6_vlut4, "v65" },
2164 { Hexagon::BI__builtin_HEXAGON_V6_vlut4_128B, "v65" },
2165 { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb, "v60,v62,v65" },
2166 { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_128B, "v60,v62,v65" },
2167 { Hexagon::BI__builtin_HEXAGON_V6_vlutvvbi, "v62,v65" },
2168 { Hexagon::BI__builtin_HEXAGON_V6_vlutvvbi_128B, "v62,v65" },
2169 { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_nm, "v62,v65" },
2170 { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_nm_128B, "v62,v65" },
2171 { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_oracc, "v60,v62,v65" },
2172 { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_oracc_128B, "v60,v62,v65" },
2173 { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_oracci, "v62,v65" },
2174 { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_oracci_128B, "v62,v65" },
2175 { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh, "v60,v62,v65" },
2176 { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_128B, "v60,v62,v65" },
2177 { Hexagon::BI__builtin_HEXAGON_V6_vlutvwhi, "v62,v65" },
2178 { Hexagon::BI__builtin_HEXAGON_V6_vlutvwhi_128B, "v62,v65" },
2179 { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_nm, "v62,v65" },
2180 { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_nm_128B, "v62,v65" },
2181 { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_oracc, "v60,v62,v65" },
2182 { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_oracc_128B, "v60,v62,v65" },
2183 { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_oracci, "v62,v65" },
2184 { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_oracci_128B, "v62,v65" },
2185 { Hexagon::BI__builtin_HEXAGON_V6_vmaxb, "v62,v65" },
2186 { Hexagon::BI__builtin_HEXAGON_V6_vmaxb_128B, "v62,v65" },
2187 { Hexagon::BI__builtin_HEXAGON_V6_vmaxh, "v60,v62,v65" },
2188 { Hexagon::BI__builtin_HEXAGON_V6_vmaxh_128B, "v60,v62,v65" },
2189 { Hexagon::BI__builtin_HEXAGON_V6_vmaxub, "v60,v62,v65" },
2190 { Hexagon::BI__builtin_HEXAGON_V6_vmaxub_128B, "v60,v62,v65" },
2191 { Hexagon::BI__builtin_HEXAGON_V6_vmaxuh, "v60,v62,v65" },
2192 { Hexagon::BI__builtin_HEXAGON_V6_vmaxuh_128B, "v60,v62,v65" },
2193 { Hexagon::BI__builtin_HEXAGON_V6_vmaxw, "v60,v62,v65" },
2194 { Hexagon::BI__builtin_HEXAGON_V6_vmaxw_128B, "v60,v62,v65" },
2195 { Hexagon::BI__builtin_HEXAGON_V6_vminb, "v62,v65" },
2196 { Hexagon::BI__builtin_HEXAGON_V6_vminb_128B, "v62,v65" },
2197 { Hexagon::BI__builtin_HEXAGON_V6_vminh, "v60,v62,v65" },
2198 { Hexagon::BI__builtin_HEXAGON_V6_vminh_128B, "v60,v62,v65" },
2199 { Hexagon::BI__builtin_HEXAGON_V6_vminub, "v60,v62,v65" },
2200 { Hexagon::BI__builtin_HEXAGON_V6_vminub_128B, "v60,v62,v65" },
2201 { Hexagon::BI__builtin_HEXAGON_V6_vminuh, "v60,v62,v65" },
2202 { Hexagon::BI__builtin_HEXAGON_V6_vminuh_128B, "v60,v62,v65" },
2203 { Hexagon::BI__builtin_HEXAGON_V6_vminw, "v60,v62,v65" },
2204 { Hexagon::BI__builtin_HEXAGON_V6_vminw_128B, "v60,v62,v65" },
2205 { Hexagon::BI__builtin_HEXAGON_V6_vmpabus, "v60,v62,v65" },
2206 { Hexagon::BI__builtin_HEXAGON_V6_vmpabus_128B, "v60,v62,v65" },
2207 { Hexagon::BI__builtin_HEXAGON_V6_vmpabus_acc, "v60,v62,v65" },
2208 { Hexagon::BI__builtin_HEXAGON_V6_vmpabus_acc_128B, "v60,v62,v65" },
2209 { Hexagon::BI__builtin_HEXAGON_V6_vmpabusv, "v60,v62,v65" },
2210 { Hexagon::BI__builtin_HEXAGON_V6_vmpabusv_128B, "v60,v62,v65" },
2211 { Hexagon::BI__builtin_HEXAGON_V6_vmpabuu, "v65" },
2212 { Hexagon::BI__builtin_HEXAGON_V6_vmpabuu_128B, "v65" },
2213 { Hexagon::BI__builtin_HEXAGON_V6_vmpabuu_acc, "v65" },
2214 { Hexagon::BI__builtin_HEXAGON_V6_vmpabuu_acc_128B, "v65" },
2215 { Hexagon::BI__builtin_HEXAGON_V6_vmpabuuv, "v60,v62,v65" },
2216 { Hexagon::BI__builtin_HEXAGON_V6_vmpabuuv_128B, "v60,v62,v65" },
2217 { Hexagon::BI__builtin_HEXAGON_V6_vmpahb, "v60,v62,v65" },
2218 { Hexagon::BI__builtin_HEXAGON_V6_vmpahb_128B, "v60,v62,v65" },
2219 { Hexagon::BI__builtin_HEXAGON_V6_vmpahb_acc, "v60,v62,v65" },
2220 { Hexagon::BI__builtin_HEXAGON_V6_vmpahb_acc_128B, "v60,v62,v65" },
2221 { Hexagon::BI__builtin_HEXAGON_V6_vmpahhsat, "v65" },
2222 { Hexagon::BI__builtin_HEXAGON_V6_vmpahhsat_128B, "v65" },
2223 { Hexagon::BI__builtin_HEXAGON_V6_vmpauhb, "v62,v65" },
2224 { Hexagon::BI__builtin_HEXAGON_V6_vmpauhb_128B, "v62,v65" },
2225 { Hexagon::BI__builtin_HEXAGON_V6_vmpauhb_acc, "v62,v65" },
2226 { Hexagon::BI__builtin_HEXAGON_V6_vmpauhb_acc_128B, "v62,v65" },
2227 { Hexagon::BI__builtin_HEXAGON_V6_vmpauhuhsat, "v65" },
2228 { Hexagon::BI__builtin_HEXAGON_V6_vmpauhuhsat_128B, "v65" },
2229 { Hexagon::BI__builtin_HEXAGON_V6_vmpsuhuhsat, "v65" },
2230 { Hexagon::BI__builtin_HEXAGON_V6_vmpsuhuhsat_128B, "v65" },
2231 { Hexagon::BI__builtin_HEXAGON_V6_vmpybus, "v60,v62,v65" },
2232 { Hexagon::BI__builtin_HEXAGON_V6_vmpybus_128B, "v60,v62,v65" },
2233 { Hexagon::BI__builtin_HEXAGON_V6_vmpybus_acc, "v60,v62,v65" },
2234 { Hexagon::BI__builtin_HEXAGON_V6_vmpybus_acc_128B, "v60,v62,v65" },
2235 { Hexagon::BI__builtin_HEXAGON_V6_vmpybusv, "v60,v62,v65" },
2236 { Hexagon::BI__builtin_HEXAGON_V6_vmpybusv_128B, "v60,v62,v65" },
2237 { Hexagon::BI__builtin_HEXAGON_V6_vmpybusv_acc, "v60,v62,v65" },
2238 { Hexagon::BI__builtin_HEXAGON_V6_vmpybusv_acc_128B, "v60,v62,v65" },
2239 { Hexagon::BI__builtin_HEXAGON_V6_vmpybv, "v60,v62,v65" },
2240 { Hexagon::BI__builtin_HEXAGON_V6_vmpybv_128B, "v60,v62,v65" },
2241 { Hexagon::BI__builtin_HEXAGON_V6_vmpybv_acc, "v60,v62,v65" },
2242 { Hexagon::BI__builtin_HEXAGON_V6_vmpybv_acc_128B, "v60,v62,v65" },
2243 { Hexagon::BI__builtin_HEXAGON_V6_vmpyewuh, "v60,v62,v65" },
2244 { Hexagon::BI__builtin_HEXAGON_V6_vmpyewuh_128B, "v60,v62,v65" },
2245 { Hexagon::BI__builtin_HEXAGON_V6_vmpyewuh_64, "v62,v65" },
2246 { Hexagon::BI__builtin_HEXAGON_V6_vmpyewuh_64_128B, "v62,v65" },
2247 { Hexagon::BI__builtin_HEXAGON_V6_vmpyh, "v60,v62,v65" },
2248 { Hexagon::BI__builtin_HEXAGON_V6_vmpyh_128B, "v60,v62,v65" },
2249 { Hexagon::BI__builtin_HEXAGON_V6_vmpyh_acc, "v65" },
2250 { Hexagon::BI__builtin_HEXAGON_V6_vmpyh_acc_128B, "v65" },
2251 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhsat_acc, "v60,v62,v65" },
2252 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhsat_acc_128B, "v60,v62,v65" },
2253 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhsrs, "v60,v62,v65" },
2254 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhsrs_128B, "v60,v62,v65" },
2255 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhss, "v60,v62,v65" },
2256 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhss_128B, "v60,v62,v65" },
2257 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhus, "v60,v62,v65" },
2258 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhus_128B, "v60,v62,v65" },
2259 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhus_acc, "v60,v62,v65" },
2260 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhus_acc_128B, "v60,v62,v65" },
2261 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhv, "v60,v62,v65" },
2262 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhv_128B, "v60,v62,v65" },
2263 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhv_acc, "v60,v62,v65" },
2264 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhv_acc_128B, "v60,v62,v65" },
2265 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhvsrs, "v60,v62,v65" },
2266 { Hexagon::BI__builtin_HEXAGON_V6_vmpyhvsrs_128B, "v60,v62,v65" },
2267 { Hexagon::BI__builtin_HEXAGON_V6_vmpyieoh, "v60,v62,v65" },
2268 { Hexagon::BI__builtin_HEXAGON_V6_vmpyieoh_128B, "v60,v62,v65" },
2269 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiewh_acc, "v60,v62,v65" },
2270 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiewh_acc_128B, "v60,v62,v65" },
2271 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiewuh, "v60,v62,v65" },
2272 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiewuh_128B, "v60,v62,v65" },
2273 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiewuh_acc, "v60,v62,v65" },
2274 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiewuh_acc_128B, "v60,v62,v65" },
2275 { Hexagon::BI__builtin_HEXAGON_V6_vmpyih, "v60,v62,v65" },
2276 { Hexagon::BI__builtin_HEXAGON_V6_vmpyih_128B, "v60,v62,v65" },
2277 { Hexagon::BI__builtin_HEXAGON_V6_vmpyih_acc, "v60,v62,v65" },
2278 { Hexagon::BI__builtin_HEXAGON_V6_vmpyih_acc_128B, "v60,v62,v65" },
2279 { Hexagon::BI__builtin_HEXAGON_V6_vmpyihb, "v60,v62,v65" },
2280 { Hexagon::BI__builtin_HEXAGON_V6_vmpyihb_128B, "v60,v62,v65" },
2281 { Hexagon::BI__builtin_HEXAGON_V6_vmpyihb_acc, "v60,v62,v65" },
2282 { Hexagon::BI__builtin_HEXAGON_V6_vmpyihb_acc_128B, "v60,v62,v65" },
2283 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiowh, "v60,v62,v65" },
2284 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiowh_128B, "v60,v62,v65" },
2285 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwb, "v60,v62,v65" },
2286 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwb_128B, "v60,v62,v65" },
2287 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwb_acc, "v60,v62,v65" },
2288 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwb_acc_128B, "v60,v62,v65" },
2289 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwh, "v60,v62,v65" },
2290 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwh_128B, "v60,v62,v65" },
2291 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwh_acc, "v60,v62,v65" },
2292 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwh_acc_128B, "v60,v62,v65" },
2293 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwub, "v62,v65" },
2294 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwub_128B, "v62,v65" },
2295 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwub_acc, "v62,v65" },
2296 { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwub_acc_128B, "v62,v65" },
2297 { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh, "v60,v62,v65" },
2298 { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_128B, "v60,v62,v65" },
2299 { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_64_acc, "v62,v65" },
2300 { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_64_acc_128B, "v62,v65" },
2301 { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_rnd, "v60,v62,v65" },
2302 { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_rnd_128B, "v60,v62,v65" },
2303 { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_rnd_sacc, "v60,v62,v65" },
2304 { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_rnd_sacc_128B, "v60,v62,v65" },
2305 { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_sacc, "v60,v62,v65" },
2306 { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_sacc_128B, "v60,v62,v65" },
2307 { Hexagon::BI__builtin_HEXAGON_V6_vmpyub, "v60,v62,v65" },
2308 { Hexagon::BI__builtin_HEXAGON_V6_vmpyub_128B, "v60,v62,v65" },
2309 { Hexagon::BI__builtin_HEXAGON_V6_vmpyub_acc, "v60,v62,v65" },
2310 { Hexagon::BI__builtin_HEXAGON_V6_vmpyub_acc_128B, "v60,v62,v65" },
2311 { Hexagon::BI__builtin_HEXAGON_V6_vmpyubv, "v60,v62,v65" },
2312 { Hexagon::BI__builtin_HEXAGON_V6_vmpyubv_128B, "v60,v62,v65" },
2313 { Hexagon::BI__builtin_HEXAGON_V6_vmpyubv_acc, "v60,v62,v65" },
2314 { Hexagon::BI__builtin_HEXAGON_V6_vmpyubv_acc_128B, "v60,v62,v65" },
2315 { Hexagon::BI__builtin_HEXAGON_V6_vmpyuh, "v60,v62,v65" },
2316 { Hexagon::BI__builtin_HEXAGON_V6_vmpyuh_128B, "v60,v62,v65" },
2317 { Hexagon::BI__builtin_HEXAGON_V6_vmpyuh_acc, "v60,v62,v65" },
2318 { Hexagon::BI__builtin_HEXAGON_V6_vmpyuh_acc_128B, "v60,v62,v65" },
2319 { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhe, "v65" },
2320 { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhe_128B, "v65" },
2321 { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhe_acc, "v65" },
2322 { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhe_acc_128B, "v65" },
2323 { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhv, "v60,v62,v65" },
2324 { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhv_128B, "v60,v62,v65" },
2325 { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhv_acc, "v60,v62,v65" },
2326 { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhv_acc_128B, "v60,v62,v65" },
2327 { Hexagon::BI__builtin_HEXAGON_V6_vmux, "v60,v62,v65" },
2328 { Hexagon::BI__builtin_HEXAGON_V6_vmux_128B, "v60,v62,v65" },
2329 { Hexagon::BI__builtin_HEXAGON_V6_vnavgb, "v65" },
2330 { Hexagon::BI__builtin_HEXAGON_V6_vnavgb_128B, "v65" },
2331 { Hexagon::BI__builtin_HEXAGON_V6_vnavgh, "v60,v62,v65" },
2332 { Hexagon::BI__builtin_HEXAGON_V6_vnavgh_128B, "v60,v62,v65" },
2333 { Hexagon::BI__builtin_HEXAGON_V6_vnavgub, "v60,v62,v65" },
2334 { Hexagon::BI__builtin_HEXAGON_V6_vnavgub_128B, "v60,v62,v65" },
2335 { Hexagon::BI__builtin_HEXAGON_V6_vnavgw, "v60,v62,v65" },
2336 { Hexagon::BI__builtin_HEXAGON_V6_vnavgw_128B, "v60,v62,v65" },
2337 { Hexagon::BI__builtin_HEXAGON_V6_vnormamth, "v60,v62,v65" },
2338 { Hexagon::BI__builtin_HEXAGON_V6_vnormamth_128B, "v60,v62,v65" },
2339 { Hexagon::BI__builtin_HEXAGON_V6_vnormamtw, "v60,v62,v65" },
2340 { Hexagon::BI__builtin_HEXAGON_V6_vnormamtw_128B, "v60,v62,v65" },
2341 { Hexagon::BI__builtin_HEXAGON_V6_vnot, "v60,v62,v65" },
2342 { Hexagon::BI__builtin_HEXAGON_V6_vnot_128B, "v60,v62,v65" },
2343 { Hexagon::BI__builtin_HEXAGON_V6_vor, "v60,v62,v65" },
2344 { Hexagon::BI__builtin_HEXAGON_V6_vor_128B, "v60,v62,v65" },
2345 { Hexagon::BI__builtin_HEXAGON_V6_vpackeb, "v60,v62,v65" },
2346 { Hexagon::BI__builtin_HEXAGON_V6_vpackeb_128B, "v60,v62,v65" },
2347 { Hexagon::BI__builtin_HEXAGON_V6_vpackeh, "v60,v62,v65" },
2348 { Hexagon::BI__builtin_HEXAGON_V6_vpackeh_128B, "v60,v62,v65" },
2349 { Hexagon::BI__builtin_HEXAGON_V6_vpackhb_sat, "v60,v62,v65" },
2350 { Hexagon::BI__builtin_HEXAGON_V6_vpackhb_sat_128B, "v60,v62,v65" },
2351 { Hexagon::BI__builtin_HEXAGON_V6_vpackhub_sat, "v60,v62,v65" },
2352 { Hexagon::BI__builtin_HEXAGON_V6_vpackhub_sat_128B, "v60,v62,v65" },
2353 { Hexagon::BI__builtin_HEXAGON_V6_vpackob, "v60,v62,v65" },
2354 { Hexagon::BI__builtin_HEXAGON_V6_vpackob_128B, "v60,v62,v65" },
2355 { Hexagon::BI__builtin_HEXAGON_V6_vpackoh, "v60,v62,v65" },
2356 { Hexagon::BI__builtin_HEXAGON_V6_vpackoh_128B, "v60,v62,v65" },
2357 { Hexagon::BI__builtin_HEXAGON_V6_vpackwh_sat, "v60,v62,v65" },
2358 { Hexagon::BI__builtin_HEXAGON_V6_vpackwh_sat_128B, "v60,v62,v65" },
2359 { Hexagon::BI__builtin_HEXAGON_V6_vpackwuh_sat, "v60,v62,v65" },
2360 { Hexagon::BI__builtin_HEXAGON_V6_vpackwuh_sat_128B, "v60,v62,v65" },
2361 { Hexagon::BI__builtin_HEXAGON_V6_vpopcounth, "v60,v62,v65" },
2362 { Hexagon::BI__builtin_HEXAGON_V6_vpopcounth_128B, "v60,v62,v65" },
2363 { Hexagon::BI__builtin_HEXAGON_V6_vprefixqb, "v65" },
2364 { Hexagon::BI__builtin_HEXAGON_V6_vprefixqb_128B, "v65" },
2365 { Hexagon::BI__builtin_HEXAGON_V6_vprefixqh, "v65" },
2366 { Hexagon::BI__builtin_HEXAGON_V6_vprefixqh_128B, "v65" },
2367 { Hexagon::BI__builtin_HEXAGON_V6_vprefixqw, "v65" },
2368 { Hexagon::BI__builtin_HEXAGON_V6_vprefixqw_128B, "v65" },
2369 { Hexagon::BI__builtin_HEXAGON_V6_vrdelta, "v60,v62,v65" },
2370 { Hexagon::BI__builtin_HEXAGON_V6_vrdelta_128B, "v60,v62,v65" },
2371 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybub_rtt, "v65" },
2372 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybub_rtt_128B, "v65" },
2373 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybub_rtt_acc, "v65" },
2374 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybub_rtt_acc_128B, "v65" },
2375 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybus, "v60,v62,v65" },
2376 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybus_128B, "v60,v62,v65" },
2377 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybus_acc, "v60,v62,v65" },
2378 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybus_acc_128B, "v60,v62,v65" },
2379 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi, "v60,v62,v65" },
2380 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_128B, "v60,v62,v65" },
2381 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_acc, "v60,v62,v65" },
2382 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_acc_128B, "v60,v62,v65" },
2383 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusv, "v60,v62,v65" },
2384 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusv_128B, "v60,v62,v65" },
2385 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusv_acc, "v60,v62,v65" },
2386 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusv_acc_128B, "v60,v62,v65" },
2387 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybv, "v60,v62,v65" },
2388 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybv_128B, "v60,v62,v65" },
2389 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybv_acc, "v60,v62,v65" },
2390 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybv_acc_128B, "v60,v62,v65" },
2391 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub, "v60,v62,v65" },
2392 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub_128B, "v60,v62,v65" },
2393 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub_acc, "v60,v62,v65" },
2394 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub_acc_128B, "v60,v62,v65" },
2395 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi, "v60,v62,v65" },
2396 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_128B, "v60,v62,v65" },
2397 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_acc, "v60,v62,v65" },
2398 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_acc_128B, "v60,v62,v65" },
2399 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub_rtt, "v65" },
2400 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub_rtt_128B, "v65" },
2401 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub_rtt_acc, "v65" },
2402 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub_rtt_acc_128B, "v65" },
2403 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubv, "v60,v62,v65" },
2404 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubv_128B, "v60,v62,v65" },
2405 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubv_acc, "v60,v62,v65" },
2406 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubv_acc_128B, "v60,v62,v65" },
2407 { Hexagon::BI__builtin_HEXAGON_V6_vror, "v60,v62,v65" },
2408 { Hexagon::BI__builtin_HEXAGON_V6_vror_128B, "v60,v62,v65" },
2409 { Hexagon::BI__builtin_HEXAGON_V6_vroundhb, "v60,v62,v65" },
2410 { Hexagon::BI__builtin_HEXAGON_V6_vroundhb_128B, "v60,v62,v65" },
2411 { Hexagon::BI__builtin_HEXAGON_V6_vroundhub, "v60,v62,v65" },
2412 { Hexagon::BI__builtin_HEXAGON_V6_vroundhub_128B, "v60,v62,v65" },
2413 { Hexagon::BI__builtin_HEXAGON_V6_vrounduhub, "v62,v65" },
2414 { Hexagon::BI__builtin_HEXAGON_V6_vrounduhub_128B, "v62,v65" },
2415 { Hexagon::BI__builtin_HEXAGON_V6_vrounduwuh, "v62,v65" },
2416 { Hexagon::BI__builtin_HEXAGON_V6_vrounduwuh_128B, "v62,v65" },
2417 { Hexagon::BI__builtin_HEXAGON_V6_vroundwh, "v60,v62,v65" },
2418 { Hexagon::BI__builtin_HEXAGON_V6_vroundwh_128B, "v60,v62,v65" },
2419 { Hexagon::BI__builtin_HEXAGON_V6_vroundwuh, "v60,v62,v65" },
2420 { Hexagon::BI__builtin_HEXAGON_V6_vroundwuh_128B, "v60,v62,v65" },
2421 { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi, "v60,v62,v65" },
2422 { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_128B, "v60,v62,v65" },
2423 { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_acc, "v60,v62,v65" },
2424 { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_acc_128B, "v60,v62,v65" },
2425 { Hexagon::BI__builtin_HEXAGON_V6_vsathub, "v60,v62,v65" },
2426 { Hexagon::BI__builtin_HEXAGON_V6_vsathub_128B, "v60,v62,v65" },
2427 { Hexagon::BI__builtin_HEXAGON_V6_vsatuwuh, "v62,v65" },
2428 { Hexagon::BI__builtin_HEXAGON_V6_vsatuwuh_128B, "v62,v65" },
2429 { Hexagon::BI__builtin_HEXAGON_V6_vsatwh, "v60,v62,v65" },
2430 { Hexagon::BI__builtin_HEXAGON_V6_vsatwh_128B, "v60,v62,v65" },
2431 { Hexagon::BI__builtin_HEXAGON_V6_vsb, "v60,v62,v65" },
2432 { Hexagon::BI__builtin_HEXAGON_V6_vsb_128B, "v60,v62,v65" },
2433 { Hexagon::BI__builtin_HEXAGON_V6_vsh, "v60,v62,v65" },
2434 { Hexagon::BI__builtin_HEXAGON_V6_vsh_128B, "v60,v62,v65" },
2435 { Hexagon::BI__builtin_HEXAGON_V6_vshufeh, "v60,v62,v65" },
2436 { Hexagon::BI__builtin_HEXAGON_V6_vshufeh_128B, "v60,v62,v65" },
2437 { Hexagon::BI__builtin_HEXAGON_V6_vshuffb, "v60,v62,v65" },
2438 { Hexagon::BI__builtin_HEXAGON_V6_vshuffb_128B, "v60,v62,v65" },
2439 { Hexagon::BI__builtin_HEXAGON_V6_vshuffeb, "v60,v62,v65" },
2440 { Hexagon::BI__builtin_HEXAGON_V6_vshuffeb_128B, "v60,v62,v65" },
2441 { Hexagon::BI__builtin_HEXAGON_V6_vshuffh, "v60,v62,v65" },
2442 { Hexagon::BI__builtin_HEXAGON_V6_vshuffh_128B, "v60,v62,v65" },
2443 { Hexagon::BI__builtin_HEXAGON_V6_vshuffob, "v60,v62,v65" },
2444 { Hexagon::BI__builtin_HEXAGON_V6_vshuffob_128B, "v60,v62,v65" },
2445 { Hexagon::BI__builtin_HEXAGON_V6_vshuffvdd, "v60,v62,v65" },
2446 { Hexagon::BI__builtin_HEXAGON_V6_vshuffvdd_128B, "v60,v62,v65" },
2447 { Hexagon::BI__builtin_HEXAGON_V6_vshufoeb, "v60,v62,v65" },
2448 { Hexagon::BI__builtin_HEXAGON_V6_vshufoeb_128B, "v60,v62,v65" },
2449 { Hexagon::BI__builtin_HEXAGON_V6_vshufoeh, "v60,v62,v65" },
2450 { Hexagon::BI__builtin_HEXAGON_V6_vshufoeh_128B, "v60,v62,v65" },
2451 { Hexagon::BI__builtin_HEXAGON_V6_vshufoh, "v60,v62,v65" },
2452 { Hexagon::BI__builtin_HEXAGON_V6_vshufoh_128B, "v60,v62,v65" },
2453 { Hexagon::BI__builtin_HEXAGON_V6_vsubb, "v60,v62,v65" },
2454 { Hexagon::BI__builtin_HEXAGON_V6_vsubb_128B, "v60,v62,v65" },
2455 { Hexagon::BI__builtin_HEXAGON_V6_vsubb_dv, "v60,v62,v65" },
2456 { Hexagon::BI__builtin_HEXAGON_V6_vsubb_dv_128B, "v60,v62,v65" },
2457 { Hexagon::BI__builtin_HEXAGON_V6_vsubbsat, "v62,v65" },
2458 { Hexagon::BI__builtin_HEXAGON_V6_vsubbsat_128B, "v62,v65" },
2459 { Hexagon::BI__builtin_HEXAGON_V6_vsubbsat_dv, "v62,v65" },
2460 { Hexagon::BI__builtin_HEXAGON_V6_vsubbsat_dv_128B, "v62,v65" },
2461 { Hexagon::BI__builtin_HEXAGON_V6_vsubcarry, "v62,v65" },
2462 { Hexagon::BI__builtin_HEXAGON_V6_vsubcarry_128B, "v62,v65" },
2463 { Hexagon::BI__builtin_HEXAGON_V6_vsubh, "v60,v62,v65" },
2464 { Hexagon::BI__builtin_HEXAGON_V6_vsubh_128B, "v60,v62,v65" },
2465 { Hexagon::BI__builtin_HEXAGON_V6_vsubh_dv, "v60,v62,v65" },
2466 { Hexagon::BI__builtin_HEXAGON_V6_vsubh_dv_128B, "v60,v62,v65" },
2467 { Hexagon::BI__builtin_HEXAGON_V6_vsubhsat, "v60,v62,v65" },
2468 { Hexagon::BI__builtin_HEXAGON_V6_vsubhsat_128B, "v60,v62,v65" },
2469 { Hexagon::BI__builtin_HEXAGON_V6_vsubhsat_dv, "v60,v62,v65" },
2470 { Hexagon::BI__builtin_HEXAGON_V6_vsubhsat_dv_128B, "v60,v62,v65" },
2471 { Hexagon::BI__builtin_HEXAGON_V6_vsubhw, "v60,v62,v65" },
2472 { Hexagon::BI__builtin_HEXAGON_V6_vsubhw_128B, "v60,v62,v65" },
2473 { Hexagon::BI__builtin_HEXAGON_V6_vsububh, "v60,v62,v65" },
2474 { Hexagon::BI__builtin_HEXAGON_V6_vsububh_128B, "v60,v62,v65" },
2475 { Hexagon::BI__builtin_HEXAGON_V6_vsububsat, "v60,v62,v65" },
2476 { Hexagon::BI__builtin_HEXAGON_V6_vsububsat_128B, "v60,v62,v65" },
2477 { Hexagon::BI__builtin_HEXAGON_V6_vsububsat_dv, "v60,v62,v65" },
2478 { Hexagon::BI__builtin_HEXAGON_V6_vsububsat_dv_128B, "v60,v62,v65" },
2479 { Hexagon::BI__builtin_HEXAGON_V6_vsubububb_sat, "v62,v65" },
2480 { Hexagon::BI__builtin_HEXAGON_V6_vsubububb_sat_128B, "v62,v65" },
2481 { Hexagon::BI__builtin_HEXAGON_V6_vsubuhsat, "v60,v62,v65" },
2482 { Hexagon::BI__builtin_HEXAGON_V6_vsubuhsat_128B, "v60,v62,v65" },
2483 { Hexagon::BI__builtin_HEXAGON_V6_vsubuhsat_dv, "v60,v62,v65" },
2484 { Hexagon::BI__builtin_HEXAGON_V6_vsubuhsat_dv_128B, "v60,v62,v65" },
2485 { Hexagon::BI__builtin_HEXAGON_V6_vsubuhw, "v60,v62,v65" },
2486 { Hexagon::BI__builtin_HEXAGON_V6_vsubuhw_128B, "v60,v62,v65" },
2487 { Hexagon::BI__builtin_HEXAGON_V6_vsubuwsat, "v62,v65" },
2488 { Hexagon::BI__builtin_HEXAGON_V6_vsubuwsat_128B, "v62,v65" },
2489 { Hexagon::BI__builtin_HEXAGON_V6_vsubuwsat_dv, "v62,v65" },
2490 { Hexagon::BI__builtin_HEXAGON_V6_vsubuwsat_dv_128B, "v62,v65" },
2491 { Hexagon::BI__builtin_HEXAGON_V6_vsubw, "v60,v62,v65" },
2492 { Hexagon::BI__builtin_HEXAGON_V6_vsubw_128B, "v60,v62,v65" },
2493 { Hexagon::BI__builtin_HEXAGON_V6_vsubw_dv, "v60,v62,v65" },
2494 { Hexagon::BI__builtin_HEXAGON_V6_vsubw_dv_128B, "v60,v62,v65" },
2495 { Hexagon::BI__builtin_HEXAGON_V6_vsubwsat, "v60,v62,v65" },
2496 { Hexagon::BI__builtin_HEXAGON_V6_vsubwsat_128B, "v60,v62,v65" },
2497 { Hexagon::BI__builtin_HEXAGON_V6_vsubwsat_dv, "v60,v62,v65" },
2498 { Hexagon::BI__builtin_HEXAGON_V6_vsubwsat_dv_128B, "v60,v62,v65" },
2499 { Hexagon::BI__builtin_HEXAGON_V6_vswap, "v60,v62,v65" },
2500 { Hexagon::BI__builtin_HEXAGON_V6_vswap_128B, "v60,v62,v65" },
2501 { Hexagon::BI__builtin_HEXAGON_V6_vtmpyb, "v60,v62,v65" },
2502 { Hexagon::BI__builtin_HEXAGON_V6_vtmpyb_128B, "v60,v62,v65" },
2503 { Hexagon::BI__builtin_HEXAGON_V6_vtmpyb_acc, "v60,v62,v65" },
2504 { Hexagon::BI__builtin_HEXAGON_V6_vtmpyb_acc_128B, "v60,v62,v65" },
2505 { Hexagon::BI__builtin_HEXAGON_V6_vtmpybus, "v60,v62,v65" },
2506 { Hexagon::BI__builtin_HEXAGON_V6_vtmpybus_128B, "v60,v62,v65" },
2507 { Hexagon::BI__builtin_HEXAGON_V6_vtmpybus_acc, "v60,v62,v65" },
2508 { Hexagon::BI__builtin_HEXAGON_V6_vtmpybus_acc_128B, "v60,v62,v65" },
2509 { Hexagon::BI__builtin_HEXAGON_V6_vtmpyhb, "v60,v62,v65" },
2510 { Hexagon::BI__builtin_HEXAGON_V6_vtmpyhb_128B, "v60,v62,v65" },
2511 { Hexagon::BI__builtin_HEXAGON_V6_vtmpyhb_acc, "v60,v62,v65" },
2512 { Hexagon::BI__builtin_HEXAGON_V6_vtmpyhb_acc_128B, "v60,v62,v65" },
2513 { Hexagon::BI__builtin_HEXAGON_V6_vunpackb, "v60,v62,v65" },
2514 { Hexagon::BI__builtin_HEXAGON_V6_vunpackb_128B, "v60,v62,v65" },
2515 { Hexagon::BI__builtin_HEXAGON_V6_vunpackh, "v60,v62,v65" },
2516 { Hexagon::BI__builtin_HEXAGON_V6_vunpackh_128B, "v60,v62,v65" },
2517 { Hexagon::BI__builtin_HEXAGON_V6_vunpackob, "v60,v62,v65" },
2518 { Hexagon::BI__builtin_HEXAGON_V6_vunpackob_128B, "v60,v62,v65" },
2519 { Hexagon::BI__builtin_HEXAGON_V6_vunpackoh, "v60,v62,v65" },
2520 { Hexagon::BI__builtin_HEXAGON_V6_vunpackoh_128B, "v60,v62,v65" },
2521 { Hexagon::BI__builtin_HEXAGON_V6_vunpackub, "v60,v62,v65" },
2522 { Hexagon::BI__builtin_HEXAGON_V6_vunpackub_128B, "v60,v62,v65" },
2523 { Hexagon::BI__builtin_HEXAGON_V6_vunpackuh, "v60,v62,v65" },
2524 { Hexagon::BI__builtin_HEXAGON_V6_vunpackuh_128B, "v60,v62,v65" },
2525 { Hexagon::BI__builtin_HEXAGON_V6_vxor, "v60,v62,v65" },
2526 { Hexagon::BI__builtin_HEXAGON_V6_vxor_128B, "v60,v62,v65" },
2527 { Hexagon::BI__builtin_HEXAGON_V6_vzb, "v60,v62,v65" },
2528 { Hexagon::BI__builtin_HEXAGON_V6_vzb_128B, "v60,v62,v65" },
2529 { Hexagon::BI__builtin_HEXAGON_V6_vzh, "v60,v62,v65" },
2530 { Hexagon::BI__builtin_HEXAGON_V6_vzh_128B, "v60,v62,v65" },
2531 };
2532
2533 // Sort the tables on first execution so we can binary search them.
2534 auto SortCmp = [](const BuiltinAndString &LHS, const BuiltinAndString &RHS) {
2535 return LHS.BuiltinID < RHS.BuiltinID;
2536 };
2537 static const bool SortOnce =
2538 (std::sort(std::begin(ValidCPU), std::end(ValidCPU), SortCmp),
2539 std::sort(std::begin(ValidHVX), std::end(ValidHVX), SortCmp), true);
2540 (void)SortOnce;
2541 auto LowerBoundCmp = [](const BuiltinAndString &BI, unsigned BuiltinID) {
2542 return BI.BuiltinID < BuiltinID;
2543 };
2544
2545 const TargetInfo &TI = Context.getTargetInfo();
2546
2547 const BuiltinAndString *FC =
2548 std::lower_bound(std::begin(ValidCPU), std::end(ValidCPU), BuiltinID,
2549 LowerBoundCmp);
2550 if (FC != std::end(ValidCPU) && FC->BuiltinID == BuiltinID) {
2551 const TargetOptions &Opts = TI.getTargetOpts();
2552 StringRef CPU = Opts.CPU;
2553 if (!CPU.empty()) {
2554 assert(CPU.startswith("hexagon") && "Unexpected CPU name")((CPU.startswith("hexagon") && "Unexpected CPU name")
? static_cast<void> (0) : __assert_fail ("CPU.startswith(\"hexagon\") && \"Unexpected CPU name\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 2554, __PRETTY_FUNCTION__))
;
2555 CPU.consume_front("hexagon");
2556 SmallVector<StringRef, 3> CPUs;
2557 StringRef(FC->Str).split(CPUs, ',');
2558 if (llvm::none_of(CPUs, [CPU](StringRef S) { return S == CPU; }))
2559 return Diag(TheCall->getBeginLoc(),
2560 diag::err_hexagon_builtin_unsupported_cpu);
2561 }
2562 }
2563
2564 const BuiltinAndString *FH =
2565 std::lower_bound(std::begin(ValidHVX), std::end(ValidHVX), BuiltinID,
2566 LowerBoundCmp);
2567 if (FH != std::end(ValidHVX) && FH->BuiltinID == BuiltinID) {
2568 if (!TI.hasFeature("hvx"))
2569 return Diag(TheCall->getBeginLoc(),
2570 diag::err_hexagon_builtin_requires_hvx);
2571
2572 SmallVector<StringRef, 3> HVXs;
2573 StringRef(FH->Str).split(HVXs, ',');
2574 bool IsValid = llvm::any_of(HVXs,
2575 [&TI] (StringRef V) {
2576 std::string F = "hvx" + V.str();
2577 return TI.hasFeature(F);
2578 });
2579 if (!IsValid)
2580 return Diag(TheCall->getBeginLoc(),
2581 diag::err_hexagon_builtin_unsupported_hvx);
2582 }
2583
2584 return false;
2585}
2586
2587bool Sema::CheckHexagonBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall) {
2588 struct ArgInfo {
2589 uint8_t OpNum;
2590 bool IsSigned;
2591 uint8_t BitWidth;
2592 uint8_t Align;
2593 };
2594 struct BuiltinInfo {
2595 unsigned BuiltinID;
2596 ArgInfo Infos[2];
2597 };
2598
2599 static BuiltinInfo Infos[] = {
2600 { Hexagon::BI__builtin_circ_ldd, {{ 3, true, 4, 3 }} },
2601 { Hexagon::BI__builtin_circ_ldw, {{ 3, true, 4, 2 }} },
2602 { Hexagon::BI__builtin_circ_ldh, {{ 3, true, 4, 1 }} },
2603 { Hexagon::BI__builtin_circ_lduh, {{ 3, true, 4, 0 }} },
2604 { Hexagon::BI__builtin_circ_ldb, {{ 3, true, 4, 0 }} },
2605 { Hexagon::BI__builtin_circ_ldub, {{ 3, true, 4, 0 }} },
2606 { Hexagon::BI__builtin_circ_std, {{ 3, true, 4, 3 }} },
2607 { Hexagon::BI__builtin_circ_stw, {{ 3, true, 4, 2 }} },
2608 { Hexagon::BI__builtin_circ_sth, {{ 3, true, 4, 1 }} },
2609 { Hexagon::BI__builtin_circ_sthhi, {{ 3, true, 4, 1 }} },
2610 { Hexagon::BI__builtin_circ_stb, {{ 3, true, 4, 0 }} },
2611
2612 { Hexagon::BI__builtin_HEXAGON_L2_loadrub_pci, {{ 1, true, 4, 0 }} },
2613 { Hexagon::BI__builtin_HEXAGON_L2_loadrb_pci, {{ 1, true, 4, 0 }} },
2614 { Hexagon::BI__builtin_HEXAGON_L2_loadruh_pci, {{ 1, true, 4, 1 }} },
2615 { Hexagon::BI__builtin_HEXAGON_L2_loadrh_pci, {{ 1, true, 4, 1 }} },
2616 { Hexagon::BI__builtin_HEXAGON_L2_loadri_pci, {{ 1, true, 4, 2 }} },
2617 { Hexagon::BI__builtin_HEXAGON_L2_loadrd_pci, {{ 1, true, 4, 3 }} },
2618 { Hexagon::BI__builtin_HEXAGON_S2_storerb_pci, {{ 1, true, 4, 0 }} },
2619 { Hexagon::BI__builtin_HEXAGON_S2_storerh_pci, {{ 1, true, 4, 1 }} },
2620 { Hexagon::BI__builtin_HEXAGON_S2_storerf_pci, {{ 1, true, 4, 1 }} },
2621 { Hexagon::BI__builtin_HEXAGON_S2_storeri_pci, {{ 1, true, 4, 2 }} },
2622 { Hexagon::BI__builtin_HEXAGON_S2_storerd_pci, {{ 1, true, 4, 3 }} },
2623
2624 { Hexagon::BI__builtin_HEXAGON_A2_combineii, {{ 1, true, 8, 0 }} },
2625 { Hexagon::BI__builtin_HEXAGON_A2_tfrih, {{ 1, false, 16, 0 }} },
2626 { Hexagon::BI__builtin_HEXAGON_A2_tfril, {{ 1, false, 16, 0 }} },
2627 { Hexagon::BI__builtin_HEXAGON_A2_tfrpi, {{ 0, true, 8, 0 }} },
2628 { Hexagon::BI__builtin_HEXAGON_A4_bitspliti, {{ 1, false, 5, 0 }} },
2629 { Hexagon::BI__builtin_HEXAGON_A4_cmpbeqi, {{ 1, false, 8, 0 }} },
2630 { Hexagon::BI__builtin_HEXAGON_A4_cmpbgti, {{ 1, true, 8, 0 }} },
2631 { Hexagon::BI__builtin_HEXAGON_A4_cround_ri, {{ 1, false, 5, 0 }} },
2632 { Hexagon::BI__builtin_HEXAGON_A4_round_ri, {{ 1, false, 5, 0 }} },
2633 { Hexagon::BI__builtin_HEXAGON_A4_round_ri_sat, {{ 1, false, 5, 0 }} },
2634 { Hexagon::BI__builtin_HEXAGON_A4_vcmpbeqi, {{ 1, false, 8, 0 }} },
2635 { Hexagon::BI__builtin_HEXAGON_A4_vcmpbgti, {{ 1, true, 8, 0 }} },
2636 { Hexagon::BI__builtin_HEXAGON_A4_vcmpbgtui, {{ 1, false, 7, 0 }} },
2637 { Hexagon::BI__builtin_HEXAGON_A4_vcmpheqi, {{ 1, true, 8, 0 }} },
2638 { Hexagon::BI__builtin_HEXAGON_A4_vcmphgti, {{ 1, true, 8, 0 }} },
2639 { Hexagon::BI__builtin_HEXAGON_A4_vcmphgtui, {{ 1, false, 7, 0 }} },
2640 { Hexagon::BI__builtin_HEXAGON_A4_vcmpweqi, {{ 1, true, 8, 0 }} },
2641 { Hexagon::BI__builtin_HEXAGON_A4_vcmpwgti, {{ 1, true, 8, 0 }} },
2642 { Hexagon::BI__builtin_HEXAGON_A4_vcmpwgtui, {{ 1, false, 7, 0 }} },
2643 { Hexagon::BI__builtin_HEXAGON_C2_bitsclri, {{ 1, false, 6, 0 }} },
2644 { Hexagon::BI__builtin_HEXAGON_C2_muxii, {{ 2, true, 8, 0 }} },
2645 { Hexagon::BI__builtin_HEXAGON_C4_nbitsclri, {{ 1, false, 6, 0 }} },
2646 { Hexagon::BI__builtin_HEXAGON_F2_dfclass, {{ 1, false, 5, 0 }} },
2647 { Hexagon::BI__builtin_HEXAGON_F2_dfimm_n, {{ 0, false, 10, 0 }} },
2648 { Hexagon::BI__builtin_HEXAGON_F2_dfimm_p, {{ 0, false, 10, 0 }} },
2649 { Hexagon::BI__builtin_HEXAGON_F2_sfclass, {{ 1, false, 5, 0 }} },
2650 { Hexagon::BI__builtin_HEXAGON_F2_sfimm_n, {{ 0, false, 10, 0 }} },
2651 { Hexagon::BI__builtin_HEXAGON_F2_sfimm_p, {{ 0, false, 10, 0 }} },
2652 { Hexagon::BI__builtin_HEXAGON_M4_mpyri_addi, {{ 2, false, 6, 0 }} },
2653 { Hexagon::BI__builtin_HEXAGON_M4_mpyri_addr_u2, {{ 1, false, 6, 2 }} },
2654 { Hexagon::BI__builtin_HEXAGON_S2_addasl_rrri, {{ 2, false, 3, 0 }} },
2655 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_acc, {{ 2, false, 6, 0 }} },
2656 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_and, {{ 2, false, 6, 0 }} },
2657 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p, {{ 1, false, 6, 0 }} },
2658 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_nac, {{ 2, false, 6, 0 }} },
2659 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_or, {{ 2, false, 6, 0 }} },
2660 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_xacc, {{ 2, false, 6, 0 }} },
2661 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_acc, {{ 2, false, 5, 0 }} },
2662 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_and, {{ 2, false, 5, 0 }} },
2663 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r, {{ 1, false, 5, 0 }} },
2664 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_nac, {{ 2, false, 5, 0 }} },
2665 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_or, {{ 2, false, 5, 0 }} },
2666 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_sat, {{ 1, false, 5, 0 }} },
2667 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_xacc, {{ 2, false, 5, 0 }} },
2668 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_vh, {{ 1, false, 4, 0 }} },
2669 { Hexagon::BI__builtin_HEXAGON_S2_asl_i_vw, {{ 1, false, 5, 0 }} },
2670 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_acc, {{ 2, false, 6, 0 }} },
2671 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_and, {{ 2, false, 6, 0 }} },
2672 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p, {{ 1, false, 6, 0 }} },
2673 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_nac, {{ 2, false, 6, 0 }} },
2674 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_or, {{ 2, false, 6, 0 }} },
2675 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_rnd_goodsyntax,
2676 {{ 1, false, 6, 0 }} },
2677 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_rnd, {{ 1, false, 6, 0 }} },
2678 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_acc, {{ 2, false, 5, 0 }} },
2679 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_and, {{ 2, false, 5, 0 }} },
2680 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r, {{ 1, false, 5, 0 }} },
2681 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_nac, {{ 2, false, 5, 0 }} },
2682 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_or, {{ 2, false, 5, 0 }} },
2683 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_rnd_goodsyntax,
2684 {{ 1, false, 5, 0 }} },
2685 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_rnd, {{ 1, false, 5, 0 }} },
2686 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_svw_trun, {{ 1, false, 5, 0 }} },
2687 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_vh, {{ 1, false, 4, 0 }} },
2688 { Hexagon::BI__builtin_HEXAGON_S2_asr_i_vw, {{ 1, false, 5, 0 }} },
2689 { Hexagon::BI__builtin_HEXAGON_S2_clrbit_i, {{ 1, false, 5, 0 }} },
2690 { Hexagon::BI__builtin_HEXAGON_S2_extractu, {{ 1, false, 5, 0 },
2691 { 2, false, 5, 0 }} },
2692 { Hexagon::BI__builtin_HEXAGON_S2_extractup, {{ 1, false, 6, 0 },
2693 { 2, false, 6, 0 }} },
2694 { Hexagon::BI__builtin_HEXAGON_S2_insert, {{ 2, false, 5, 0 },
2695 { 3, false, 5, 0 }} },
2696 { Hexagon::BI__builtin_HEXAGON_S2_insertp, {{ 2, false, 6, 0 },
2697 { 3, false, 6, 0 }} },
2698 { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_acc, {{ 2, false, 6, 0 }} },
2699 { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_and, {{ 2, false, 6, 0 }} },
2700 { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p, {{ 1, false, 6, 0 }} },
2701 { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_nac, {{ 2, false, 6, 0 }} },
2702 { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_or, {{ 2, false, 6, 0 }} },
2703 { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_xacc, {{ 2, false, 6, 0 }} },
2704 { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_acc, {{ 2, false, 5, 0 }} },
2705 { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_and, {{ 2, false, 5, 0 }} },
2706 { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r, {{ 1, false, 5, 0 }} },
2707 { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_nac, {{ 2, false, 5, 0 }} },
2708 { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_or, {{ 2, false, 5, 0 }} },
2709 { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_xacc, {{ 2, false, 5, 0 }} },
2710 { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_vh, {{ 1, false, 4, 0 }} },
2711 { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_vw, {{ 1, false, 5, 0 }} },
2712 { Hexagon::BI__builtin_HEXAGON_S2_setbit_i, {{ 1, false, 5, 0 }} },
2713 { Hexagon::BI__builtin_HEXAGON_S2_tableidxb_goodsyntax,
2714 {{ 2, false, 4, 0 },
2715 { 3, false, 5, 0 }} },
2716 { Hexagon::BI__builtin_HEXAGON_S2_tableidxd_goodsyntax,
2717 {{ 2, false, 4, 0 },
2718 { 3, false, 5, 0 }} },
2719 { Hexagon::BI__builtin_HEXAGON_S2_tableidxh_goodsyntax,
2720 {{ 2, false, 4, 0 },
2721 { 3, false, 5, 0 }} },
2722 { Hexagon::BI__builtin_HEXAGON_S2_tableidxw_goodsyntax,
2723 {{ 2, false, 4, 0 },
2724 { 3, false, 5, 0 }} },
2725 { Hexagon::BI__builtin_HEXAGON_S2_togglebit_i, {{ 1, false, 5, 0 }} },
2726 { Hexagon::BI__builtin_HEXAGON_S2_tstbit_i, {{ 1, false, 5, 0 }} },
2727 { Hexagon::BI__builtin_HEXAGON_S2_valignib, {{ 2, false, 3, 0 }} },
2728 { Hexagon::BI__builtin_HEXAGON_S2_vspliceib, {{ 2, false, 3, 0 }} },
2729 { Hexagon::BI__builtin_HEXAGON_S4_addi_asl_ri, {{ 2, false, 5, 0 }} },
2730 { Hexagon::BI__builtin_HEXAGON_S4_addi_lsr_ri, {{ 2, false, 5, 0 }} },
2731 { Hexagon::BI__builtin_HEXAGON_S4_andi_asl_ri, {{ 2, false, 5, 0 }} },
2732 { Hexagon::BI__builtin_HEXAGON_S4_andi_lsr_ri, {{ 2, false, 5, 0 }} },
2733 { Hexagon::BI__builtin_HEXAGON_S4_clbaddi, {{ 1, true , 6, 0 }} },
2734 { Hexagon::BI__builtin_HEXAGON_S4_clbpaddi, {{ 1, true, 6, 0 }} },
2735 { Hexagon::BI__builtin_HEXAGON_S4_extract, {{ 1, false, 5, 0 },
2736 { 2, false, 5, 0 }} },
2737 { Hexagon::BI__builtin_HEXAGON_S4_extractp, {{ 1, false, 6, 0 },
2738 { 2, false, 6, 0 }} },
2739 { Hexagon::BI__builtin_HEXAGON_S4_lsli, {{ 0, true, 6, 0 }} },
2740 { Hexagon::BI__builtin_HEXAGON_S4_ntstbit_i, {{ 1, false, 5, 0 }} },
2741 { Hexagon::BI__builtin_HEXAGON_S4_ori_asl_ri, {{ 2, false, 5, 0 }} },
2742 { Hexagon::BI__builtin_HEXAGON_S4_ori_lsr_ri, {{ 2, false, 5, 0 }} },
2743 { Hexagon::BI__builtin_HEXAGON_S4_subi_asl_ri, {{ 2, false, 5, 0 }} },
2744 { Hexagon::BI__builtin_HEXAGON_S4_subi_lsr_ri, {{ 2, false, 5, 0 }} },
2745 { Hexagon::BI__builtin_HEXAGON_S4_vrcrotate_acc, {{ 3, false, 2, 0 }} },
2746 { Hexagon::BI__builtin_HEXAGON_S4_vrcrotate, {{ 2, false, 2, 0 }} },
2747 { Hexagon::BI__builtin_HEXAGON_S5_asrhub_rnd_sat_goodsyntax,
2748 {{ 1, false, 4, 0 }} },
2749 { Hexagon::BI__builtin_HEXAGON_S5_asrhub_sat, {{ 1, false, 4, 0 }} },
2750 { Hexagon::BI__builtin_HEXAGON_S5_vasrhrnd_goodsyntax,
2751 {{ 1, false, 4, 0 }} },
2752 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p, {{ 1, false, 6, 0 }} },
2753 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_acc, {{ 2, false, 6, 0 }} },
2754 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_and, {{ 2, false, 6, 0 }} },
2755 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_nac, {{ 2, false, 6, 0 }} },
2756 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_or, {{ 2, false, 6, 0 }} },
2757 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_xacc, {{ 2, false, 6, 0 }} },
2758 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r, {{ 1, false, 5, 0 }} },
2759 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_acc, {{ 2, false, 5, 0 }} },
2760 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_and, {{ 2, false, 5, 0 }} },
2761 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_nac, {{ 2, false, 5, 0 }} },
2762 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_or, {{ 2, false, 5, 0 }} },
2763 { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_xacc, {{ 2, false, 5, 0 }} },
2764 { Hexagon::BI__builtin_HEXAGON_V6_valignbi, {{ 2, false, 3, 0 }} },
2765 { Hexagon::BI__builtin_HEXAGON_V6_valignbi_128B, {{ 2, false, 3, 0 }} },
2766 { Hexagon::BI__builtin_HEXAGON_V6_vlalignbi, {{ 2, false, 3, 0 }} },
2767 { Hexagon::BI__builtin_HEXAGON_V6_vlalignbi_128B, {{ 2, false, 3, 0 }} },
2768 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi, {{ 2, false, 1, 0 }} },
2769 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_128B, {{ 2, false, 1, 0 }} },
2770 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_acc, {{ 3, false, 1, 0 }} },
2771 { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_acc_128B,
2772 {{ 3, false, 1, 0 }} },
2773 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi, {{ 2, false, 1, 0 }} },
2774 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_128B, {{ 2, false, 1, 0 }} },
2775 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_acc, {{ 3, false, 1, 0 }} },
2776 { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_acc_128B,
2777 {{ 3, false, 1, 0 }} },
2778 { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi, {{ 2, false, 1, 0 }} },
2779 { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_128B, {{ 2, false, 1, 0 }} },
2780 { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_acc, {{ 3, false, 1, 0 }} },
2781 { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_acc_128B,
2782 {{ 3, false, 1, 0 }} },
2783 };
2784
2785 // Use a dynamically initialized static to sort the table exactly once on
2786 // first run.
2787 static const bool SortOnce =
2788 (std::sort(std::begin(Infos), std::end(Infos),
2789 [](const BuiltinInfo &LHS, const BuiltinInfo &RHS) {
2790 return LHS.BuiltinID < RHS.BuiltinID;
2791 }),
2792 true);
2793 (void)SortOnce;
2794
2795 const BuiltinInfo *F =
2796 std::lower_bound(std::begin(Infos), std::end(Infos), BuiltinID,
2797 [](const BuiltinInfo &BI, unsigned BuiltinID) {
2798 return BI.BuiltinID < BuiltinID;
2799 });
2800 if (F == std::end(Infos) || F->BuiltinID != BuiltinID)
2801 return false;
2802
2803 bool Error = false;
2804
2805 for (const ArgInfo &A : F->Infos) {
2806 // Ignore empty ArgInfo elements.
2807 if (A.BitWidth == 0)
2808 continue;
2809
2810 int32_t Min = A.IsSigned ? -(1 << (A.BitWidth - 1)) : 0;
2811 int32_t Max = (1 << (A.IsSigned ? A.BitWidth - 1 : A.BitWidth)) - 1;
2812 if (!A.Align) {
2813 Error |= SemaBuiltinConstantArgRange(TheCall, A.OpNum, Min, Max);
2814 } else {
2815 unsigned M = 1 << A.Align;
2816 Min *= M;
2817 Max *= M;
2818 Error |= SemaBuiltinConstantArgRange(TheCall, A.OpNum, Min, Max) |
2819 SemaBuiltinConstantArgMultiple(TheCall, A.OpNum, M);
2820 }
2821 }
2822 return Error;
2823}
2824
2825bool Sema::CheckHexagonBuiltinFunctionCall(unsigned BuiltinID,
2826 CallExpr *TheCall) {
2827 return CheckHexagonBuiltinCpu(BuiltinID, TheCall) ||
2828 CheckHexagonBuiltinArgument(BuiltinID, TheCall);
2829}
2830
2831
2832// CheckMipsBuiltinFunctionCall - Checks the constant value passed to the
2833// intrinsic is correct. The switch statement is ordered by DSP, MSA. The
2834// ordering for DSP is unspecified. MSA is ordered by the data format used
2835// by the underlying instruction i.e., df/m, df/n and then by size.
2836//
2837// FIXME: The size tests here should instead be tablegen'd along with the
2838// definitions from include/clang/Basic/BuiltinsMips.def.
2839// FIXME: GCC is strict on signedness for some of these intrinsics, we should
2840// be too.
2841bool Sema::CheckMipsBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
2842 unsigned i = 0, l = 0, u = 0, m = 0;
2843 switch (BuiltinID) {
2844 default: return false;
2845 case Mips::BI__builtin_mips_wrdsp: i = 1; l = 0; u = 63; break;
2846 case Mips::BI__builtin_mips_rddsp: i = 0; l = 0; u = 63; break;
2847 case Mips::BI__builtin_mips_append: i = 2; l = 0; u = 31; break;
2848 case Mips::BI__builtin_mips_balign: i = 2; l = 0; u = 3; break;
2849 case Mips::BI__builtin_mips_precr_sra_ph_w: i = 2; l = 0; u = 31; break;
2850 case Mips::BI__builtin_mips_precr_sra_r_ph_w: i = 2; l = 0; u = 31; break;
2851 case Mips::BI__builtin_mips_prepend: i = 2; l = 0; u = 31; break;
2852 // MSA instrinsics. Instructions (which the intrinsics maps to) which use the
2853 // df/m field.
2854 // These intrinsics take an unsigned 3 bit immediate.
2855 case Mips::BI__builtin_msa_bclri_b:
2856 case Mips::BI__builtin_msa_bnegi_b:
2857 case Mips::BI__builtin_msa_bseti_b:
2858 case Mips::BI__builtin_msa_sat_s_b:
2859 case Mips::BI__builtin_msa_sat_u_b:
2860 case Mips::BI__builtin_msa_slli_b:
2861 case Mips::BI__builtin_msa_srai_b:
2862 case Mips::BI__builtin_msa_srari_b:
2863 case Mips::BI__builtin_msa_srli_b:
2864 case Mips::BI__builtin_msa_srlri_b: i = 1; l = 0; u = 7; break;
2865 case Mips::BI__builtin_msa_binsli_b:
2866 case Mips::BI__builtin_msa_binsri_b: i = 2; l = 0; u = 7; break;
2867 // These intrinsics take an unsigned 4 bit immediate.
2868 case Mips::BI__builtin_msa_bclri_h:
2869 case Mips::BI__builtin_msa_bnegi_h:
2870 case Mips::BI__builtin_msa_bseti_h:
2871 case Mips::BI__builtin_msa_sat_s_h:
2872 case Mips::BI__builtin_msa_sat_u_h:
2873 case Mips::BI__builtin_msa_slli_h:
2874 case Mips::BI__builtin_msa_srai_h:
2875 case Mips::BI__builtin_msa_srari_h:
2876 case Mips::BI__builtin_msa_srli_h:
2877 case Mips::BI__builtin_msa_srlri_h: i = 1; l = 0; u = 15; break;
2878 case Mips::BI__builtin_msa_binsli_h:
2879 case Mips::BI__builtin_msa_binsri_h: i = 2; l = 0; u = 15; break;
2880 // These intrinsics take an unsigned 5 bit immediate.
2881 // The first block of intrinsics actually have an unsigned 5 bit field,
2882 // not a df/n field.
2883 case Mips::BI__builtin_msa_clei_u_b:
2884 case Mips::BI__builtin_msa_clei_u_h:
2885 case Mips::BI__builtin_msa_clei_u_w:
2886 case Mips::BI__builtin_msa_clei_u_d:
2887 case Mips::BI__builtin_msa_clti_u_b:
2888 case Mips::BI__builtin_msa_clti_u_h:
2889 case Mips::BI__builtin_msa_clti_u_w:
2890 case Mips::BI__builtin_msa_clti_u_d:
2891 case Mips::BI__builtin_msa_maxi_u_b:
2892 case Mips::BI__builtin_msa_maxi_u_h:
2893 case Mips::BI__builtin_msa_maxi_u_w:
2894 case Mips::BI__builtin_msa_maxi_u_d:
2895 case Mips::BI__builtin_msa_mini_u_b:
2896 case Mips::BI__builtin_msa_mini_u_h:
2897 case Mips::BI__builtin_msa_mini_u_w:
2898 case Mips::BI__builtin_msa_mini_u_d:
2899 case Mips::BI__builtin_msa_addvi_b:
2900 case Mips::BI__builtin_msa_addvi_h:
2901 case Mips::BI__builtin_msa_addvi_w:
2902 case Mips::BI__builtin_msa_addvi_d:
2903 case Mips::BI__builtin_msa_bclri_w:
2904 case Mips::BI__builtin_msa_bnegi_w:
2905 case Mips::BI__builtin_msa_bseti_w:
2906 case Mips::BI__builtin_msa_sat_s_w:
2907 case Mips::BI__builtin_msa_sat_u_w:
2908 case Mips::BI__builtin_msa_slli_w:
2909 case Mips::BI__builtin_msa_srai_w:
2910 case Mips::BI__builtin_msa_srari_w:
2911 case Mips::BI__builtin_msa_srli_w:
2912 case Mips::BI__builtin_msa_srlri_w:
2913 case Mips::BI__builtin_msa_subvi_b:
2914 case Mips::BI__builtin_msa_subvi_h:
2915 case Mips::BI__builtin_msa_subvi_w:
2916 case Mips::BI__builtin_msa_subvi_d: i = 1; l = 0; u = 31; break;
2917 case Mips::BI__builtin_msa_binsli_w:
2918 case Mips::BI__builtin_msa_binsri_w: i = 2; l = 0; u = 31; break;
2919 // These intrinsics take an unsigned 6 bit immediate.
2920 case Mips::BI__builtin_msa_bclri_d:
2921 case Mips::BI__builtin_msa_bnegi_d:
2922 case Mips::BI__builtin_msa_bseti_d:
2923 case Mips::BI__builtin_msa_sat_s_d:
2924 case Mips::BI__builtin_msa_sat_u_d:
2925 case Mips::BI__builtin_msa_slli_d:
2926 case Mips::BI__builtin_msa_srai_d:
2927 case Mips::BI__builtin_msa_srari_d:
2928 case Mips::BI__builtin_msa_srli_d:
2929 case Mips::BI__builtin_msa_srlri_d: i = 1; l = 0; u = 63; break;
2930 case Mips::BI__builtin_msa_binsli_d:
2931 case Mips::BI__builtin_msa_binsri_d: i = 2; l = 0; u = 63; break;
2932 // These intrinsics take a signed 5 bit immediate.
2933 case Mips::BI__builtin_msa_ceqi_b:
2934 case Mips::BI__builtin_msa_ceqi_h:
2935 case Mips::BI__builtin_msa_ceqi_w:
2936 case Mips::BI__builtin_msa_ceqi_d:
2937 case Mips::BI__builtin_msa_clti_s_b:
2938 case Mips::BI__builtin_msa_clti_s_h:
2939 case Mips::BI__builtin_msa_clti_s_w:
2940 case Mips::BI__builtin_msa_clti_s_d:
2941 case Mips::BI__builtin_msa_clei_s_b:
2942 case Mips::BI__builtin_msa_clei_s_h:
2943 case Mips::BI__builtin_msa_clei_s_w:
2944 case Mips::BI__builtin_msa_clei_s_d:
2945 case Mips::BI__builtin_msa_maxi_s_b:
2946 case Mips::BI__builtin_msa_maxi_s_h:
2947 case Mips::BI__builtin_msa_maxi_s_w:
2948 case Mips::BI__builtin_msa_maxi_s_d:
2949 case Mips::BI__builtin_msa_mini_s_b:
2950 case Mips::BI__builtin_msa_mini_s_h:
2951 case Mips::BI__builtin_msa_mini_s_w:
2952 case Mips::BI__builtin_msa_mini_s_d: i = 1; l = -16; u = 15; break;
2953 // These intrinsics take an unsigned 8 bit immediate.
2954 case Mips::BI__builtin_msa_andi_b:
2955 case Mips::BI__builtin_msa_nori_b:
2956 case Mips::BI__builtin_msa_ori_b:
2957 case Mips::BI__builtin_msa_shf_b:
2958 case Mips::BI__builtin_msa_shf_h:
2959 case Mips::BI__builtin_msa_shf_w:
2960 case Mips::BI__builtin_msa_xori_b: i = 1; l = 0; u = 255; break;
2961 case Mips::BI__builtin_msa_bseli_b:
2962 case Mips::BI__builtin_msa_bmnzi_b:
2963 case Mips::BI__builtin_msa_bmzi_b: i = 2; l = 0; u = 255; break;
2964 // df/n format
2965 // These intrinsics take an unsigned 4 bit immediate.
2966 case Mips::BI__builtin_msa_copy_s_b:
2967 case Mips::BI__builtin_msa_copy_u_b:
2968 case Mips::BI__builtin_msa_insve_b:
2969 case Mips::BI__builtin_msa_splati_b: i = 1; l = 0; u = 15; break;
2970 case Mips::BI__builtin_msa_sldi_b: i = 2; l = 0; u = 15; break;
2971 // These intrinsics take an unsigned 3 bit immediate.
2972 case Mips::BI__builtin_msa_copy_s_h:
2973 case Mips::BI__builtin_msa_copy_u_h:
2974 case Mips::BI__builtin_msa_insve_h:
2975 case Mips::BI__builtin_msa_splati_h: i = 1; l = 0; u = 7; break;
2976 case Mips::BI__builtin_msa_sldi_h: i = 2; l = 0; u = 7; break;
2977 // These intrinsics take an unsigned 2 bit immediate.
2978 case Mips::BI__builtin_msa_copy_s_w:
2979 case Mips::BI__builtin_msa_copy_u_w:
2980 case Mips::BI__builtin_msa_insve_w:
2981 case Mips::BI__builtin_msa_splati_w: i = 1; l = 0; u = 3; break;
2982 case Mips::BI__builtin_msa_sldi_w: i = 2; l = 0; u = 3; break;
2983 // These intrinsics take an unsigned 1 bit immediate.
2984 case Mips::BI__builtin_msa_copy_s_d:
2985 case Mips::BI__builtin_msa_copy_u_d:
2986 case Mips::BI__builtin_msa_insve_d:
2987 case Mips::BI__builtin_msa_splati_d: i = 1; l = 0; u = 1; break;
2988 case Mips::BI__builtin_msa_sldi_d: i = 2; l = 0; u = 1; break;
2989 // Memory offsets and immediate loads.
2990 // These intrinsics take a signed 10 bit immediate.
2991 case Mips::BI__builtin_msa_ldi_b: i = 0; l = -128; u = 255; break;
2992 case Mips::BI__builtin_msa_ldi_h:
2993 case Mips::BI__builtin_msa_ldi_w:
2994 case Mips::BI__builtin_msa_ldi_d: i = 0; l = -512; u = 511; break;
2995 case Mips::BI__builtin_msa_ld_b: i = 1; l = -512; u = 511; m = 16; break;
2996 case Mips::BI__builtin_msa_ld_h: i = 1; l = -1024; u = 1022; m = 16; break;
2997 case Mips::BI__builtin_msa_ld_w: i = 1; l = -2048; u = 2044; m = 16; break;
2998 case Mips::BI__builtin_msa_ld_d: i = 1; l = -4096; u = 4088; m = 16; break;
2999 case Mips::BI__builtin_msa_st_b: i = 2; l = -512; u = 511; m = 16; break;
3000 case Mips::BI__builtin_msa_st_h: i = 2; l = -1024; u = 1022; m = 16; break;
3001 case Mips::BI__builtin_msa_st_w: i = 2; l = -2048; u = 2044; m = 16; break;
3002 case Mips::BI__builtin_msa_st_d: i = 2; l = -4096; u = 4088; m = 16; break;
3003 }
3004
3005 if (!m)
3006 return SemaBuiltinConstantArgRange(TheCall, i, l, u);
3007
3008 return SemaBuiltinConstantArgRange(TheCall, i, l, u) ||
3009 SemaBuiltinConstantArgMultiple(TheCall, i, m);
3010}
3011
3012bool Sema::CheckPPCBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
3013 unsigned i = 0, l = 0, u = 0;
3014 bool Is64BitBltin = BuiltinID == PPC::BI__builtin_divde ||
3015 BuiltinID == PPC::BI__builtin_divdeu ||
3016 BuiltinID == PPC::BI__builtin_bpermd;
3017 bool IsTarget64Bit = Context.getTargetInfo()
3018 .getTypeWidth(Context
3019 .getTargetInfo()
3020 .getIntPtrType()) == 64;
3021 bool IsBltinExtDiv = BuiltinID == PPC::BI__builtin_divwe ||
3022 BuiltinID == PPC::BI__builtin_divweu ||
3023 BuiltinID == PPC::BI__builtin_divde ||
3024 BuiltinID == PPC::BI__builtin_divdeu;
3025
3026 if (Is64BitBltin && !IsTarget64Bit)
3027 return Diag(TheCall->getBeginLoc(), diag::err_64_bit_builtin_32_bit_tgt)
3028 << TheCall->getSourceRange();
3029
3030 if ((IsBltinExtDiv && !Context.getTargetInfo().hasFeature("extdiv")) ||
3031 (BuiltinID == PPC::BI__builtin_bpermd &&
3032 !Context.getTargetInfo().hasFeature("bpermd")))
3033 return Diag(TheCall->getBeginLoc(), diag::err_ppc_builtin_only_on_pwr7)
3034 << TheCall->getSourceRange();
3035
3036 auto SemaVSXCheck = [&](CallExpr *TheCall) -> bool {
3037 if (!Context.getTargetInfo().hasFeature("vsx"))
3038 return Diag(TheCall->getBeginLoc(), diag::err_ppc_builtin_only_on_pwr7)
3039 << TheCall->getSourceRange();
3040 return false;
3041 };
3042
3043 switch (BuiltinID) {
3044 default: return false;
3045 case PPC::BI__builtin_altivec_crypto_vshasigmaw:
3046 case PPC::BI__builtin_altivec_crypto_vshasigmad:
3047 return SemaBuiltinConstantArgRange(TheCall, 1, 0, 1) ||
3048 SemaBuiltinConstantArgRange(TheCall, 2, 0, 15);
3049 case PPC::BI__builtin_tbegin:
3050 case PPC::BI__builtin_tend: i = 0; l = 0; u = 1; break;
3051 case PPC::BI__builtin_tsr: i = 0; l = 0; u = 7; break;
3052 case PPC::BI__builtin_tabortwc:
3053 case PPC::BI__builtin_tabortdc: i = 0; l = 0; u = 31; break;
3054 case PPC::BI__builtin_tabortwci:
3055 case PPC::BI__builtin_tabortdci:
3056 return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31) ||
3057 SemaBuiltinConstantArgRange(TheCall, 2, 0, 31);
3058 case PPC::BI__builtin_vsx_xxpermdi:
3059 case PPC::BI__builtin_vsx_xxsldwi:
3060 return SemaBuiltinVSX(TheCall);
3061 case PPC::BI__builtin_unpack_vector_int128:
3062 return SemaVSXCheck(TheCall) ||
3063 SemaBuiltinConstantArgRange(TheCall, 1, 0, 1);
3064 case PPC::BI__builtin_pack_vector_int128:
3065 return SemaVSXCheck(TheCall);
3066 }
3067 return SemaBuiltinConstantArgRange(TheCall, i, l, u);
3068}
3069
3070bool Sema::CheckSystemZBuiltinFunctionCall(unsigned BuiltinID,
3071 CallExpr *TheCall) {
3072 if (BuiltinID == SystemZ::BI__builtin_tabort) {
3073 Expr *Arg = TheCall->getArg(0);
3074 llvm::APSInt AbortCode(32);
3075 if (Arg->isIntegerConstantExpr(AbortCode, Context) &&
3076 AbortCode.getSExtValue() >= 0 && AbortCode.getSExtValue() < 256)
3077 return Diag(Arg->getBeginLoc(), diag::err_systemz_invalid_tabort_code)
3078 << Arg->getSourceRange();
3079 }
3080
3081 // For intrinsics which take an immediate value as part of the instruction,
3082 // range check them here.
3083 unsigned i = 0, l = 0, u = 0;
3084 switch (BuiltinID) {
3085 default: return false;
3086 case SystemZ::BI__builtin_s390_lcbb: i = 1; l = 0; u = 15; break;
3087 case SystemZ::BI__builtin_s390_verimb:
3088 case SystemZ::BI__builtin_s390_verimh:
3089 case SystemZ::BI__builtin_s390_verimf:
3090 case SystemZ::BI__builtin_s390_verimg: i = 3; l = 0; u = 255; break;
3091 case SystemZ::BI__builtin_s390_vfaeb:
3092 case SystemZ::BI__builtin_s390_vfaeh:
3093 case SystemZ::BI__builtin_s390_vfaef:
3094 case SystemZ::BI__builtin_s390_vfaebs:
3095 case SystemZ::BI__builtin_s390_vfaehs:
3096 case SystemZ::BI__builtin_s390_vfaefs:
3097 case SystemZ::BI__builtin_s390_vfaezb:
3098 case SystemZ::BI__builtin_s390_vfaezh:
3099 case SystemZ::BI__builtin_s390_vfaezf:
3100 case SystemZ::BI__builtin_s390_vfaezbs:
3101 case SystemZ::BI__builtin_s390_vfaezhs:
3102 case SystemZ::BI__builtin_s390_vfaezfs: i = 2; l = 0; u = 15; break;
3103 case SystemZ::BI__builtin_s390_vfisb:
3104 case SystemZ::BI__builtin_s390_vfidb:
3105 return SemaBuiltinConstantArgRange(TheCall, 1, 0, 15) ||
3106 SemaBuiltinConstantArgRange(TheCall, 2, 0, 15);
3107 case SystemZ::BI__builtin_s390_vftcisb:
3108 case SystemZ::BI__builtin_s390_vftcidb: i = 1; l = 0; u = 4095; break;
3109 case SystemZ::BI__builtin_s390_vlbb: i = 1; l = 0; u = 15; break;
3110 case SystemZ::BI__builtin_s390_vpdi: i = 2; l = 0; u = 15; break;
3111 case SystemZ::BI__builtin_s390_vsldb: i = 2; l = 0; u = 15; break;
3112 case SystemZ::BI__builtin_s390_vstrcb:
3113 case SystemZ::BI__builtin_s390_vstrch:
3114 case SystemZ::BI__builtin_s390_vstrcf:
3115 case SystemZ::BI__builtin_s390_vstrczb:
3116 case SystemZ::BI__builtin_s390_vstrczh:
3117 case SystemZ::BI__builtin_s390_vstrczf:
3118 case SystemZ::BI__builtin_s390_vstrcbs:
3119 case SystemZ::BI__builtin_s390_vstrchs:
3120 case SystemZ::BI__builtin_s390_vstrcfs:
3121 case SystemZ::BI__builtin_s390_vstrczbs:
3122 case SystemZ::BI__builtin_s390_vstrczhs:
3123 case SystemZ::BI__builtin_s390_vstrczfs: i = 3; l = 0; u = 15; break;
3124 case SystemZ::BI__builtin_s390_vmslg: i = 3; l = 0; u = 15; break;
3125 case SystemZ::BI__builtin_s390_vfminsb:
3126 case SystemZ::BI__builtin_s390_vfmaxsb:
3127 case SystemZ::BI__builtin_s390_vfmindb:
3128 case SystemZ::BI__builtin_s390_vfmaxdb: i = 2; l = 0; u = 15; break;
3129 }
3130 return SemaBuiltinConstantArgRange(TheCall, i, l, u);
3131}
3132
3133/// SemaBuiltinCpuSupports - Handle __builtin_cpu_supports(char *).
3134/// This checks that the target supports __builtin_cpu_supports and
3135/// that the string argument is constant and valid.
3136static bool SemaBuiltinCpuSupports(Sema &S, CallExpr *TheCall) {
3137 Expr *Arg = TheCall->getArg(0);
3138
3139 // Check if the argument is a string literal.
3140 if (!isa<StringLiteral>(Arg->IgnoreParenImpCasts()))
3141 return S.Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
3142 << Arg->getSourceRange();
3143
3144 // Check the contents of the string.
3145 StringRef Feature =
3146 cast<StringLiteral>(Arg->IgnoreParenImpCasts())->getString();
3147 if (!S.Context.getTargetInfo().validateCpuSupports(Feature))
3148 return S.Diag(TheCall->getBeginLoc(), diag::err_invalid_cpu_supports)
3149 << Arg->getSourceRange();
3150 return false;
3151}
3152
3153/// SemaBuiltinCpuIs - Handle __builtin_cpu_is(char *).
3154/// This checks that the target supports __builtin_cpu_is and
3155/// that the string argument is constant and valid.
3156static bool SemaBuiltinCpuIs(Sema &S, CallExpr *TheCall) {
3157 Expr *Arg = TheCall->getArg(0);
3158
3159 // Check if the argument is a string literal.
3160 if (!isa<StringLiteral>(Arg->IgnoreParenImpCasts()))
3161 return S.Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
3162 << Arg->getSourceRange();
3163
3164 // Check the contents of the string.
3165 StringRef Feature =
3166 cast<StringLiteral>(Arg->IgnoreParenImpCasts())->getString();
3167 if (!S.Context.getTargetInfo().validateCpuIs(Feature))
3168 return S.Diag(TheCall->getBeginLoc(), diag::err_invalid_cpu_is)
3169 << Arg->getSourceRange();
3170 return false;
3171}
3172
3173// Check if the rounding mode is legal.
3174bool Sema::CheckX86BuiltinRoundingOrSAE(unsigned BuiltinID, CallExpr *TheCall) {
3175 // Indicates if this instruction has rounding control or just SAE.
3176 bool HasRC = false;
3177
3178 unsigned ArgNum = 0;
3179 switch (BuiltinID) {
3180 default:
3181 return false;
3182 case X86::BI__builtin_ia32_vcvttsd2si32:
3183 case X86::BI__builtin_ia32_vcvttsd2si64:
3184 case X86::BI__builtin_ia32_vcvttsd2usi32:
3185 case X86::BI__builtin_ia32_vcvttsd2usi64:
3186 case X86::BI__builtin_ia32_vcvttss2si32:
3187 case X86::BI__builtin_ia32_vcvttss2si64:
3188 case X86::BI__builtin_ia32_vcvttss2usi32:
3189 case X86::BI__builtin_ia32_vcvttss2usi64:
3190 ArgNum = 1;
3191 break;
3192 case X86::BI__builtin_ia32_maxpd512:
3193 case X86::BI__builtin_ia32_maxps512:
3194 case X86::BI__builtin_ia32_minpd512:
3195 case X86::BI__builtin_ia32_minps512:
3196 ArgNum = 2;
3197 break;
3198 case X86::BI__builtin_ia32_cvtps2pd512_mask:
3199 case X86::BI__builtin_ia32_cvttpd2dq512_mask:
3200 case X86::BI__builtin_ia32_cvttpd2qq512_mask:
3201 case X86::BI__builtin_ia32_cvttpd2udq512_mask:
3202 case X86::BI__builtin_ia32_cvttpd2uqq512_mask:
3203 case X86::BI__builtin_ia32_cvttps2dq512_mask:
3204 case X86::BI__builtin_ia32_cvttps2qq512_mask:
3205 case X86::BI__builtin_ia32_cvttps2udq512_mask:
3206 case X86::BI__builtin_ia32_cvttps2uqq512_mask:
3207 case X86::BI__builtin_ia32_exp2pd_mask:
3208 case X86::BI__builtin_ia32_exp2ps_mask:
3209 case X86::BI__builtin_ia32_getexppd512_mask:
3210 case X86::BI__builtin_ia32_getexpps512_mask:
3211 case X86::BI__builtin_ia32_rcp28pd_mask:
3212 case X86::BI__builtin_ia32_rcp28ps_mask:
3213 case X86::BI__builtin_ia32_rsqrt28pd_mask:
3214 case X86::BI__builtin_ia32_rsqrt28ps_mask:
3215 case X86::BI__builtin_ia32_vcomisd:
3216 case X86::BI__builtin_ia32_vcomiss:
3217 case X86::BI__builtin_ia32_vcvtph2ps512_mask:
3218 ArgNum = 3;
3219 break;
3220 case X86::BI__builtin_ia32_cmppd512_mask:
3221 case X86::BI__builtin_ia32_cmpps512_mask:
3222 case X86::BI__builtin_ia32_cmpsd_mask:
3223 case X86::BI__builtin_ia32_cmpss_mask:
3224 case X86::BI__builtin_ia32_cvtss2sd_round_mask:
3225 case X86::BI__builtin_ia32_getexpsd128_round_mask:
3226 case X86::BI__builtin_ia32_getexpss128_round_mask:
3227 case X86::BI__builtin_ia32_maxsd_round_mask:
3228 case X86::BI__builtin_ia32_maxss_round_mask:
3229 case X86::BI__builtin_ia32_minsd_round_mask:
3230 case X86::BI__builtin_ia32_minss_round_mask:
3231 case X86::BI__builtin_ia32_rcp28sd_round_mask:
3232 case X86::BI__builtin_ia32_rcp28ss_round_mask:
3233 case X86::BI__builtin_ia32_reducepd512_mask:
3234 case X86::BI__builtin_ia32_reduceps512_mask:
3235 case X86::BI__builtin_ia32_rndscalepd_mask:
3236 case X86::BI__builtin_ia32_rndscaleps_mask:
3237 case X86::BI__builtin_ia32_rsqrt28sd_round_mask:
3238 case X86::BI__builtin_ia32_rsqrt28ss_round_mask:
3239 ArgNum = 4;
3240 break;
3241 case X86::BI__builtin_ia32_fixupimmpd512_mask:
3242 case X86::BI__builtin_ia32_fixupimmpd512_maskz:
3243 case X86::BI__builtin_ia32_fixupimmps512_mask:
3244 case X86::BI__builtin_ia32_fixupimmps512_maskz:
3245 case X86::BI__builtin_ia32_fixupimmsd_mask:
3246 case X86::BI__builtin_ia32_fixupimmsd_maskz:
3247 case X86::BI__builtin_ia32_fixupimmss_mask:
3248 case X86::BI__builtin_ia32_fixupimmss_maskz:
3249 case X86::BI__builtin_ia32_rangepd512_mask:
3250 case X86::BI__builtin_ia32_rangeps512_mask:
3251 case X86::BI__builtin_ia32_rangesd128_round_mask:
3252 case X86::BI__builtin_ia32_rangess128_round_mask:
3253 case X86::BI__builtin_ia32_reducesd_mask:
3254 case X86::BI__builtin_ia32_reducess_mask:
3255 case X86::BI__builtin_ia32_rndscalesd_round_mask:
3256 case X86::BI__builtin_ia32_rndscaless_round_mask:
3257 ArgNum = 5;
3258 break;
3259 case X86::BI__builtin_ia32_vcvtsd2si64:
3260 case X86::BI__builtin_ia32_vcvtsd2si32:
3261 case X86::BI__builtin_ia32_vcvtsd2usi32:
3262 case X86::BI__builtin_ia32_vcvtsd2usi64:
3263 case X86::BI__builtin_ia32_vcvtss2si32:
3264 case X86::BI__builtin_ia32_vcvtss2si64:
3265 case X86::BI__builtin_ia32_vcvtss2usi32:
3266 case X86::BI__builtin_ia32_vcvtss2usi64:
3267 case X86::BI__builtin_ia32_sqrtpd512:
3268 case X86::BI__builtin_ia32_sqrtps512:
3269 ArgNum = 1;
3270 HasRC = true;
3271 break;
3272 case X86::BI__builtin_ia32_addpd512:
3273 case X86::BI__builtin_ia32_addps512:
3274 case X86::BI__builtin_ia32_divpd512:
3275 case X86::BI__builtin_ia32_divps512:
3276 case X86::BI__builtin_ia32_mulpd512:
3277 case X86::BI__builtin_ia32_mulps512:
3278 case X86::BI__builtin_ia32_subpd512:
3279 case X86::BI__builtin_ia32_subps512:
3280 case X86::BI__builtin_ia32_cvtsi2sd64:
3281 case X86::BI__builtin_ia32_cvtsi2ss32:
3282 case X86::BI__builtin_ia32_cvtsi2ss64:
3283 case X86::BI__builtin_ia32_cvtusi2sd64:
3284 case X86::BI__builtin_ia32_cvtusi2ss32:
3285 case X86::BI__builtin_ia32_cvtusi2ss64:
3286 ArgNum = 2;
3287 HasRC = true;
3288 break;
3289 case X86::BI__builtin_ia32_cvtdq2ps512_mask:
3290 case X86::BI__builtin_ia32_cvtudq2ps512_mask:
3291 case X86::BI__builtin_ia32_cvtpd2ps512_mask:
3292 case X86::BI__builtin_ia32_cvtpd2qq512_mask:
3293 case X86::BI__builtin_ia32_cvtpd2uqq512_mask:
3294 case X86::BI__builtin_ia32_cvtps2qq512_mask:
3295 case X86::BI__builtin_ia32_cvtps2uqq512_mask:
3296 case X86::BI__builtin_ia32_cvtqq2pd512_mask:
3297 case X86::BI__builtin_ia32_cvtqq2ps512_mask:
3298 case X86::BI__builtin_ia32_cvtuqq2pd512_mask:
3299 case X86::BI__builtin_ia32_cvtuqq2ps512_mask:
3300 ArgNum = 3;
3301 HasRC = true;
3302 break;
3303 case X86::BI__builtin_ia32_addss_round_mask:
3304 case X86::BI__builtin_ia32_addsd_round_mask:
3305 case X86::BI__builtin_ia32_divss_round_mask:
3306 case X86::BI__builtin_ia32_divsd_round_mask:
3307 case X86::BI__builtin_ia32_mulss_round_mask:
3308 case X86::BI__builtin_ia32_mulsd_round_mask:
3309 case X86::BI__builtin_ia32_subss_round_mask:
3310 case X86::BI__builtin_ia32_subsd_round_mask:
3311 case X86::BI__builtin_ia32_scalefpd512_mask:
3312 case X86::BI__builtin_ia32_scalefps512_mask:
3313 case X86::BI__builtin_ia32_scalefsd_round_mask:
3314 case X86::BI__builtin_ia32_scalefss_round_mask:
3315 case X86::BI__builtin_ia32_getmantpd512_mask:
3316 case X86::BI__builtin_ia32_getmantps512_mask:
3317 case X86::BI__builtin_ia32_cvtsd2ss_round_mask:
3318 case X86::BI__builtin_ia32_sqrtsd_round_mask:
3319 case X86::BI__builtin_ia32_sqrtss_round_mask:
3320 case X86::BI__builtin_ia32_vfmaddsd3_mask:
3321 case X86::BI__builtin_ia32_vfmaddsd3_maskz:
3322 case X86::BI__builtin_ia32_vfmaddsd3_mask3:
3323 case X86::BI__builtin_ia32_vfmaddss3_mask:
3324 case X86::BI__builtin_ia32_vfmaddss3_maskz:
3325 case X86::BI__builtin_ia32_vfmaddss3_mask3:
3326 case X86::BI__builtin_ia32_vfmaddpd512_mask:
3327 case X86::BI__builtin_ia32_vfmaddpd512_maskz:
3328 case X86::BI__builtin_ia32_vfmaddpd512_mask3:
3329 case X86::BI__builtin_ia32_vfmsubpd512_mask3:
3330 case X86::BI__builtin_ia32_vfmaddps512_mask:
3331 case X86::BI__builtin_ia32_vfmaddps512_maskz:
3332 case X86::BI__builtin_ia32_vfmaddps512_mask3:
3333 case X86::BI__builtin_ia32_vfmsubps512_mask3:
3334 case X86::BI__builtin_ia32_vfmaddsubpd512_mask:
3335 case X86::BI__builtin_ia32_vfmaddsubpd512_maskz:
3336 case X86::BI__builtin_ia32_vfmaddsubpd512_mask3:
3337 case X86::BI__builtin_ia32_vfmsubaddpd512_mask3:
3338 case X86::BI__builtin_ia32_vfmaddsubps512_mask:
3339 case X86::BI__builtin_ia32_vfmaddsubps512_maskz:
3340 case X86::BI__builtin_ia32_vfmaddsubps512_mask3:
3341 case X86::BI__builtin_ia32_vfmsubaddps512_mask3:
3342 ArgNum = 4;
3343 HasRC = true;
3344 break;
3345 case X86::BI__builtin_ia32_getmantsd_round_mask:
3346 case X86::BI__builtin_ia32_getmantss_round_mask:
3347 ArgNum = 5;
3348 HasRC = true;
3349 break;
3350 }
3351
3352 llvm::APSInt Result;
3353
3354 // We can't check the value of a dependent argument.
3355 Expr *Arg = TheCall->getArg(ArgNum);
3356 if (Arg->isTypeDependent() || Arg->isValueDependent())
3357 return false;
3358
3359 // Check constant-ness first.
3360 if (SemaBuiltinConstantArg(TheCall, ArgNum, Result))
3361 return true;
3362
3363 // Make sure rounding mode is either ROUND_CUR_DIRECTION or ROUND_NO_EXC bit
3364 // is set. If the intrinsic has rounding control(bits 1:0), make sure its only
3365 // combined with ROUND_NO_EXC.
3366 if (Result == 4/*ROUND_CUR_DIRECTION*/ ||
3367 Result == 8/*ROUND_NO_EXC*/ ||
3368 (HasRC && Result.getZExtValue() >= 8 && Result.getZExtValue() <= 11))
3369 return false;
3370
3371 return Diag(TheCall->getBeginLoc(), diag::err_x86_builtin_invalid_rounding)
3372 << Arg->getSourceRange();
3373}
3374
3375// Check if the gather/scatter scale is legal.
3376bool Sema::CheckX86BuiltinGatherScatterScale(unsigned BuiltinID,
3377 CallExpr *TheCall) {
3378 unsigned ArgNum = 0;
3379 switch (BuiltinID) {
3380 default:
3381 return false;
3382 case X86::BI__builtin_ia32_gatherpfdpd:
3383 case X86::BI__builtin_ia32_gatherpfdps:
3384 case X86::BI__builtin_ia32_gatherpfqpd:
3385 case X86::BI__builtin_ia32_gatherpfqps:
3386 case X86::BI__builtin_ia32_scatterpfdpd:
3387 case X86::BI__builtin_ia32_scatterpfdps:
3388 case X86::BI__builtin_ia32_scatterpfqpd:
3389 case X86::BI__builtin_ia32_scatterpfqps:
3390 ArgNum = 3;
3391 break;
3392 case X86::BI__builtin_ia32_gatherd_pd:
3393 case X86::BI__builtin_ia32_gatherd_pd256:
3394 case X86::BI__builtin_ia32_gatherq_pd:
3395 case X86::BI__builtin_ia32_gatherq_pd256:
3396 case X86::BI__builtin_ia32_gatherd_ps:
3397 case X86::BI__builtin_ia32_gatherd_ps256:
3398 case X86::BI__builtin_ia32_gatherq_ps:
3399 case X86::BI__builtin_ia32_gatherq_ps256:
3400 case X86::BI__builtin_ia32_gatherd_q:
3401 case X86::BI__builtin_ia32_gatherd_q256:
3402 case X86::BI__builtin_ia32_gatherq_q:
3403 case X86::BI__builtin_ia32_gatherq_q256:
3404 case X86::BI__builtin_ia32_gatherd_d:
3405 case X86::BI__builtin_ia32_gatherd_d256:
3406 case X86::BI__builtin_ia32_gatherq_d:
3407 case X86::BI__builtin_ia32_gatherq_d256:
3408 case X86::BI__builtin_ia32_gather3div2df:
3409 case X86::BI__builtin_ia32_gather3div2di:
3410 case X86::BI__builtin_ia32_gather3div4df:
3411 case X86::BI__builtin_ia32_gather3div4di:
3412 case X86::BI__builtin_ia32_gather3div4sf:
3413 case X86::BI__builtin_ia32_gather3div4si:
3414 case X86::BI__builtin_ia32_gather3div8sf:
3415 case X86::BI__builtin_ia32_gather3div8si:
3416 case X86::BI__builtin_ia32_gather3siv2df:
3417 case X86::BI__builtin_ia32_gather3siv2di:
3418 case X86::BI__builtin_ia32_gather3siv4df:
3419 case X86::BI__builtin_ia32_gather3siv4di:
3420 case X86::BI__builtin_ia32_gather3siv4sf:
3421 case X86::BI__builtin_ia32_gather3siv4si:
3422 case X86::BI__builtin_ia32_gather3siv8sf:
3423 case X86::BI__builtin_ia32_gather3siv8si:
3424 case X86::BI__builtin_ia32_gathersiv8df:
3425 case X86::BI__builtin_ia32_gathersiv16sf:
3426 case X86::BI__builtin_ia32_gatherdiv8df:
3427 case X86::BI__builtin_ia32_gatherdiv16sf:
3428 case X86::BI__builtin_ia32_gathersiv8di:
3429 case X86::BI__builtin_ia32_gathersiv16si:
3430 case X86::BI__builtin_ia32_gatherdiv8di:
3431 case X86::BI__builtin_ia32_gatherdiv16si:
3432 case X86::BI__builtin_ia32_scatterdiv2df:
3433 case X86::BI__builtin_ia32_scatterdiv2di:
3434 case X86::BI__builtin_ia32_scatterdiv4df:
3435 case X86::BI__builtin_ia32_scatterdiv4di:
3436 case X86::BI__builtin_ia32_scatterdiv4sf:
3437 case X86::BI__builtin_ia32_scatterdiv4si:
3438 case X86::BI__builtin_ia32_scatterdiv8sf:
3439 case X86::BI__builtin_ia32_scatterdiv8si:
3440 case X86::BI__builtin_ia32_scattersiv2df:
3441 case X86::BI__builtin_ia32_scattersiv2di:
3442 case X86::BI__builtin_ia32_scattersiv4df:
3443 case X86::BI__builtin_ia32_scattersiv4di:
3444 case X86::BI__builtin_ia32_scattersiv4sf:
3445 case X86::BI__builtin_ia32_scattersiv4si:
3446 case X86::BI__builtin_ia32_scattersiv8sf:
3447 case X86::BI__builtin_ia32_scattersiv8si:
3448 case X86::BI__builtin_ia32_scattersiv8df:
3449 case X86::BI__builtin_ia32_scattersiv16sf:
3450 case X86::BI__builtin_ia32_scatterdiv8df:
3451 case X86::BI__builtin_ia32_scatterdiv16sf:
3452 case X86::BI__builtin_ia32_scattersiv8di:
3453 case X86::BI__builtin_ia32_scattersiv16si:
3454 case X86::BI__builtin_ia32_scatterdiv8di:
3455 case X86::BI__builtin_ia32_scatterdiv16si:
3456 ArgNum = 4;
3457 break;
3458 }
3459
3460 llvm::APSInt Result;
3461
3462 // We can't check the value of a dependent argument.
3463 Expr *Arg = TheCall->getArg(ArgNum);
3464 if (Arg->isTypeDependent() || Arg->isValueDependent())
3465 return false;
3466
3467 // Check constant-ness first.
3468 if (SemaBuiltinConstantArg(TheCall, ArgNum, Result))
3469 return true;
3470
3471 if (Result == 1 || Result == 2 || Result == 4 || Result == 8)
3472 return false;
3473
3474 return Diag(TheCall->getBeginLoc(), diag::err_x86_builtin_invalid_scale)
3475 << Arg->getSourceRange();
3476}
3477
3478static bool isX86_32Builtin(unsigned BuiltinID) {
3479 // These builtins only work on x86-32 targets.
3480 switch (BuiltinID) {
3481 case X86::BI__builtin_ia32_readeflags_u32:
3482 case X86::BI__builtin_ia32_writeeflags_u32:
3483 return true;
3484 }
3485
3486 return false;
3487}
3488
3489bool Sema::CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
3490 if (BuiltinID == X86::BI__builtin_cpu_supports)
3491 return SemaBuiltinCpuSupports(*this, TheCall);
3492
3493 if (BuiltinID == X86::BI__builtin_cpu_is)
3494 return SemaBuiltinCpuIs(*this, TheCall);
3495
3496 // Check for 32-bit only builtins on a 64-bit target.
3497 const llvm::Triple &TT = Context.getTargetInfo().getTriple();
3498 if (TT.getArch() != llvm::Triple::x86 && isX86_32Builtin(BuiltinID))
3499 return Diag(TheCall->getCallee()->getBeginLoc(),
3500 diag::err_32_bit_builtin_64_bit_tgt);
3501
3502 // If the intrinsic has rounding or SAE make sure its valid.
3503 if (CheckX86BuiltinRoundingOrSAE(BuiltinID, TheCall))
3504 return true;
3505
3506 // If the intrinsic has a gather/scatter scale immediate make sure its valid.
3507 if (CheckX86BuiltinGatherScatterScale(BuiltinID, TheCall))
3508 return true;
3509
3510 // For intrinsics which take an immediate value as part of the instruction,
3511 // range check them here.
3512 int i = 0, l = 0, u = 0;
3513 switch (BuiltinID) {
3514 default:
3515 return false;
3516 case X86::BI__builtin_ia32_vec_ext_v2si:
3517 case X86::BI__builtin_ia32_vec_ext_v2di:
3518 case X86::BI__builtin_ia32_vextractf128_pd256:
3519 case X86::BI__builtin_ia32_vextractf128_ps256:
3520 case X86::BI__builtin_ia32_vextractf128_si256:
3521 case X86::BI__builtin_ia32_extract128i256:
3522 case X86::BI__builtin_ia32_extractf64x4_mask:
3523 case X86::BI__builtin_ia32_extracti64x4_mask:
3524 case X86::BI__builtin_ia32_extractf32x8_mask:
3525 case X86::BI__builtin_ia32_extracti32x8_mask:
3526 case X86::BI__builtin_ia32_extractf64x2_256_mask:
3527 case X86::BI__builtin_ia32_extracti64x2_256_mask:
3528 case X86::BI__builtin_ia32_extractf32x4_256_mask:
3529 case X86::BI__builtin_ia32_extracti32x4_256_mask:
3530 i = 1; l = 0; u = 1;
3531 break;
3532 case X86::BI__builtin_ia32_vec_set_v2di:
3533 case X86::BI__builtin_ia32_vinsertf128_pd256:
3534 case X86::BI__builtin_ia32_vinsertf128_ps256:
3535 case X86::BI__builtin_ia32_vinsertf128_si256:
3536 case X86::BI__builtin_ia32_insert128i256:
3537 case X86::BI__builtin_ia32_insertf32x8:
3538 case X86::BI__builtin_ia32_inserti32x8:
3539 case X86::BI__builtin_ia32_insertf64x4:
3540 case X86::BI__builtin_ia32_inserti64x4:
3541 case X86::BI__builtin_ia32_insertf64x2_256:
3542 case X86::BI__builtin_ia32_inserti64x2_256:
3543 case X86::BI__builtin_ia32_insertf32x4_256:
3544 case X86::BI__builtin_ia32_inserti32x4_256:
3545 i = 2; l = 0; u = 1;
3546 break;
3547 case X86::BI__builtin_ia32_vpermilpd:
3548 case X86::BI__builtin_ia32_vec_ext_v4hi:
3549 case X86::BI__builtin_ia32_vec_ext_v4si:
3550 case X86::BI__builtin_ia32_vec_ext_v4sf:
3551 case X86::BI__builtin_ia32_vec_ext_v4di:
3552 case X86::BI__builtin_ia32_extractf32x4_mask:
3553 case X86::BI__builtin_ia32_extracti32x4_mask:
3554 case X86::BI__builtin_ia32_extractf64x2_512_mask:
3555 case X86::BI__builtin_ia32_extracti64x2_512_mask:
3556 i = 1; l = 0; u = 3;
3557 break;
3558 case X86::BI_mm_prefetch:
3559 case X86::BI__builtin_ia32_vec_ext_v8hi:
3560 case X86::BI__builtin_ia32_vec_ext_v8si:
3561 i = 1; l = 0; u = 7;
3562 break;
3563 case X86::BI__builtin_ia32_sha1rnds4:
3564 case X86::BI__builtin_ia32_blendpd:
3565 case X86::BI__builtin_ia32_shufpd:
3566 case X86::BI__builtin_ia32_vec_set_v4hi:
3567 case X86::BI__builtin_ia32_vec_set_v4si:
3568 case X86::BI__builtin_ia32_vec_set_v4di:
3569 case X86::BI__builtin_ia32_shuf_f32x4_256:
3570 case X86::BI__builtin_ia32_shuf_f64x2_256:
3571 case X86::BI__builtin_ia32_shuf_i32x4_256:
3572 case X86::BI__builtin_ia32_shuf_i64x2_256:
3573 case X86::BI__builtin_ia32_insertf64x2_512:
3574 case X86::BI__builtin_ia32_inserti64x2_512:
3575 case X86::BI__builtin_ia32_insertf32x4:
3576 case X86::BI__builtin_ia32_inserti32x4:
3577 i = 2; l = 0; u = 3;
3578 break;
3579 case X86::BI__builtin_ia32_vpermil2pd:
3580 case X86::BI__builtin_ia32_vpermil2pd256:
3581 case X86::BI__builtin_ia32_vpermil2ps:
3582 case X86::BI__builtin_ia32_vpermil2ps256:
3583 i = 3; l = 0; u = 3;
3584 break;
3585 case X86::BI__builtin_ia32_cmpb128_mask:
3586 case X86::BI__builtin_ia32_cmpw128_mask:
3587 case X86::BI__builtin_ia32_cmpd128_mask:
3588 case X86::BI__builtin_ia32_cmpq128_mask:
3589 case X86::BI__builtin_ia32_cmpb256_mask:
3590 case X86::BI__builtin_ia32_cmpw256_mask:
3591 case X86::BI__builtin_ia32_cmpd256_mask:
3592 case X86::BI__builtin_ia32_cmpq256_mask:
3593 case X86::BI__builtin_ia32_cmpb512_mask:
3594 case X86::BI__builtin_ia32_cmpw512_mask:
3595 case X86::BI__builtin_ia32_cmpd512_mask:
3596 case X86::BI__builtin_ia32_cmpq512_mask:
3597 case X86::BI__builtin_ia32_ucmpb128_mask:
3598 case X86::BI__builtin_ia32_ucmpw128_mask:
3599 case X86::BI__builtin_ia32_ucmpd128_mask:
3600 case X86::BI__builtin_ia32_ucmpq128_mask:
3601 case X86::BI__builtin_ia32_ucmpb256_mask:
3602 case X86::BI__builtin_ia32_ucmpw256_mask:
3603 case X86::BI__builtin_ia32_ucmpd256_mask:
3604 case X86::BI__builtin_ia32_ucmpq256_mask:
3605 case X86::BI__builtin_ia32_ucmpb512_mask:
3606 case X86::BI__builtin_ia32_ucmpw512_mask:
3607 case X86::BI__builtin_ia32_ucmpd512_mask:
3608 case X86::BI__builtin_ia32_ucmpq512_mask:
3609 case X86::BI__builtin_ia32_vpcomub:
3610 case X86::BI__builtin_ia32_vpcomuw:
3611 case X86::BI__builtin_ia32_vpcomud:
3612 case X86::BI__builtin_ia32_vpcomuq:
3613 case X86::BI__builtin_ia32_vpcomb:
3614 case X86::BI__builtin_ia32_vpcomw:
3615 case X86::BI__builtin_ia32_vpcomd:
3616 case X86::BI__builtin_ia32_vpcomq:
3617 case X86::BI__builtin_ia32_vec_set_v8hi:
3618 case X86::BI__builtin_ia32_vec_set_v8si:
3619 i = 2; l = 0; u = 7;
3620 break;
3621 case X86::BI__builtin_ia32_vpermilpd256:
3622 case X86::BI__builtin_ia32_roundps:
3623 case X86::BI__builtin_ia32_roundpd:
3624 case X86::BI__builtin_ia32_roundps256:
3625 case X86::BI__builtin_ia32_roundpd256:
3626 case X86::BI__builtin_ia32_getmantpd128_mask:
3627 case X86::BI__builtin_ia32_getmantpd256_mask:
3628 case X86::BI__builtin_ia32_getmantps128_mask:
3629 case X86::BI__builtin_ia32_getmantps256_mask:
3630 case X86::BI__builtin_ia32_getmantpd512_mask:
3631 case X86::BI__builtin_ia32_getmantps512_mask:
3632 case X86::BI__builtin_ia32_vec_ext_v16qi:
3633 case X86::BI__builtin_ia32_vec_ext_v16hi:
3634 i = 1; l = 0; u = 15;
3635 break;
3636 case X86::BI__builtin_ia32_pblendd128:
3637 case X86::BI__builtin_ia32_blendps:
3638 case X86::BI__builtin_ia32_blendpd256:
3639 case X86::BI__builtin_ia32_shufpd256:
3640 case X86::BI__builtin_ia32_roundss:
3641 case X86::BI__builtin_ia32_roundsd:
3642 case X86::BI__builtin_ia32_rangepd128_mask:
3643 case X86::BI__builtin_ia32_rangepd256_mask:
3644 case X86::BI__builtin_ia32_rangepd512_mask:
3645 case X86::BI__builtin_ia32_rangeps128_mask:
3646 case X86::BI__builtin_ia32_rangeps256_mask:
3647 case X86::BI__builtin_ia32_rangeps512_mask:
3648 case X86::BI__builtin_ia32_getmantsd_round_mask:
3649 case X86::BI__builtin_ia32_getmantss_round_mask:
3650 case X86::BI__builtin_ia32_vec_set_v16qi:
3651 case X86::BI__builtin_ia32_vec_set_v16hi:
3652 i = 2; l = 0; u = 15;
3653 break;
3654 case X86::BI__builtin_ia32_vec_ext_v32qi:
3655 i = 1; l = 0; u = 31;
3656 break;
3657 case X86::BI__builtin_ia32_cmpps:
3658 case X86::BI__builtin_ia32_cmpss:
3659 case X86::BI__builtin_ia32_cmppd:
3660 case X86::BI__builtin_ia32_cmpsd:
3661 case X86::BI__builtin_ia32_cmpps256:
3662 case X86::BI__builtin_ia32_cmppd256:
3663 case X86::BI__builtin_ia32_cmpps128_mask:
3664 case X86::BI__builtin_ia32_cmppd128_mask:
3665 case X86::BI__builtin_ia32_cmpps256_mask:
3666 case X86::BI__builtin_ia32_cmppd256_mask:
3667 case X86::BI__builtin_ia32_cmpps512_mask:
3668 case X86::BI__builtin_ia32_cmppd512_mask:
3669 case X86::BI__builtin_ia32_cmpsd_mask:
3670 case X86::BI__builtin_ia32_cmpss_mask:
3671 case X86::BI__builtin_ia32_vec_set_v32qi:
3672 i = 2; l = 0; u = 31;
3673 break;
3674 case X86::BI__builtin_ia32_permdf256:
3675 case X86::BI__builtin_ia32_permdi256:
3676 case X86::BI__builtin_ia32_permdf512:
3677 case X86::BI__builtin_ia32_permdi512:
3678 case X86::BI__builtin_ia32_vpermilps:
3679 case X86::BI__builtin_ia32_vpermilps256:
3680 case X86::BI__builtin_ia32_vpermilpd512:
3681 case X86::BI__builtin_ia32_vpermilps512:
3682 case X86::BI__builtin_ia32_pshufd:
3683 case X86::BI__builtin_ia32_pshufd256:
3684 case X86::BI__builtin_ia32_pshufd512:
3685 case X86::BI__builtin_ia32_pshufhw:
3686 case X86::BI__builtin_ia32_pshufhw256:
3687 case X86::BI__builtin_ia32_pshufhw512:
3688 case X86::BI__builtin_ia32_pshuflw:
3689 case X86::BI__builtin_ia32_pshuflw256:
3690 case X86::BI__builtin_ia32_pshuflw512:
3691 case X86::BI__builtin_ia32_vcvtps2ph:
3692 case X86::BI__builtin_ia32_vcvtps2ph_mask:
3693 case X86::BI__builtin_ia32_vcvtps2ph256:
3694 case X86::BI__builtin_ia32_vcvtps2ph256_mask:
3695 case X86::BI__builtin_ia32_vcvtps2ph512_mask:
3696 case X86::BI__builtin_ia32_rndscaleps_128_mask:
3697 case X86::BI__builtin_ia32_rndscalepd_128_mask:
3698 case X86::BI__builtin_ia32_rndscaleps_256_mask:
3699 case X86::BI__builtin_ia32_rndscalepd_256_mask:
3700 case X86::BI__builtin_ia32_rndscaleps_mask:
3701 case X86::BI__builtin_ia32_rndscalepd_mask:
3702 case X86::BI__builtin_ia32_reducepd128_mask:
3703 case X86::BI__builtin_ia32_reducepd256_mask:
3704 case X86::BI__builtin_ia32_reducepd512_mask:
3705 case X86::BI__builtin_ia32_reduceps128_mask:
3706 case X86::BI__builtin_ia32_reduceps256_mask:
3707 case X86::BI__builtin_ia32_reduceps512_mask:
3708 case X86::BI__builtin_ia32_prold512:
3709 case X86::BI__builtin_ia32_prolq512:
3710 case X86::BI__builtin_ia32_prold128:
3711 case X86::BI__builtin_ia32_prold256:
3712 case X86::BI__builtin_ia32_prolq128:
3713 case X86::BI__builtin_ia32_prolq256:
3714 case X86::BI__builtin_ia32_prord512:
3715 case X86::BI__builtin_ia32_prorq512:
3716 case X86::BI__builtin_ia32_prord128:
3717 case X86::BI__builtin_ia32_prord256:
3718 case X86::BI__builtin_ia32_prorq128:
3719 case X86::BI__builtin_ia32_prorq256:
3720 case X86::BI__builtin_ia32_fpclasspd128_mask:
3721 case X86::BI__builtin_ia32_fpclasspd256_mask:
3722 case X86::BI__builtin_ia32_fpclassps128_mask:
3723 case X86::BI__builtin_ia32_fpclassps256_mask:
3724 case X86::BI__builtin_ia32_fpclassps512_mask:
3725 case X86::BI__builtin_ia32_fpclasspd512_mask:
3726 case X86::BI__builtin_ia32_fpclasssd_mask:
3727 case X86::BI__builtin_ia32_fpclassss_mask:
3728 case X86::BI__builtin_ia32_pslldqi128_byteshift:
3729 case X86::BI__builtin_ia32_pslldqi256_byteshift:
3730 case X86::BI__builtin_ia32_pslldqi512_byteshift:
3731 case X86::BI__builtin_ia32_psrldqi128_byteshift:
3732 case X86::BI__builtin_ia32_psrldqi256_byteshift:
3733 case X86::BI__builtin_ia32_psrldqi512_byteshift:
3734 case X86::BI__builtin_ia32_kshiftliqi:
3735 case X86::BI__builtin_ia32_kshiftlihi:
3736 case X86::BI__builtin_ia32_kshiftlisi:
3737 case X86::BI__builtin_ia32_kshiftlidi:
3738 case X86::BI__builtin_ia32_kshiftriqi:
3739 case X86::BI__builtin_ia32_kshiftrihi:
3740 case X86::BI__builtin_ia32_kshiftrisi:
3741 case X86::BI__builtin_ia32_kshiftridi:
3742 i = 1; l = 0; u = 255;
3743 break;
3744 case X86::BI__builtin_ia32_vperm2f128_pd256:
3745 case X86::BI__builtin_ia32_vperm2f128_ps256:
3746 case X86::BI__builtin_ia32_vperm2f128_si256:
3747 case X86::BI__builtin_ia32_permti256:
3748 case X86::BI__builtin_ia32_pblendw128:
3749 case X86::BI__builtin_ia32_pblendw256:
3750 case X86::BI__builtin_ia32_blendps256:
3751 case X86::BI__builtin_ia32_pblendd256:
3752 case X86::BI__builtin_ia32_palignr128:
3753 case X86::BI__builtin_ia32_palignr256:
3754 case X86::BI__builtin_ia32_palignr512:
3755 case X86::BI__builtin_ia32_alignq512:
3756 case X86::BI__builtin_ia32_alignd512:
3757 case X86::BI__builtin_ia32_alignd128:
3758 case X86::BI__builtin_ia32_alignd256:
3759 case X86::BI__builtin_ia32_alignq128:
3760 case X86::BI__builtin_ia32_alignq256:
3761 case X86::BI__builtin_ia32_vcomisd:
3762 case X86::BI__builtin_ia32_vcomiss:
3763 case X86::BI__builtin_ia32_shuf_f32x4:
3764 case X86::BI__builtin_ia32_shuf_f64x2:
3765 case X86::BI__builtin_ia32_shuf_i32x4:
3766 case X86::BI__builtin_ia32_shuf_i64x2:
3767 case X86::BI__builtin_ia32_shufpd512:
3768 case X86::BI__builtin_ia32_shufps:
3769 case X86::BI__builtin_ia32_shufps256:
3770 case X86::BI__builtin_ia32_shufps512:
3771 case X86::BI__builtin_ia32_dbpsadbw128:
3772 case X86::BI__builtin_ia32_dbpsadbw256:
3773 case X86::BI__builtin_ia32_dbpsadbw512:
3774 case X86::BI__builtin_ia32_vpshldd128:
3775 case X86::BI__builtin_ia32_vpshldd256:
3776 case X86::BI__builtin_ia32_vpshldd512:
3777 case X86::BI__builtin_ia32_vpshldq128:
3778 case X86::BI__builtin_ia32_vpshldq256:
3779 case X86::BI__builtin_ia32_vpshldq512:
3780 case X86::BI__builtin_ia32_vpshldw128:
3781 case X86::BI__builtin_ia32_vpshldw256:
3782 case X86::BI__builtin_ia32_vpshldw512:
3783 case X86::BI__builtin_ia32_vpshrdd128:
3784 case X86::BI__builtin_ia32_vpshrdd256:
3785 case X86::BI__builtin_ia32_vpshrdd512:
3786 case X86::BI__builtin_ia32_vpshrdq128:
3787 case X86::BI__builtin_ia32_vpshrdq256:
3788 case X86::BI__builtin_ia32_vpshrdq512:
3789 case X86::BI__builtin_ia32_vpshrdw128:
3790 case X86::BI__builtin_ia32_vpshrdw256:
3791 case X86::BI__builtin_ia32_vpshrdw512:
3792 i = 2; l = 0; u = 255;
3793 break;
3794 case X86::BI__builtin_ia32_fixupimmpd512_mask:
3795 case X86::BI__builtin_ia32_fixupimmpd512_maskz:
3796 case X86::BI__builtin_ia32_fixupimmps512_mask:
3797 case X86::BI__builtin_ia32_fixupimmps512_maskz:
3798 case X86::BI__builtin_ia32_fixupimmsd_mask:
3799 case X86::BI__builtin_ia32_fixupimmsd_maskz:
3800 case X86::BI__builtin_ia32_fixupimmss_mask:
3801 case X86::BI__builtin_ia32_fixupimmss_maskz:
3802 case X86::BI__builtin_ia32_fixupimmpd128_mask:
3803 case X86::BI__builtin_ia32_fixupimmpd128_maskz:
3804 case X86::BI__builtin_ia32_fixupimmpd256_mask:
3805 case X86::BI__builtin_ia32_fixupimmpd256_maskz:
3806 case X86::BI__builtin_ia32_fixupimmps128_mask:
3807 case X86::BI__builtin_ia32_fixupimmps128_maskz:
3808 case X86::BI__builtin_ia32_fixupimmps256_mask:
3809 case X86::BI__builtin_ia32_fixupimmps256_maskz:
3810 case X86::BI__builtin_ia32_pternlogd512_mask:
3811 case X86::BI__builtin_ia32_pternlogd512_maskz:
3812 case X86::BI__builtin_ia32_pternlogq512_mask:
3813 case X86::BI__builtin_ia32_pternlogq512_maskz:
3814 case X86::BI__builtin_ia32_pternlogd128_mask:
3815 case X86::BI__builtin_ia32_pternlogd128_maskz:
3816 case X86::BI__builtin_ia32_pternlogd256_mask:
3817 case X86::BI__builtin_ia32_pternlogd256_maskz:
3818 case X86::BI__builtin_ia32_pternlogq128_mask:
3819 case X86::BI__builtin_ia32_pternlogq128_maskz:
3820 case X86::BI__builtin_ia32_pternlogq256_mask:
3821 case X86::BI__builtin_ia32_pternlogq256_maskz:
3822 i = 3; l = 0; u = 255;
3823 break;
3824 case X86::BI__builtin_ia32_gatherpfdpd:
3825 case X86::BI__builtin_ia32_gatherpfdps:
3826 case X86::BI__builtin_ia32_gatherpfqpd:
3827 case X86::BI__builtin_ia32_gatherpfqps:
3828 case X86::BI__builtin_ia32_scatterpfdpd:
3829 case X86::BI__builtin_ia32_scatterpfdps:
3830 case X86::BI__builtin_ia32_scatterpfqpd:
3831 case X86::BI__builtin_ia32_scatterpfqps:
3832 i = 4; l = 2; u = 3;
3833 break;
3834 case X86::BI__builtin_ia32_rndscalesd_round_mask:
3835 case X86::BI__builtin_ia32_rndscaless_round_mask:
3836 i = 4; l = 0; u = 255;
3837 break;
3838 }
3839
3840 // Note that we don't force a hard error on the range check here, allowing
3841 // template-generated or macro-generated dead code to potentially have out-of-
3842 // range values. These need to code generate, but don't need to necessarily
3843 // make any sense. We use a warning that defaults to an error.
3844 return SemaBuiltinConstantArgRange(TheCall, i, l, u, /*RangeIsError*/ false);
3845}
3846
3847/// Given a FunctionDecl's FormatAttr, attempts to populate the FomatStringInfo
3848/// parameter with the FormatAttr's correct format_idx and firstDataArg.
3849/// Returns true when the format fits the function and the FormatStringInfo has
3850/// been populated.
3851bool Sema::getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember,
3852 FormatStringInfo *FSI) {
3853 FSI->HasVAListArg = Format->getFirstArg() == 0;
3854 FSI->FormatIdx = Format->getFormatIdx() - 1;
3855 FSI->FirstDataArg = FSI->HasVAListArg ? 0 : Format->getFirstArg() - 1;
3856
3857 // The way the format attribute works in GCC, the implicit this argument
3858 // of member functions is counted. However, it doesn't appear in our own
3859 // lists, so decrement format_idx in that case.
3860 if (IsCXXMember) {
3861 if(FSI->FormatIdx == 0)
3862 return false;
3863 --FSI->FormatIdx;
3864 if (FSI->FirstDataArg != 0)
3865 --FSI->FirstDataArg;
3866 }
3867 return true;
3868}
3869
3870/// Checks if a the given expression evaluates to null.
3871///
3872/// Returns true if the value evaluates to null.
3873static bool CheckNonNullExpr(Sema &S, const Expr *Expr) {
3874 // If the expression has non-null type, it doesn't evaluate to null.
3875 if (auto nullability
3876 = Expr->IgnoreImplicit()->getType()->getNullability(S.Context)) {
3877 if (*nullability == NullabilityKind::NonNull)
3878 return false;
3879 }
3880
3881 // As a special case, transparent unions initialized with zero are
3882 // considered null for the purposes of the nonnull attribute.
3883 if (const RecordType *UT = Expr->getType()->getAsUnionType()) {
3884 if (UT->getDecl()->hasAttr<TransparentUnionAttr>())
3885 if (const CompoundLiteralExpr *CLE =
3886 dyn_cast<CompoundLiteralExpr>(Expr))
3887 if (const InitListExpr *ILE =
3888 dyn_cast<InitListExpr>(CLE->getInitializer()))
3889 Expr = ILE->getInit(0);
3890 }
3891
3892 bool Result;
3893 return (!Expr->isValueDependent() &&
3894 Expr->EvaluateAsBooleanCondition(Result, S.Context) &&
3895 !Result);
3896}
3897
3898static void CheckNonNullArgument(Sema &S,
3899 const Expr *ArgExpr,
3900 SourceLocation CallSiteLoc) {
3901 if (CheckNonNullExpr(S, ArgExpr))
3902 S.DiagRuntimeBehavior(CallSiteLoc, ArgExpr,
3903 S.PDiag(diag::warn_null_arg) << ArgExpr->getSourceRange());
3904}
3905
3906bool Sema::GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx) {
3907 FormatStringInfo FSI;
3908 if ((GetFormatStringType(Format) == FST_NSString) &&
3909 getFormatStringInfo(Format, false, &FSI)) {
3910 Idx = FSI.FormatIdx;
3911 return true;
3912 }
3913 return false;
3914}
3915
3916/// Diagnose use of %s directive in an NSString which is being passed
3917/// as formatting string to formatting method.
3918static void
3919DiagnoseCStringFormatDirectiveInCFAPI(Sema &S,
3920 const NamedDecl *FDecl,
3921 Expr **Args,
3922 unsigned NumArgs) {
3923 unsigned Idx = 0;
3924 bool Format = false;
3925 ObjCStringFormatFamily SFFamily = FDecl->getObjCFStringFormattingFamily();
3926 if (SFFamily == ObjCStringFormatFamily::SFF_CFString) {
3927 Idx = 2;
3928 Format = true;
3929 }
3930 else
3931 for (const auto *I : FDecl->specific_attrs<FormatAttr>()) {
3932 if (S.GetFormatNSStringIdx(I, Idx)) {
3933 Format = true;
3934 break;
3935 }
3936 }
3937 if (!Format || NumArgs <= Idx)
3938 return;
3939 const Expr *FormatExpr = Args[Idx];
3940 if (const CStyleCastExpr *CSCE = dyn_cast<CStyleCastExpr>(FormatExpr))
3941 FormatExpr = CSCE->getSubExpr();
3942 const StringLiteral *FormatString;
3943 if (const ObjCStringLiteral *OSL =
3944 dyn_cast<ObjCStringLiteral>(FormatExpr->IgnoreParenImpCasts()))
3945 FormatString = OSL->getString();
3946 else
3947 FormatString = dyn_cast<StringLiteral>(FormatExpr->IgnoreParenImpCasts());
3948 if (!FormatString)
3949 return;
3950 if (S.FormatStringHasSArg(FormatString)) {
3951 S.Diag(FormatExpr->getExprLoc(), diag::warn_objc_cdirective_format_string)
3952 << "%s" << 1 << 1;
3953 S.Diag(FDecl->getLocation(), diag::note_entity_declared_at)
3954 << FDecl->getDeclName();
3955 }
3956}
3957
3958/// Determine whether the given type has a non-null nullability annotation.
3959static bool isNonNullType(ASTContext &ctx, QualType type) {
3960 if (auto nullability = type->getNullability(ctx))
3961 return *nullability == NullabilityKind::NonNull;
3962
3963 return false;
3964}
3965
3966static void CheckNonNullArguments(Sema &S,
3967 const NamedDecl *FDecl,
3968 const FunctionProtoType *Proto,
3969 ArrayRef<const Expr *> Args,
3970 SourceLocation CallSiteLoc) {
3971 assert((FDecl || Proto) && "Need a function declaration or prototype")(((FDecl || Proto) && "Need a function declaration or prototype"
) ? static_cast<void> (0) : __assert_fail ("(FDecl || Proto) && \"Need a function declaration or prototype\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 3971, __PRETTY_FUNCTION__))
;
3972
3973 // Check the attributes attached to the method/function itself.
3974 llvm::SmallBitVector NonNullArgs;
3975 if (FDecl) {
9
Taking false branch
3976 // Handle the nonnull attribute on the function/method declaration itself.
3977 for (const auto *NonNull : FDecl->specific_attrs<NonNullAttr>()) {
3978 if (!NonNull->args_size()) {
3979 // Easy case: all pointer arguments are nonnull.
3980 for (const auto *Arg : Args)
3981 if (S.isValidPointerAttrType(Arg->getType()))
3982 CheckNonNullArgument(S, Arg, CallSiteLoc);
3983 return;
3984 }
3985
3986 for (const ParamIdx &Idx : NonNull->args()) {
3987 unsigned IdxAST = Idx.getASTIndex();
3988 if (IdxAST >= Args.size())
3989 continue;
3990 if (NonNullArgs.empty())
3991 NonNullArgs.resize(Args.size());
3992 NonNullArgs.set(IdxAST);
3993 }
3994 }
3995 }
3996
3997 if (FDecl && (isa<FunctionDecl>(FDecl) || isa<ObjCMethodDecl>(FDecl))) {
3998 // Handle the nonnull attribute on the parameters of the
3999 // function/method.
4000 ArrayRef<ParmVarDecl*> parms;
4001 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(FDecl))
4002 parms = FD->parameters();
4003 else
4004 parms = cast<ObjCMethodDecl>(FDecl)->parameters();
4005
4006 unsigned ParamIndex = 0;
4007 for (ArrayRef<ParmVarDecl*>::iterator I = parms.begin(), E = parms.end();
4008 I != E; ++I, ++ParamIndex) {
4009 const ParmVarDecl *PVD = *I;
4010 if (PVD->hasAttr<NonNullAttr>() ||
4011 isNonNullType(S.Context, PVD->getType())) {
4012 if (NonNullArgs.empty())
4013 NonNullArgs.resize(Args.size());
4014
4015 NonNullArgs.set(ParamIndex);
4016 }
4017 }
4018 } else {
4019 // If we have a non-function, non-method declaration but no
4020 // function prototype, try to dig out the function prototype.
4021 if (!Proto) {
10
Taking false branch
4022 if (const ValueDecl *VD = dyn_cast<ValueDecl>(FDecl)) {
4023 QualType type = VD->getType().getNonReferenceType();
4024 if (auto pointerType = type->getAs<PointerType>())
4025 type = pointerType->getPointeeType();
4026 else if (auto blockType = type->getAs<BlockPointerType>())
4027 type = blockType->getPointeeType();
4028 // FIXME: data member pointers?
4029
4030 // Dig out the function prototype, if there is one.
4031 Proto = type->getAs<FunctionProtoType>();
4032 }
4033 }
4034
4035 // Fill in non-null argument information from the nullability
4036 // information on the parameter types (if we have them).
4037 if (Proto) {
11
Taking true branch
4038 unsigned Index = 0;
4039 for (auto paramType : Proto->getParamTypes()) {
12
Assuming '__begin3' is not equal to '__end3'
4040 if (isNonNullType(S.Context, paramType)) {
13
Taking true branch
4041 if (NonNullArgs.empty())
14
Taking true branch
4042 NonNullArgs.resize(Args.size());
15
Calling 'SmallBitVector::resize'
21
Returned allocated memory
4043
4044 NonNullArgs.set(Index);
22
Calling 'SmallBitVector::set'
4045 }
4046
4047 ++Index;
4048 }
4049 }
4050 }
4051
4052 // Check for non-null arguments.
4053 for (unsigned ArgIndex = 0, ArgIndexEnd = NonNullArgs.size();
4054 ArgIndex != ArgIndexEnd; ++ArgIndex) {
4055 if (NonNullArgs[ArgIndex])
4056 CheckNonNullArgument(S, Args[ArgIndex], CallSiteLoc);
4057 }
4058}
4059
4060/// Handles the checks for format strings, non-POD arguments to vararg
4061/// functions, NULL arguments passed to non-NULL parameters, and diagnose_if
4062/// attributes.
4063void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
4064 const Expr *ThisArg, ArrayRef<const Expr *> Args,
4065 bool IsMemberFunction, SourceLocation Loc,
4066 SourceRange Range, VariadicCallType CallType) {
4067 // FIXME: We should check as much as we can in the template definition.
4068 if (CurContext->isDependentContext())
2
Assuming the condition is false
3
Taking false branch
4069 return;
4070
4071 // Printf and scanf checking.
4072 llvm::SmallBitVector CheckedVarArgs;
4073 if (FDecl) {
4
Taking false branch
4074 for (const auto *I : FDecl->specific_attrs<FormatAttr>()) {
4075 // Only create vector if there are format attributes.
4076 CheckedVarArgs.resize(Args.size());
4077
4078 CheckFormatArguments(I, Args, IsMemberFunction, CallType, Loc, Range,
4079 CheckedVarArgs);
4080 }
4081 }
4082
4083 // Refuse POD arguments that weren't caught by the format string
4084 // checks above.
4085 auto *FD = dyn_cast_or_null<FunctionDecl>(FDecl);
4086 if (CallType != VariadicDoesNotApply &&
5
Assuming 'CallType' is equal to VariadicDoesNotApply
4087 (!FD || FD->getBuiltinID() != Builtin::BI__noop)) {
4088 unsigned NumParams = Proto ? Proto->getNumParams()
4089 : FDecl && isa<FunctionDecl>(FDecl)
4090 ? cast<FunctionDecl>(FDecl)->getNumParams()
4091 : FDecl && isa<ObjCMethodDecl>(FDecl)
4092 ? cast<ObjCMethodDecl>(FDecl)->param_size()
4093 : 0;
4094
4095 for (unsigned ArgIdx = NumParams; ArgIdx < Args.size(); ++ArgIdx) {
4096 // Args[ArgIdx] can be null in malformed code.
4097 if (const Expr *Arg = Args[ArgIdx]) {
4098 if (CheckedVarArgs.empty() || !CheckedVarArgs[ArgIdx])
4099 checkVariadicArgument(Arg, CallType);
4100 }
4101 }
4102 }
4103
4104 if (FDecl || Proto) {
6
Assuming 'Proto' is non-null
7
Taking true branch
4105 CheckNonNullArguments(*this, FDecl, Proto, Args, Loc);
8
Calling 'CheckNonNullArguments'
4106
4107 // Type safety checking.
4108 if (FDecl) {
4109 for (const auto *I : FDecl->specific_attrs<ArgumentWithTypeTagAttr>())
4110 CheckArgumentWithTypeTag(I, Args, Loc);
4111 }
4112 }
4113
4114 if (FD)
4115 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
4116}
4117
4118/// CheckConstructorCall - Check a constructor call for correctness and safety
4119/// properties not enforced by the C type system.
4120void Sema::CheckConstructorCall(FunctionDecl *FDecl,
4121 ArrayRef<const Expr *> Args,
4122 const FunctionProtoType *Proto,
4123 SourceLocation Loc) {
4124 VariadicCallType CallType =
4125 Proto->isVariadic() ? VariadicConstructor : VariadicDoesNotApply;
4126 checkCall(FDecl, Proto, /*ThisArg=*/nullptr, Args, /*IsMemberFunction=*/true,
4127 Loc, SourceRange(), CallType);
4128}
4129
4130/// CheckFunctionCall - Check a direct function call for various correctness
4131/// and safety properties not strictly enforced by the C type system.
4132bool Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
4133 const FunctionProtoType *Proto) {
4134 bool IsMemberOperatorCall = isa<CXXOperatorCallExpr>(TheCall) &&
4135 isa<CXXMethodDecl>(FDecl);
4136 bool IsMemberFunction = isa<CXXMemberCallExpr>(TheCall) ||
4137 IsMemberOperatorCall;
4138 VariadicCallType CallType = getVariadicCallType(FDecl, Proto,
4139 TheCall->getCallee());
4140 Expr** Args = TheCall->getArgs();
4141 unsigned NumArgs = TheCall->getNumArgs();
4142
4143 Expr *ImplicitThis = nullptr;
4144 if (IsMemberOperatorCall) {
4145 // If this is a call to a member operator, hide the first argument
4146 // from checkCall.
4147 // FIXME: Our choice of AST representation here is less than ideal.
4148 ImplicitThis = Args[0];
4149 ++Args;
4150 --NumArgs;
4151 } else if (IsMemberFunction)
4152 ImplicitThis =
4153 cast<CXXMemberCallExpr>(TheCall)->getImplicitObjectArgument();
4154
4155 checkCall(FDecl, Proto, ImplicitThis, llvm::makeArrayRef(Args, NumArgs),
4156 IsMemberFunction, TheCall->getRParenLoc(),
4157 TheCall->getCallee()->getSourceRange(), CallType);
4158
4159 IdentifierInfo *FnInfo = FDecl->getIdentifier();
4160 // None of the checks below are needed for functions that don't have
4161 // simple names (e.g., C++ conversion functions).
4162 if (!FnInfo)
4163 return false;
4164
4165 CheckAbsoluteValueFunction(TheCall, FDecl);
4166 CheckMaxUnsignedZero(TheCall, FDecl);
4167
4168 if (getLangOpts().ObjC1)
4169 DiagnoseCStringFormatDirectiveInCFAPI(*this, FDecl, Args, NumArgs);
4170
4171 unsigned CMId = FDecl->getMemoryFunctionKind();
4172 if (CMId == 0)
4173 return false;
4174
4175 // Handle memory setting and copying functions.
4176// if (CMId == Builtin::BIstrlcpy || CMId == Builtin::BIstrlcat)
4177// CheckStrlcpycatArguments(TheCall, FnInfo);
4178// else
4179 if (CMId == Builtin::BIstrncat)
4180 CheckStrncatArguments(TheCall, FnInfo);
4181 else
4182 CheckMemaccessArguments(TheCall, CMId, FnInfo);
4183
4184 return false;
4185}
4186
4187bool Sema::CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation lbrac,
4188 ArrayRef<const Expr *> Args) {
4189 VariadicCallType CallType =
4190 Method->isVariadic() ? VariadicMethod : VariadicDoesNotApply;
4191
4192 checkCall(Method, nullptr, /*ThisArg=*/nullptr, Args,
4193 /*IsMemberFunction=*/false, lbrac, Method->getSourceRange(),
4194 CallType);
4195
4196 return false;
4197}
4198
4199bool Sema::CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall,
4200 const FunctionProtoType *Proto) {
4201 QualType Ty;
4202 if (const auto *V = dyn_cast<VarDecl>(NDecl))
4203 Ty = V->getType().getNonReferenceType();
4204 else if (const auto *F = dyn_cast<FieldDecl>(NDecl))
4205 Ty = F->getType().getNonReferenceType();
4206 else
4207 return false;
4208
4209 if (!Ty->isBlockPointerType() && !Ty->isFunctionPointerType() &&
4210 !Ty->isFunctionProtoType())
4211 return false;
4212
4213 VariadicCallType CallType;
4214 if (!Proto || !Proto->isVariadic()) {
4215 CallType = VariadicDoesNotApply;
4216 } else if (Ty->isBlockPointerType()) {
4217 CallType = VariadicBlock;
4218 } else { // Ty->isFunctionPointerType()
4219 CallType = VariadicFunction;
4220 }
4221
4222 checkCall(NDecl, Proto, /*ThisArg=*/nullptr,
4223 llvm::makeArrayRef(TheCall->getArgs(), TheCall->getNumArgs()),
4224 /*IsMemberFunction=*/false, TheCall->getRParenLoc(),
4225 TheCall->getCallee()->getSourceRange(), CallType);
4226
4227 return false;
4228}
4229
4230/// Checks function calls when a FunctionDecl or a NamedDecl is not available,
4231/// such as function pointers returned from functions.
4232bool Sema::CheckOtherCall(CallExpr *TheCall, const FunctionProtoType *Proto) {
4233 VariadicCallType CallType = getVariadicCallType(/*FDecl=*/nullptr, Proto,
4234 TheCall->getCallee());
4235 checkCall(/*FDecl=*/nullptr, Proto, /*ThisArg=*/nullptr,
1
Calling 'Sema::checkCall'
4236 llvm::makeArrayRef(TheCall->getArgs(), TheCall->getNumArgs()),
4237 /*IsMemberFunction=*/false, TheCall->getRParenLoc(),
4238 TheCall->getCallee()->getSourceRange(), CallType);
4239
4240 return false;
4241}
4242
4243static bool isValidOrderingForOp(int64_t Ordering, AtomicExpr::AtomicOp Op) {
4244 if (!llvm::isValidAtomicOrderingCABI(Ordering))
4245 return false;
4246
4247 auto OrderingCABI = (llvm::AtomicOrderingCABI)Ordering;
4248 switch (Op) {
4249 case AtomicExpr::AO__c11_atomic_init:
4250 case AtomicExpr::AO__opencl_atomic_init:
4251 llvm_unreachable("There is no ordering argument for an init")::llvm::llvm_unreachable_internal("There is no ordering argument for an init"
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 4251)
;
4252
4253 case AtomicExpr::AO__c11_atomic_load:
4254 case AtomicExpr::AO__opencl_atomic_load:
4255 case AtomicExpr::AO__atomic_load_n:
4256 case AtomicExpr::AO__atomic_load:
4257 return OrderingCABI != llvm::AtomicOrderingCABI::release &&
4258 OrderingCABI != llvm::AtomicOrderingCABI::acq_rel;
4259
4260 case AtomicExpr::AO__c11_atomic_store:
4261 case AtomicExpr::AO__opencl_atomic_store:
4262 case AtomicExpr::AO__atomic_store:
4263 case AtomicExpr::AO__atomic_store_n:
4264 return OrderingCABI != llvm::AtomicOrderingCABI::consume &&
4265 OrderingCABI != llvm::AtomicOrderingCABI::acquire &&
4266 OrderingCABI != llvm::AtomicOrderingCABI::acq_rel;
4267
4268 default:
4269 return true;
4270 }
4271}
4272
4273ExprResult Sema::SemaAtomicOpsOverloaded(ExprResult TheCallResult,
4274 AtomicExpr::AtomicOp Op) {
4275 CallExpr *TheCall = cast<CallExpr>(TheCallResult.get());
4276 DeclRefExpr *DRE =cast<DeclRefExpr>(TheCall->getCallee()->IgnoreParenCasts());
4277
4278 // All the non-OpenCL operations take one of the following forms.
4279 // The OpenCL operations take the __c11 forms with one extra argument for
4280 // synchronization scope.
4281 enum {
4282 // C __c11_atomic_init(A *, C)
4283 Init,
4284
4285 // C __c11_atomic_load(A *, int)
4286 Load,
4287
4288 // void __atomic_load(A *, CP, int)
4289 LoadCopy,
4290
4291 // void __atomic_store(A *, CP, int)
4292 Copy,
4293
4294 // C __c11_atomic_add(A *, M, int)
4295 Arithmetic,
4296
4297 // C __atomic_exchange_n(A *, CP, int)
4298 Xchg,
4299
4300 // void __atomic_exchange(A *, C *, CP, int)
4301 GNUXchg,
4302
4303 // bool __c11_atomic_compare_exchange_strong(A *, C *, CP, int, int)
4304 C11CmpXchg,
4305
4306 // bool __atomic_compare_exchange(A *, C *, CP, bool, int, int)
4307 GNUCmpXchg
4308 } Form = Init;
4309
4310 const unsigned NumForm = GNUCmpXchg + 1;
4311 const unsigned NumArgs[] = { 2, 2, 3, 3, 3, 3, 4, 5, 6 };
4312 const unsigned NumVals[] = { 1, 0, 1, 1, 1, 1, 2, 2, 3 };
4313 // where:
4314 // C is an appropriate type,
4315 // A is volatile _Atomic(C) for __c11 builtins and is C for GNU builtins,
4316 // CP is C for __c11 builtins and GNU _n builtins and is C * otherwise,
4317 // M is C if C is an integer, and ptrdiff_t if C is a pointer, and
4318 // the int parameters are for orderings.
4319
4320 static_assert(sizeof(NumArgs)/sizeof(NumArgs[0]) == NumForm
4321 && sizeof(NumVals)/sizeof(NumVals[0]) == NumForm,
4322 "need to update code for modified forms");
4323 static_assert(AtomicExpr::AO__c11_atomic_init == 0 &&
4324 AtomicExpr::AO__c11_atomic_fetch_xor + 1 ==
4325 AtomicExpr::AO__atomic_load,
4326 "need to update code for modified C11 atomics");
4327 bool IsOpenCL = Op >= AtomicExpr::AO__opencl_atomic_init &&
4328 Op <= AtomicExpr::AO__opencl_atomic_fetch_max;
4329 bool IsC11 = (Op >= AtomicExpr::AO__c11_atomic_init &&
4330 Op <= AtomicExpr::AO__c11_atomic_fetch_xor) ||
4331 IsOpenCL;
4332 bool IsN = Op == AtomicExpr::AO__atomic_load_n ||
4333 Op == AtomicExpr::AO__atomic_store_n ||
4334 Op == AtomicExpr::AO__atomic_exchange_n ||
4335 Op == AtomicExpr::AO__atomic_compare_exchange_n;
4336 bool IsAddSub = false;
4337 bool IsMinMax = false;
4338
4339 switch (Op) {
4340 case AtomicExpr::AO__c11_atomic_init:
4341 case AtomicExpr::AO__opencl_atomic_init:
4342 Form = Init;
4343 break;
4344
4345 case AtomicExpr::AO__c11_atomic_load:
4346 case AtomicExpr::AO__opencl_atomic_load:
4347 case AtomicExpr::AO__atomic_load_n:
4348 Form = Load;
4349 break;
4350
4351 case AtomicExpr::AO__atomic_load:
4352 Form = LoadCopy;
4353 break;
4354
4355 case AtomicExpr::AO__c11_atomic_store:
4356 case AtomicExpr::AO__opencl_atomic_store:
4357 case AtomicExpr::AO__atomic_store:
4358 case AtomicExpr::AO__atomic_store_n:
4359 Form = Copy;
4360 break;
4361
4362 case AtomicExpr::AO__c11_atomic_fetch_add:
4363 case AtomicExpr::AO__c11_atomic_fetch_sub:
4364 case AtomicExpr::AO__opencl_atomic_fetch_add:
4365 case AtomicExpr::AO__opencl_atomic_fetch_sub:
4366 case AtomicExpr::AO__opencl_atomic_fetch_min:
4367 case AtomicExpr::AO__opencl_atomic_fetch_max:
4368 case AtomicExpr::AO__atomic_fetch_add:
4369 case AtomicExpr::AO__atomic_fetch_sub:
4370 case AtomicExpr::AO__atomic_add_fetch:
4371 case AtomicExpr::AO__atomic_sub_fetch:
4372 IsAddSub = true;
4373 LLVM_FALLTHROUGH[[clang::fallthrough]];
4374 case AtomicExpr::AO__c11_atomic_fetch_and:
4375 case AtomicExpr::AO__c11_atomic_fetch_or:
4376 case AtomicExpr::AO__c11_atomic_fetch_xor:
4377 case AtomicExpr::AO__opencl_atomic_fetch_and:
4378 case AtomicExpr::AO__opencl_atomic_fetch_or:
4379 case AtomicExpr::AO__opencl_atomic_fetch_xor:
4380 case AtomicExpr::AO__atomic_fetch_and:
4381 case AtomicExpr::AO__atomic_fetch_or:
4382 case AtomicExpr::AO__atomic_fetch_xor:
4383 case AtomicExpr::AO__atomic_fetch_nand:
4384 case AtomicExpr::AO__atomic_and_fetch:
4385 case AtomicExpr::AO__atomic_or_fetch:
4386 case AtomicExpr::AO__atomic_xor_fetch:
4387 case AtomicExpr::AO__atomic_nand_fetch:
4388 Form = Arithmetic;
4389 break;
4390
4391 case AtomicExpr::AO__atomic_fetch_min:
4392 case AtomicExpr::AO__atomic_fetch_max:
4393 IsMinMax = true;
4394 Form = Arithmetic;
4395 break;
4396
4397 case AtomicExpr::AO__c11_atomic_exchange:
4398 case AtomicExpr::AO__opencl_atomic_exchange:
4399 case AtomicExpr::AO__atomic_exchange_n:
4400 Form = Xchg;
4401 break;
4402
4403 case AtomicExpr::AO__atomic_exchange:
4404 Form = GNUXchg;
4405 break;
4406
4407 case AtomicExpr::AO__c11_atomic_compare_exchange_strong:
4408 case AtomicExpr::AO__c11_atomic_compare_exchange_weak:
4409 case AtomicExpr::AO__opencl_atomic_compare_exchange_strong:
4410 case AtomicExpr::AO__opencl_atomic_compare_exchange_weak:
4411 Form = C11CmpXchg;
4412 break;
4413
4414 case AtomicExpr::AO__atomic_compare_exchange:
4415 case AtomicExpr::AO__atomic_compare_exchange_n:
4416 Form = GNUCmpXchg;
4417 break;
4418 }
4419
4420 unsigned AdjustedNumArgs = NumArgs[Form];
4421 if (IsOpenCL && Op != AtomicExpr::AO__opencl_atomic_init)
4422 ++AdjustedNumArgs;
4423 // Check we have the right number of arguments.
4424 if (TheCall->getNumArgs() < AdjustedNumArgs) {
4425 Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args)
4426 << 0 << AdjustedNumArgs << TheCall->getNumArgs()
4427 << TheCall->getCallee()->getSourceRange();
4428 return ExprError();
4429 } else if (TheCall->getNumArgs() > AdjustedNumArgs) {
4430 Diag(TheCall->getArg(AdjustedNumArgs)->getBeginLoc(),
4431 diag::err_typecheck_call_too_many_args)
4432 << 0 << AdjustedNumArgs << TheCall->getNumArgs()
4433 << TheCall->getCallee()->getSourceRange();
4434 return ExprError();
4435 }
4436
4437 // Inspect the first argument of the atomic operation.
4438 Expr *Ptr = TheCall->getArg(0);
4439 ExprResult ConvertedPtr = DefaultFunctionArrayLvalueConversion(Ptr);
4440 if (ConvertedPtr.isInvalid())
4441 return ExprError();
4442
4443 Ptr = ConvertedPtr.get();
4444 const PointerType *pointerType = Ptr->getType()->getAs<PointerType>();
4445 if (!pointerType) {
4446 Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_must_be_pointer)
4447 << Ptr->getType() << Ptr->getSourceRange();
4448 return ExprError();
4449 }
4450
4451 // For a __c11 builtin, this should be a pointer to an _Atomic type.
4452 QualType AtomTy = pointerType->getPointeeType(); // 'A'
4453 QualType ValType = AtomTy; // 'C'
4454 if (IsC11) {
4455 if (!AtomTy->isAtomicType()) {
4456 Diag(DRE->getBeginLoc(), diag::err_atomic_op_needs_atomic)
4457 << Ptr->getType() << Ptr->getSourceRange();
4458 return ExprError();
4459 }
4460 if ((Form != Load && Form != LoadCopy && AtomTy.isConstQualified()) ||
4461 AtomTy.getAddressSpace() == LangAS::opencl_constant) {
4462 Diag(DRE->getBeginLoc(), diag::err_atomic_op_needs_non_const_atomic)
4463 << (AtomTy.isConstQualified() ? 0 : 1) << Ptr->getType()
4464 << Ptr->getSourceRange();
4465 return ExprError();
4466 }
4467 ValType = AtomTy->getAs<AtomicType>()->getValueType();
4468 } else if (Form != Load && Form != LoadCopy) {
4469 if (ValType.isConstQualified()) {
4470 Diag(DRE->getBeginLoc(), diag::err_atomic_op_needs_non_const_pointer)
4471 << Ptr->getType() << Ptr->getSourceRange();
4472 return ExprError();
4473 }
4474 }
4475
4476 // For an arithmetic operation, the implied arithmetic must be well-formed.
4477 if (Form == Arithmetic) {
4478 // gcc does not enforce these rules for GNU atomics, but we do so for sanity.
4479 if (IsAddSub && !ValType->isIntegerType()
4480 && !ValType->isPointerType()) {
4481 Diag(DRE->getBeginLoc(), diag::err_atomic_op_needs_atomic_int_or_ptr)
4482 << IsC11 << Ptr->getType() << Ptr->getSourceRange();
4483 return ExprError();
4484 }
4485 if (IsMinMax) {
4486 const BuiltinType *BT = ValType->getAs<BuiltinType>();
4487 if (!BT || (BT->getKind() != BuiltinType::Int &&
4488 BT->getKind() != BuiltinType::UInt)) {
4489 Diag(DRE->getBeginLoc(), diag::err_atomic_op_needs_int32_or_ptr);
4490 return ExprError();
4491 }
4492 }
4493 if (!IsAddSub && !IsMinMax && !ValType->isIntegerType()) {
4494 Diag(DRE->getBeginLoc(), diag::err_atomic_op_bitwise_needs_atomic_int)
4495 << IsC11 << Ptr->getType() << Ptr->getSourceRange();
4496 return ExprError();
4497 }
4498 if (IsC11 && ValType->isPointerType() &&
4499 RequireCompleteType(Ptr->getBeginLoc(), ValType->getPointeeType(),
4500 diag::err_incomplete_type)) {
4501 return ExprError();
4502 }
4503 } else if (IsN && !ValType->isIntegerType() && !ValType->isPointerType()) {
4504 // For __atomic_*_n operations, the value type must be a scalar integral or
4505 // pointer type which is 1, 2, 4, 8 or 16 bytes in length.
4506 Diag(DRE->getBeginLoc(), diag::err_atomic_op_needs_atomic_int_or_ptr)
4507 << IsC11 << Ptr->getType() << Ptr->getSourceRange();
4508 return ExprError();
4509 }
4510
4511 if (!IsC11 && !AtomTy.isTriviallyCopyableType(Context) &&
4512 !AtomTy->isScalarType()) {
4513 // For GNU atomics, require a trivially-copyable type. This is not part of
4514 // the GNU atomics specification, but we enforce it for sanity.
4515 Diag(DRE->getBeginLoc(), diag::err_atomic_op_needs_trivial_copy)
4516 << Ptr->getType() << Ptr->getSourceRange();
4517 return ExprError();
4518 }
4519
4520 switch (ValType.getObjCLifetime()) {
4521 case Qualifiers::OCL_None:
4522 case Qualifiers::OCL_ExplicitNone:
4523 // okay
4524 break;
4525
4526 case Qualifiers::OCL_Weak:
4527 case Qualifiers::OCL_Strong:
4528 case Qualifiers::OCL_Autoreleasing:
4529 // FIXME: Can this happen? By this point, ValType should be known
4530 // to be trivially copyable.
4531 Diag(DRE->getBeginLoc(), diag::err_arc_atomic_ownership)
4532 << ValType << Ptr->getSourceRange();
4533 return ExprError();
4534 }
4535
4536 // All atomic operations have an overload which takes a pointer to a volatile
4537 // 'A'. We shouldn't let the volatile-ness of the pointee-type inject itself
4538 // into the result or the other operands. Similarly atomic_load takes a
4539 // pointer to a const 'A'.
4540 ValType.removeLocalVolatile();
4541 ValType.removeLocalConst();
4542 QualType ResultType = ValType;
4543 if (Form == Copy || Form == LoadCopy || Form == GNUXchg ||
4544 Form == Init)
4545 ResultType = Context.VoidTy;
4546 else if (Form == C11CmpXchg || Form == GNUCmpXchg)
4547 ResultType = Context.BoolTy;
4548
4549 // The type of a parameter passed 'by value'. In the GNU atomics, such
4550 // arguments are actually passed as pointers.
4551 QualType ByValType = ValType; // 'CP'
4552 bool IsPassedByAddress = false;
4553 if (!IsC11 && !IsN) {
4554 ByValType = Ptr->getType();
4555 IsPassedByAddress = true;
4556 }
4557
4558 // The first argument's non-CV pointer type is used to deduce the type of
4559 // subsequent arguments, except for:
4560 // - weak flag (always converted to bool)
4561 // - memory order (always converted to int)
4562 // - scope (always converted to int)
4563 for (unsigned i = 0; i != TheCall->getNumArgs(); ++i) {
4564 QualType Ty;
4565 if (i < NumVals[Form] + 1) {
4566 switch (i) {
4567 case 0:
4568 // The first argument is always a pointer. It has a fixed type.
4569 // It is always dereferenced, a nullptr is undefined.
4570 CheckNonNullArgument(*this, TheCall->getArg(i), DRE->getBeginLoc());
4571 // Nothing else to do: we already know all we want about this pointer.
4572 continue;
4573 case 1:
4574 // The second argument is the non-atomic operand. For arithmetic, this
4575 // is always passed by value, and for a compare_exchange it is always
4576 // passed by address. For the rest, GNU uses by-address and C11 uses
4577 // by-value.
4578 assert(Form != Load)((Form != Load) ? static_cast<void> (0) : __assert_fail
("Form != Load", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 4578, __PRETTY_FUNCTION__))
;
4579 if (Form == Init || (Form == Arithmetic && ValType->isIntegerType()))
4580 Ty = ValType;
4581 else if (Form == Copy || Form == Xchg) {
4582 if (IsPassedByAddress)
4583 // The value pointer is always dereferenced, a nullptr is undefined.
4584 CheckNonNullArgument(*this, TheCall->getArg(i), DRE->getBeginLoc());
4585 Ty = ByValType;
4586 } else if (Form == Arithmetic)
4587 Ty = Context.getPointerDiffType();
4588 else {
4589 Expr *ValArg = TheCall->getArg(i);
4590 // The value pointer is always dereferenced, a nullptr is undefined.
4591 CheckNonNullArgument(*this, ValArg, DRE->getBeginLoc());
4592 LangAS AS = LangAS::Default;
4593 // Keep address space of non-atomic pointer type.
4594 if (const PointerType *PtrTy =
4595 ValArg->getType()->getAs<PointerType>()) {
4596 AS = PtrTy->getPointeeType().getAddressSpace();
4597 }
4598 Ty = Context.getPointerType(
4599 Context.getAddrSpaceQualType(ValType.getUnqualifiedType(), AS));
4600 }
4601 break;
4602 case 2:
4603 // The third argument to compare_exchange / GNU exchange is the desired
4604 // value, either by-value (for the C11 and *_n variant) or as a pointer.
4605 if (IsPassedByAddress)
4606 CheckNonNullArgument(*this, TheCall->getArg(i), DRE->getBeginLoc());
4607 Ty = ByValType;
4608 break;
4609 case 3:
4610 // The fourth argument to GNU compare_exchange is a 'weak' flag.
4611 Ty = Context.BoolTy;
4612 break;
4613 }
4614 } else {
4615 // The order(s) and scope are always converted to int.
4616 Ty = Context.IntTy;
4617 }
4618
4619 InitializedEntity Entity =
4620 InitializedEntity::InitializeParameter(Context, Ty, false);
4621 ExprResult Arg = TheCall->getArg(i);
4622 Arg = PerformCopyInitialization(Entity, SourceLocation(), Arg);
4623 if (Arg.isInvalid())
4624 return true;
4625 TheCall->setArg(i, Arg.get());
4626 }
4627
4628 // Permute the arguments into a 'consistent' order.
4629 SmallVector<Expr*, 5> SubExprs;
4630 SubExprs.push_back(Ptr);
4631 switch (Form) {
4632 case Init:
4633 // Note, AtomicExpr::getVal1() has a special case for this atomic.
4634 SubExprs.push_back(TheCall->getArg(1)); // Val1
4635 break;
4636 case Load:
4637 SubExprs.push_back(TheCall->getArg(1)); // Order
4638 break;
4639 case LoadCopy:
4640 case Copy:
4641 case Arithmetic:
4642 case Xchg:
4643 SubExprs.push_back(TheCall->getArg(2)); // Order
4644 SubExprs.push_back(TheCall->getArg(1)); // Val1
4645 break;
4646 case GNUXchg:
4647 // Note, AtomicExpr::getVal2() has a special case for this atomic.
4648 SubExprs.push_back(TheCall->getArg(3)); // Order
4649 SubExprs.push_back(TheCall->getArg(1)); // Val1
4650 SubExprs.push_back(TheCall->getArg(2)); // Val2
4651 break;
4652 case C11CmpXchg:
4653 SubExprs.push_back(TheCall->getArg(3)); // Order
4654 SubExprs.push_back(TheCall->getArg(1)); // Val1
4655 SubExprs.push_back(TheCall->getArg(4)); // OrderFail
4656 SubExprs.push_back(TheCall->getArg(2)); // Val2
4657 break;
4658 case GNUCmpXchg:
4659 SubExprs.push_back(TheCall->getArg(4)); // Order
4660 SubExprs.push_back(TheCall->getArg(1)); // Val1
4661 SubExprs.push_back(TheCall->getArg(5)); // OrderFail
4662 SubExprs.push_back(TheCall->getArg(2)); // Val2
4663 SubExprs.push_back(TheCall->getArg(3)); // Weak
4664 break;
4665 }
4666
4667 if (SubExprs.size() >= 2 && Form != Init) {
4668 llvm::APSInt Result(32);
4669 if (SubExprs[1]->isIntegerConstantExpr(Result, Context) &&
4670 !isValidOrderingForOp(Result.getSExtValue(), Op))
4671 Diag(SubExprs[1]->getBeginLoc(),
4672 diag::warn_atomic_op_has_invalid_memory_order)
4673 << SubExprs[1]->getSourceRange();
4674 }
4675
4676 if (auto ScopeModel = AtomicExpr::getScopeModel(Op)) {
4677 auto *Scope = TheCall->getArg(TheCall->getNumArgs() - 1);
4678 llvm::APSInt Result(32);
4679 if (Scope->isIntegerConstantExpr(Result, Context) &&
4680 !ScopeModel->isValid(Result.getZExtValue())) {
4681 Diag(Scope->getBeginLoc(), diag::err_atomic_op_has_invalid_synch_scope)
4682 << Scope->getSourceRange();
4683 }
4684 SubExprs.push_back(Scope);
4685 }
4686
4687 AtomicExpr *AE =
4688 new (Context) AtomicExpr(TheCall->getCallee()->getBeginLoc(), SubExprs,
4689 ResultType, Op, TheCall->getRParenLoc());
4690
4691 if ((Op == AtomicExpr::AO__c11_atomic_load ||
4692 Op == AtomicExpr::AO__c11_atomic_store ||
4693 Op == AtomicExpr::AO__opencl_atomic_load ||
4694 Op == AtomicExpr::AO__opencl_atomic_store ) &&
4695 Context.AtomicUsesUnsupportedLibcall(AE))
4696 Diag(AE->getBeginLoc(), diag::err_atomic_load_store_uses_lib)
4697 << ((Op == AtomicExpr::AO__c11_atomic_load ||
4698 Op == AtomicExpr::AO__opencl_atomic_load)
4699 ? 0
4700 : 1);
4701
4702 return AE;
4703}
4704
4705/// checkBuiltinArgument - Given a call to a builtin function, perform
4706/// normal type-checking on the given argument, updating the call in
4707/// place. This is useful when a builtin function requires custom
4708/// type-checking for some of its arguments but not necessarily all of
4709/// them.
4710///
4711/// Returns true on error.
4712static bool checkBuiltinArgument(Sema &S, CallExpr *E, unsigned ArgIndex) {
4713 FunctionDecl *Fn = E->getDirectCallee();
4714 assert(Fn && "builtin call without direct callee!")((Fn && "builtin call without direct callee!") ? static_cast
<void> (0) : __assert_fail ("Fn && \"builtin call without direct callee!\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 4714, __PRETTY_FUNCTION__))
;
4715
4716 ParmVarDecl *Param = Fn->getParamDecl(ArgIndex);
4717 InitializedEntity Entity =
4718 InitializedEntity::InitializeParameter(S.Context, Param);
4719
4720 ExprResult Arg = E->getArg(0);
4721 Arg = S.PerformCopyInitialization(Entity, SourceLocation(), Arg);
4722 if (Arg.isInvalid())
4723 return true;
4724
4725 E->setArg(ArgIndex, Arg.get());
4726 return false;
4727}
4728
4729/// We have a call to a function like __sync_fetch_and_add, which is an
4730/// overloaded function based on the pointer type of its first argument.
4731/// The main ActOnCallExpr routines have already promoted the types of
4732/// arguments because all of these calls are prototyped as void(...).
4733///
4734/// This function goes through and does final semantic checking for these
4735/// builtins, as well as generating any warnings.
4736ExprResult
4737Sema::SemaBuiltinAtomicOverloaded(ExprResult TheCallResult) {
4738 CallExpr *TheCall = static_cast<CallExpr *>(TheCallResult.get());
4739 Expr *Callee = TheCall->getCallee();
4740 DeclRefExpr *DRE = cast<DeclRefExpr>(Callee->IgnoreParenCasts());
4741 FunctionDecl *FDecl = cast<FunctionDecl>(DRE->getDecl());
4742
4743 // Ensure that we have at least one argument to do type inference from.
4744 if (TheCall->getNumArgs() < 1) {
4745 Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args_at_least)
4746 << 0 << 1 << TheCall->getNumArgs() << Callee->getSourceRange();
4747 return ExprError();
4748 }
4749
4750 // Inspect the first argument of the atomic builtin. This should always be
4751 // a pointer type, whose element is an integral scalar or pointer type.
4752 // Because it is a pointer type, we don't have to worry about any implicit
4753 // casts here.
4754 // FIXME: We don't allow floating point scalars as input.
4755 Expr *FirstArg = TheCall->getArg(0);
4756 ExprResult FirstArgResult = DefaultFunctionArrayLvalueConversion(FirstArg);
4757 if (FirstArgResult.isInvalid())
4758 return ExprError();
4759 FirstArg = FirstArgResult.get();
4760 TheCall->setArg(0, FirstArg);
4761
4762 const PointerType *pointerType = FirstArg->getType()->getAs<PointerType>();
4763 if (!pointerType) {
4764 Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_must_be_pointer)
4765 << FirstArg->getType() << FirstArg->getSourceRange();
4766 return ExprError();
4767 }
4768
4769 QualType ValType = pointerType->getPointeeType();
4770 if (!ValType->isIntegerType() && !ValType->isAnyPointerType() &&
4771 !ValType->isBlockPointerType()) {
4772 Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_must_be_pointer_intptr)
4773 << FirstArg->getType() << FirstArg->getSourceRange();
4774 return ExprError();
4775 }
4776
4777 if (ValType.isConstQualified()) {
4778 Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_cannot_be_const)
4779 << FirstArg->getType() << FirstArg->getSourceRange();
4780 return ExprError();
4781 }
4782
4783 switch (ValType.getObjCLifetime()) {
4784 case Qualifiers::OCL_None:
4785 case Qualifiers::OCL_ExplicitNone:
4786 // okay
4787 break;
4788
4789 case Qualifiers::OCL_Weak:
4790 case Qualifiers::OCL_Strong:
4791 case Qualifiers::OCL_Autoreleasing:
4792 Diag(DRE->getBeginLoc(), diag::err_arc_atomic_ownership)
4793 << ValType << FirstArg->getSourceRange();
4794 return ExprError();
4795 }
4796
4797 // Strip any qualifiers off ValType.
4798 ValType = ValType.getUnqualifiedType();
4799
4800 // The majority of builtins return a value, but a few have special return
4801 // types, so allow them to override appropriately below.
4802 QualType ResultType = ValType;
4803
4804 // We need to figure out which concrete builtin this maps onto. For example,
4805 // __sync_fetch_and_add with a 2 byte object turns into
4806 // __sync_fetch_and_add_2.
4807#define BUILTIN_ROW(x) \
4808 { Builtin::BI##x##_1, Builtin::BI##x##_2, Builtin::BI##x##_4, \
4809 Builtin::BI##x##_8, Builtin::BI##x##_16 }
4810
4811 static const unsigned BuiltinIndices[][5] = {
4812 BUILTIN_ROW(__sync_fetch_and_add),
4813 BUILTIN_ROW(__sync_fetch_and_sub),
4814 BUILTIN_ROW(__sync_fetch_and_or),
4815 BUILTIN_ROW(__sync_fetch_and_and),
4816 BUILTIN_ROW(__sync_fetch_and_xor),
4817 BUILTIN_ROW(__sync_fetch_and_nand),
4818
4819 BUILTIN_ROW(__sync_add_and_fetch),
4820 BUILTIN_ROW(__sync_sub_and_fetch),
4821 BUILTIN_ROW(__sync_and_and_fetch),
4822 BUILTIN_ROW(__sync_or_and_fetch),
4823 BUILTIN_ROW(__sync_xor_and_fetch),
4824 BUILTIN_ROW(__sync_nand_and_fetch),
4825
4826 BUILTIN_ROW(__sync_val_compare_and_swap),
4827 BUILTIN_ROW(__sync_bool_compare_and_swap),
4828 BUILTIN_ROW(__sync_lock_test_and_set),
4829 BUILTIN_ROW(__sync_lock_release),
4830 BUILTIN_ROW(__sync_swap)
4831 };
4832#undef BUILTIN_ROW
4833
4834 // Determine the index of the size.
4835 unsigned SizeIndex;
4836 switch (Context.getTypeSizeInChars(ValType).getQuantity()) {
4837 case 1: SizeIndex = 0; break;
4838 case 2: SizeIndex = 1; break;
4839 case 4: SizeIndex = 2; break;
4840 case 8: SizeIndex = 3; break;
4841 case 16: SizeIndex = 4; break;
4842 default:
4843 Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_pointer_size)
4844 << FirstArg->getType() << FirstArg->getSourceRange();
4845 return ExprError();
4846 }
4847
4848 // Each of these builtins has one pointer argument, followed by some number of
4849 // values (0, 1 or 2) followed by a potentially empty varags list of stuff
4850 // that we ignore. Find out which row of BuiltinIndices to read from as well
4851 // as the number of fixed args.
4852 unsigned BuiltinID = FDecl->getBuiltinID();
4853 unsigned BuiltinIndex, NumFixed = 1;
4854 bool WarnAboutSemanticsChange = false;
4855 switch (BuiltinID) {
4856 default: llvm_unreachable("Unknown overloaded atomic builtin!")::llvm::llvm_unreachable_internal("Unknown overloaded atomic builtin!"
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 4856)
;
4857 case Builtin::BI__sync_fetch_and_add:
4858 case Builtin::BI__sync_fetch_and_add_1:
4859 case Builtin::BI__sync_fetch_and_add_2:
4860 case Builtin::BI__sync_fetch_and_add_4:
4861 case Builtin::BI__sync_fetch_and_add_8:
4862 case Builtin::BI__sync_fetch_and_add_16:
4863 BuiltinIndex = 0;
4864 break;
4865
4866 case Builtin::BI__sync_fetch_and_sub:
4867 case Builtin::BI__sync_fetch_and_sub_1:
4868 case Builtin::BI__sync_fetch_and_sub_2:
4869 case Builtin::BI__sync_fetch_and_sub_4:
4870 case Builtin::BI__sync_fetch_and_sub_8:
4871 case Builtin::BI__sync_fetch_and_sub_16:
4872 BuiltinIndex = 1;
4873 break;
4874
4875 case Builtin::BI__sync_fetch_and_or:
4876 case Builtin::BI__sync_fetch_and_or_1:
4877 case Builtin::BI__sync_fetch_and_or_2:
4878 case Builtin::BI__sync_fetch_and_or_4:
4879 case Builtin::BI__sync_fetch_and_or_8:
4880 case Builtin::BI__sync_fetch_and_or_16:
4881 BuiltinIndex = 2;
4882 break;
4883
4884 case Builtin::BI__sync_fetch_and_and:
4885 case Builtin::BI__sync_fetch_and_and_1:
4886 case Builtin::BI__sync_fetch_and_and_2:
4887 case Builtin::BI__sync_fetch_and_and_4:
4888 case Builtin::BI__sync_fetch_and_and_8:
4889 case Builtin::BI__sync_fetch_and_and_16:
4890 BuiltinIndex = 3;
4891 break;
4892
4893 case Builtin::BI__sync_fetch_and_xor:
4894 case Builtin::BI__sync_fetch_and_xor_1:
4895 case Builtin::BI__sync_fetch_and_xor_2:
4896 case Builtin::BI__sync_fetch_and_xor_4:
4897 case Builtin::BI__sync_fetch_and_xor_8:
4898 case Builtin::BI__sync_fetch_and_xor_16:
4899 BuiltinIndex = 4;
4900 break;
4901
4902 case Builtin::BI__sync_fetch_and_nand:
4903 case Builtin::BI__sync_fetch_and_nand_1:
4904 case Builtin::BI__sync_fetch_and_nand_2:
4905 case Builtin::BI__sync_fetch_and_nand_4:
4906 case Builtin::BI__sync_fetch_and_nand_8:
4907 case Builtin::BI__sync_fetch_and_nand_16:
4908 BuiltinIndex = 5;
4909 WarnAboutSemanticsChange = true;
4910 break;
4911
4912 case Builtin::BI__sync_add_and_fetch:
4913 case Builtin::BI__sync_add_and_fetch_1:
4914 case Builtin::BI__sync_add_and_fetch_2:
4915 case Builtin::BI__sync_add_and_fetch_4:
4916 case Builtin::BI__sync_add_and_fetch_8:
4917 case Builtin::BI__sync_add_and_fetch_16:
4918 BuiltinIndex = 6;
4919 break;
4920
4921 case Builtin::BI__sync_sub_and_fetch:
4922 case Builtin::BI__sync_sub_and_fetch_1:
4923 case Builtin::BI__sync_sub_and_fetch_2:
4924 case Builtin::BI__sync_sub_and_fetch_4:
4925 case Builtin::BI__sync_sub_and_fetch_8:
4926 case Builtin::BI__sync_sub_and_fetch_16:
4927 BuiltinIndex = 7;
4928 break;
4929
4930 case Builtin::BI__sync_and_and_fetch:
4931 case Builtin::BI__sync_and_and_fetch_1:
4932 case Builtin::BI__sync_and_and_fetch_2:
4933 case Builtin::BI__sync_and_and_fetch_4:
4934 case Builtin::BI__sync_and_and_fetch_8:
4935 case Builtin::BI__sync_and_and_fetch_16:
4936 BuiltinIndex = 8;
4937 break;
4938
4939 case Builtin::BI__sync_or_and_fetch:
4940 case Builtin::BI__sync_or_and_fetch_1:
4941 case Builtin::BI__sync_or_and_fetch_2:
4942 case Builtin::BI__sync_or_and_fetch_4:
4943 case Builtin::BI__sync_or_and_fetch_8:
4944 case Builtin::BI__sync_or_and_fetch_16:
4945 BuiltinIndex = 9;
4946 break;
4947
4948 case Builtin::BI__sync_xor_and_fetch:
4949 case Builtin::BI__sync_xor_and_fetch_1:
4950 case Builtin::BI__sync_xor_and_fetch_2:
4951 case Builtin::BI__sync_xor_and_fetch_4:
4952 case Builtin::BI__sync_xor_and_fetch_8:
4953 case Builtin::BI__sync_xor_and_fetch_16:
4954 BuiltinIndex = 10;
4955 break;
4956
4957 case Builtin::BI__sync_nand_and_fetch:
4958 case Builtin::BI__sync_nand_and_fetch_1:
4959 case Builtin::BI__sync_nand_and_fetch_2:
4960 case Builtin::BI__sync_nand_and_fetch_4:
4961 case Builtin::BI__sync_nand_and_fetch_8:
4962 case Builtin::BI__sync_nand_and_fetch_16:
4963 BuiltinIndex = 11;
4964 WarnAboutSemanticsChange = true;
4965 break;
4966
4967 case Builtin::BI__sync_val_compare_and_swap:
4968 case Builtin::BI__sync_val_compare_and_swap_1:
4969 case Builtin::BI__sync_val_compare_and_swap_2:
4970 case Builtin::BI__sync_val_compare_and_swap_4:
4971 case Builtin::BI__sync_val_compare_and_swap_8:
4972 case Builtin::BI__sync_val_compare_and_swap_16:
4973 BuiltinIndex = 12;
4974 NumFixed = 2;
4975 break;
4976
4977 case Builtin::BI__sync_bool_compare_and_swap:
4978 case Builtin::BI__sync_bool_compare_and_swap_1:
4979 case Builtin::BI__sync_bool_compare_and_swap_2:
4980 case Builtin::BI__sync_bool_compare_and_swap_4:
4981 case Builtin::BI__sync_bool_compare_and_swap_8:
4982 case Builtin::BI__sync_bool_compare_and_swap_16:
4983 BuiltinIndex = 13;
4984 NumFixed = 2;
4985 ResultType = Context.BoolTy;
4986 break;
4987
4988 case Builtin::BI__sync_lock_test_and_set:
4989 case Builtin::BI__sync_lock_test_and_set_1:
4990 case Builtin::BI__sync_lock_test_and_set_2:
4991 case Builtin::BI__sync_lock_test_and_set_4:
4992 case Builtin::BI__sync_lock_test_and_set_8:
4993 case Builtin::BI__sync_lock_test_and_set_16:
4994 BuiltinIndex = 14;
4995 break;
4996
4997 case Builtin::BI__sync_lock_release:
4998 case Builtin::BI__sync_lock_release_1:
4999 case Builtin::BI__sync_lock_release_2:
5000 case Builtin::BI__sync_lock_release_4:
5001 case Builtin::BI__sync_lock_release_8:
5002 case Builtin::BI__sync_lock_release_16:
5003 BuiltinIndex = 15;
5004 NumFixed = 0;
5005 ResultType = Context.VoidTy;
5006 break;
5007
5008 case Builtin::BI__sync_swap:
5009 case Builtin::BI__sync_swap_1:
5010 case Builtin::BI__sync_swap_2:
5011 case Builtin::BI__sync_swap_4:
5012 case Builtin::BI__sync_swap_8:
5013 case Builtin::BI__sync_swap_16:
5014 BuiltinIndex = 16;
5015 break;
5016 }
5017
5018 // Now that we know how many fixed arguments we expect, first check that we
5019 // have at least that many.
5020 if (TheCall->getNumArgs() < 1+NumFixed) {
5021 Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args_at_least)
5022 << 0 << 1 + NumFixed << TheCall->getNumArgs()
5023 << Callee->getSourceRange();
5024 return ExprError();
5025 }
5026
5027 Diag(TheCall->getEndLoc(), diag::warn_atomic_implicit_seq_cst)
5028 << Callee->getSourceRange();
5029
5030 if (WarnAboutSemanticsChange) {
5031 Diag(TheCall->getEndLoc(), diag::warn_sync_fetch_and_nand_semantics_change)
5032 << Callee->getSourceRange();
5033 }
5034
5035 // Get the decl for the concrete builtin from this, we can tell what the
5036 // concrete integer type we should convert to is.
5037 unsigned NewBuiltinID = BuiltinIndices[BuiltinIndex][SizeIndex];
5038 const char *NewBuiltinName = Context.BuiltinInfo.getName(NewBuiltinID);
5039 FunctionDecl *NewBuiltinDecl;
5040 if (NewBuiltinID == BuiltinID)
5041 NewBuiltinDecl = FDecl;
5042 else {
5043 // Perform builtin lookup to avoid redeclaring it.
5044 DeclarationName DN(&Context.Idents.get(NewBuiltinName));
5045 LookupResult Res(*this, DN, DRE->getBeginLoc(), LookupOrdinaryName);
5046 LookupName(Res, TUScope, /*AllowBuiltinCreation=*/true);
5047 assert(Res.getFoundDecl())((Res.getFoundDecl()) ? static_cast<void> (0) : __assert_fail
("Res.getFoundDecl()", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 5047, __PRETTY_FUNCTION__))
;
5048 NewBuiltinDecl = dyn_cast<FunctionDecl>(Res.getFoundDecl());
5049 if (!NewBuiltinDecl)
5050 return ExprError();
5051 }
5052
5053 // The first argument --- the pointer --- has a fixed type; we
5054 // deduce the types of the rest of the arguments accordingly. Walk
5055 // the remaining arguments, converting them to the deduced value type.
5056 for (unsigned i = 0; i != NumFixed; ++i) {
5057 ExprResult Arg = TheCall->getArg(i+1);
5058
5059 // GCC does an implicit conversion to the pointer or integer ValType. This
5060 // can fail in some cases (1i -> int**), check for this error case now.
5061 // Initialize the argument.
5062 InitializedEntity Entity = InitializedEntity::InitializeParameter(Context,
5063 ValType, /*consume*/ false);
5064 Arg = PerformCopyInitialization(Entity, SourceLocation(), Arg);
5065 if (Arg.isInvalid())
5066 return ExprError();
5067
5068 // Okay, we have something that *can* be converted to the right type. Check
5069 // to see if there is a potentially weird extension going on here. This can
5070 // happen when you do an atomic operation on something like an char* and
5071 // pass in 42. The 42 gets converted to char. This is even more strange
5072 // for things like 45.123 -> char, etc.
5073 // FIXME: Do this check.
5074 TheCall->setArg(i+1, Arg.get());
5075 }
5076
5077 ASTContext& Context = this->getASTContext();
5078
5079 // Create a new DeclRefExpr to refer to the new decl.
5080 DeclRefExpr* NewDRE = DeclRefExpr::Create(
5081 Context,
5082 DRE->getQualifierLoc(),
5083 SourceLocation(),
5084 NewBuiltinDecl,
5085 /*enclosing*/ false,
5086 DRE->getLocation(),
5087 Context.BuiltinFnTy,
5088 DRE->getValueKind());
5089
5090 // Set the callee in the CallExpr.
5091 // FIXME: This loses syntactic information.
5092 QualType CalleePtrTy = Context.getPointerType(NewBuiltinDecl->getType());
5093 ExprResult PromotedCall = ImpCastExprToType(NewDRE, CalleePtrTy,
5094 CK_BuiltinFnToFnPtr);
5095 TheCall->setCallee(PromotedCall.get());
5096
5097 // Change the result type of the call to match the original value type. This
5098 // is arbitrary, but the codegen for these builtins ins design to handle it
5099 // gracefully.
5100 TheCall->setType(ResultType);
5101
5102 return TheCallResult;
5103}
5104
5105/// SemaBuiltinNontemporalOverloaded - We have a call to
5106/// __builtin_nontemporal_store or __builtin_nontemporal_load, which is an
5107/// overloaded function based on the pointer type of its last argument.
5108///
5109/// This function goes through and does final semantic checking for these
5110/// builtins.
5111ExprResult Sema::SemaBuiltinNontemporalOverloaded(ExprResult TheCallResult) {
5112 CallExpr *TheCall = (CallExpr *)TheCallResult.get();
5113 DeclRefExpr *DRE =
5114 cast<DeclRefExpr>(TheCall->getCallee()->IgnoreParenCasts());
5115 FunctionDecl *FDecl = cast<FunctionDecl>(DRE->getDecl());
5116 unsigned BuiltinID = FDecl->getBuiltinID();
5117 assert((BuiltinID == Builtin::BI__builtin_nontemporal_store ||(((BuiltinID == Builtin::BI__builtin_nontemporal_store || BuiltinID
== Builtin::BI__builtin_nontemporal_load) && "Unexpected nontemporal load/store builtin!"
) ? static_cast<void> (0) : __assert_fail ("(BuiltinID == Builtin::BI__builtin_nontemporal_store || BuiltinID == Builtin::BI__builtin_nontemporal_load) && \"Unexpected nontemporal load/store builtin!\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 5119, __PRETTY_FUNCTION__))
5118 BuiltinID == Builtin::BI__builtin_nontemporal_load) &&(((BuiltinID == Builtin::BI__builtin_nontemporal_store || BuiltinID
== Builtin::BI__builtin_nontemporal_load) && "Unexpected nontemporal load/store builtin!"
) ? static_cast<void> (0) : __assert_fail ("(BuiltinID == Builtin::BI__builtin_nontemporal_store || BuiltinID == Builtin::BI__builtin_nontemporal_load) && \"Unexpected nontemporal load/store builtin!\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 5119, __PRETTY_FUNCTION__))
5119 "Unexpected nontemporal load/store builtin!")(((BuiltinID == Builtin::BI__builtin_nontemporal_store || BuiltinID
== Builtin::BI__builtin_nontemporal_load) && "Unexpected nontemporal load/store builtin!"
) ? static_cast<void> (0) : __assert_fail ("(BuiltinID == Builtin::BI__builtin_nontemporal_store || BuiltinID == Builtin::BI__builtin_nontemporal_load) && \"Unexpected nontemporal load/store builtin!\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 5119, __PRETTY_FUNCTION__))
;
5120 bool isStore = BuiltinID == Builtin::BI__builtin_nontemporal_store;
5121 unsigned numArgs = isStore ? 2 : 1;
5122
5123 // Ensure that we have the proper number of arguments.
5124 if (checkArgCount(*this, TheCall, numArgs))
5125 return ExprError();
5126
5127 // Inspect the last argument of the nontemporal builtin. This should always
5128 // be a pointer type, from which we imply the type of the memory access.
5129 // Because it is a pointer type, we don't have to worry about any implicit
5130 // casts here.
5131 Expr *PointerArg = TheCall->getArg(numArgs - 1);
5132 ExprResult PointerArgResult =
5133 DefaultFunctionArrayLvalueConversion(PointerArg);
5134
5135 if (PointerArgResult.isInvalid())
5136 return ExprError();
5137 PointerArg = PointerArgResult.get();
5138 TheCall->setArg(numArgs - 1, PointerArg);
5139
5140 const PointerType *pointerType = PointerArg->getType()->getAs<PointerType>();
5141 if (!pointerType) {
5142 Diag(DRE->getBeginLoc(), diag::err_nontemporal_builtin_must_be_pointer)
5143 << PointerArg->getType() << PointerArg->getSourceRange();
5144 return ExprError();
5145 }
5146
5147 QualType ValType = pointerType->getPointeeType();
5148
5149 // Strip any qualifiers off ValType.
5150 ValType = ValType.getUnqualifiedType();
5151 if (!ValType->isIntegerType() && !ValType->isAnyPointerType() &&
5152 !ValType->isBlockPointerType() && !ValType->isFloatingType() &&
5153 !ValType->isVectorType()) {
5154 Diag(DRE->getBeginLoc(),
5155 diag::err_nontemporal_builtin_must_be_pointer_intfltptr_or_vector)
5156 << PointerArg->getType() << PointerArg->getSourceRange();
5157 return ExprError();
5158 }
5159
5160 if (!isStore) {
5161 TheCall->setType(ValType);
5162 return TheCallResult;
5163 }
5164
5165 ExprResult ValArg = TheCall->getArg(0);
5166 InitializedEntity Entity = InitializedEntity::InitializeParameter(
5167 Context, ValType, /*consume*/ false);
5168 ValArg = PerformCopyInitialization(Entity, SourceLocation(), ValArg);
5169 if (ValArg.isInvalid())
5170 return ExprError();
5171
5172 TheCall->setArg(0, ValArg.get());
5173 TheCall->setType(Context.VoidTy);
5174 return TheCallResult;
5175}
5176
5177/// CheckObjCString - Checks that the argument to the builtin
5178/// CFString constructor is correct
5179/// Note: It might also make sense to do the UTF-16 conversion here (would
5180/// simplify the backend).
5181bool Sema::CheckObjCString(Expr *Arg) {
5182 Arg = Arg->IgnoreParenCasts();
5183 StringLiteral *Literal = dyn_cast<StringLiteral>(Arg);
5184
5185 if (!Literal || !Literal->isAscii()) {
5186 Diag(Arg->getBeginLoc(), diag::err_cfstring_literal_not_string_constant)
5187 << Arg->getSourceRange();
5188 return true;
5189 }
5190
5191 if (Literal->containsNonAsciiOrNull()) {
5192 StringRef String = Literal->getString();
5193 unsigned NumBytes = String.size();
5194 SmallVector<llvm::UTF16, 128> ToBuf(NumBytes);
5195 const llvm::UTF8 *FromPtr = (const llvm::UTF8 *)String.data();
5196 llvm::UTF16 *ToPtr = &ToBuf[0];
5197
5198 llvm::ConversionResult Result =
5199 llvm::ConvertUTF8toUTF16(&FromPtr, FromPtr + NumBytes, &ToPtr,
5200 ToPtr + NumBytes, llvm::strictConversion);
5201 // Check for conversion failure.
5202 if (Result != llvm::conversionOK)
5203 Diag(Arg->getBeginLoc(), diag::warn_cfstring_truncated)
5204 << Arg->getSourceRange();
5205 }
5206 return false;
5207}
5208
5209/// CheckObjCString - Checks that the format string argument to the os_log()
5210/// and os_trace() functions is correct, and converts it to const char *.
5211ExprResult Sema::CheckOSLogFormatStringArg(Expr *Arg) {
5212 Arg = Arg->IgnoreParenCasts();
5213 auto *Literal = dyn_cast<StringLiteral>(Arg);
5214 if (!Literal) {
5215 if (auto *ObjcLiteral = dyn_cast<ObjCStringLiteral>(Arg)) {
5216 Literal = ObjcLiteral->getString();
5217 }
5218 }
5219
5220 if (!Literal || (!Literal->isAscii() && !Literal->isUTF8())) {
5221 return ExprError(
5222 Diag(Arg->getBeginLoc(), diag::err_os_log_format_not_string_constant)
5223 << Arg->getSourceRange());
5224 }
5225
5226 ExprResult Result(Literal);
5227 QualType ResultTy = Context.getPointerType(Context.CharTy.withConst());
5228 InitializedEntity Entity =
5229 InitializedEntity::InitializeParameter(Context, ResultTy, false);
5230 Result = PerformCopyInitialization(Entity, SourceLocation(), Result);
5231 return Result;
5232}
5233
5234/// Check that the user is calling the appropriate va_start builtin for the
5235/// target and calling convention.
5236static bool checkVAStartABI(Sema &S, unsigned BuiltinID, Expr *Fn) {
5237 const llvm::Triple &TT = S.Context.getTargetInfo().getTriple();
5238 bool IsX64 = TT.getArch() == llvm::Triple::x86_64;
5239 bool IsAArch64 = TT.getArch() == llvm::Triple::aarch64;
5240 bool IsWindows = TT.isOSWindows();
5241 bool IsMSVAStart = BuiltinID == Builtin::BI__builtin_ms_va_start;
5242 if (IsX64 || IsAArch64) {
5243 CallingConv CC = CC_C;
5244 if (const FunctionDecl *FD = S.getCurFunctionDecl())
5245 CC = FD->getType()->getAs<FunctionType>()->getCallConv();
5246 if (IsMSVAStart) {
5247 // Don't allow this in System V ABI functions.
5248 if (CC == CC_X86_64SysV || (!IsWindows && CC != CC_Win64))
5249 return S.Diag(Fn->getBeginLoc(),
5250 diag::err_ms_va_start_used_in_sysv_function);
5251 } else {
5252 // On x86-64/AArch64 Unix, don't allow this in Win64 ABI functions.
5253 // On x64 Windows, don't allow this in System V ABI functions.
5254 // (Yes, that means there's no corresponding way to support variadic
5255 // System V ABI functions on Windows.)
5256 if ((IsWindows && CC == CC_X86_64SysV) ||
5257 (!IsWindows && CC == CC_Win64))
5258 return S.Diag(Fn->getBeginLoc(),
5259 diag::err_va_start_used_in_wrong_abi_function)
5260 << !IsWindows;
5261 }
5262 return false;
5263 }
5264
5265 if (IsMSVAStart)
5266 return S.Diag(Fn->getBeginLoc(), diag::err_builtin_x64_aarch64_only);
5267 return false;
5268}
5269
5270static bool checkVAStartIsInVariadicFunction(Sema &S, Expr *Fn,
5271 ParmVarDecl **LastParam = nullptr) {
5272 // Determine whether the current function, block, or obj-c method is variadic
5273 // and get its parameter list.
5274 bool IsVariadic = false;
5275 ArrayRef<ParmVarDecl *> Params;
5276 DeclContext *Caller = S.CurContext;
5277 if (auto *Block = dyn_cast<BlockDecl>(Caller)) {
5278 IsVariadic = Block->isVariadic();
5279 Params = Block->parameters();
5280 } else if (auto *FD = dyn_cast<FunctionDecl>(Caller)) {
5281 IsVariadic = FD->isVariadic();
5282 Params = FD->parameters();
5283 } else if (auto *MD = dyn_cast<ObjCMethodDecl>(Caller)) {
5284 IsVariadic = MD->isVariadic();
5285 // FIXME: This isn't correct for methods (results in bogus warning).
5286 Params = MD->parameters();
5287 } else if (isa<CapturedDecl>(Caller)) {
5288 // We don't support va_start in a CapturedDecl.
5289 S.Diag(Fn->getBeginLoc(), diag::err_va_start_captured_stmt);
5290 return true;
5291 } else {
5292 // This must be some other declcontext that parses exprs.
5293 S.Diag(Fn->getBeginLoc(), diag::err_va_start_outside_function);
5294 return true;
5295 }
5296
5297 if (!IsVariadic) {
5298 S.Diag(Fn->getBeginLoc(), diag::err_va_start_fixed_function);
5299 return true;
5300 }
5301
5302 if (LastParam)
5303 *LastParam = Params.empty() ? nullptr : Params.back();
5304
5305 return false;
5306}
5307
5308/// Check the arguments to '__builtin_va_start' or '__builtin_ms_va_start'
5309/// for validity. Emit an error and return true on failure; return false
5310/// on success.
5311bool Sema::SemaBuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) {
5312 Expr *Fn = TheCall->getCallee();
5313
5314 if (checkVAStartABI(*this, BuiltinID, Fn))
5315 return true;
5316
5317 if (TheCall->getNumArgs() > 2) {
5318 Diag(TheCall->getArg(2)->getBeginLoc(),
5319 diag::err_typecheck_call_too_many_args)
5320 << 0 /*function call*/ << 2 << TheCall->getNumArgs()
5321 << Fn->getSourceRange()
5322 << SourceRange(TheCall->getArg(2)->getBeginLoc(),
5323 (*(TheCall->arg_end() - 1))->getEndLoc());
5324 return true;
5325 }
5326
5327 if (TheCall->getNumArgs() < 2) {
5328 return Diag(TheCall->getEndLoc(),
5329 diag::err_typecheck_call_too_few_args_at_least)
5330 << 0 /*function call*/ << 2 << TheCall->getNumArgs();
5331 }
5332
5333 // Type-check the first argument normally.
5334 if (checkBuiltinArgument(*this, TheCall, 0))
5335 return true;
5336
5337 // Check that the current function is variadic, and get its last parameter.
5338 ParmVarDecl *LastParam;
5339 if (checkVAStartIsInVariadicFunction(*this, Fn, &LastParam))
5340 return true;
5341
5342 // Verify that the second argument to the builtin is the last argument of the
5343 // current function or method.
5344 bool SecondArgIsLastNamedArgument = false;
5345 const Expr *Arg = TheCall->getArg(1)->IgnoreParenCasts();
5346
5347 // These are valid if SecondArgIsLastNamedArgument is false after the next
5348 // block.
5349 QualType Type;
5350 SourceLocation ParamLoc;
5351 bool IsCRegister = false;
5352
5353 if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(Arg)) {
5354 if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(DR->getDecl())) {
5355 SecondArgIsLastNamedArgument = PV == LastParam;
5356
5357 Type = PV->getType();
5358 ParamLoc = PV->getLocation();
5359 IsCRegister =
5360 PV->getStorageClass() == SC_Register && !getLangOpts().CPlusPlus;
5361 }
5362 }
5363
5364 if (!SecondArgIsLastNamedArgument)
5365 Diag(TheCall->getArg(1)->getBeginLoc(),
5366 diag::warn_second_arg_of_va_start_not_last_named_param);
5367 else if (IsCRegister || Type->isReferenceType() ||
5368 Type->isSpecificBuiltinType(BuiltinType::Float) || [=] {
5369 // Promotable integers are UB, but enumerations need a bit of
5370 // extra checking to see what their promotable type actually is.
5371 if (!Type->isPromotableIntegerType())
5372 return false;
5373 if (!Type->isEnumeralType())
5374 return true;
5375 const EnumDecl *ED = Type->getAs<EnumType>()->getDecl();
5376 return !(ED &&
5377 Context.typesAreCompatible(ED->getPromotionType(), Type));
5378 }()) {
5379 unsigned Reason = 0;
5380 if (Type->isReferenceType()) Reason = 1;
5381 else if (IsCRegister) Reason = 2;
5382 Diag(Arg->getBeginLoc(), diag::warn_va_start_type_is_undefined) << Reason;
5383 Diag(ParamLoc, diag::note_parameter_type) << Type;
5384 }
5385
5386 TheCall->setType(Context.VoidTy);
5387 return false;
5388}
5389
5390bool Sema::SemaBuiltinVAStartARMMicrosoft(CallExpr *Call) {
5391 // void __va_start(va_list *ap, const char *named_addr, size_t slot_size,
5392 // const char *named_addr);
5393
5394 Expr *Func = Call->getCallee();
5395
5396 if (Call->getNumArgs() < 3)
5397 return Diag(Call->getEndLoc(),
5398 diag::err_typecheck_call_too_few_args_at_least)
5399 << 0 /*function call*/ << 3 << Call->getNumArgs();
5400
5401 // Type-check the first argument normally.
5402 if (checkBuiltinArgument(*this, Call, 0))
5403 return true;
5404
5405 // Check that the current function is variadic.
5406 if (checkVAStartIsInVariadicFunction(*this, Func))
5407 return true;
5408
5409 // __va_start on Windows does not validate the parameter qualifiers
5410
5411 const Expr *Arg1 = Call->getArg(1)->IgnoreParens();
5412 const Type *Arg1Ty = Arg1->getType().getCanonicalType().getTypePtr();
5413
5414 const Expr *Arg2 = Call->getArg(2)->IgnoreParens();
5415 const Type *Arg2Ty = Arg2->getType().getCanonicalType().getTypePtr();
5416
5417 const QualType &ConstCharPtrTy =
5418 Context.getPointerType(Context.CharTy.withConst());
5419 if (!Arg1Ty->isPointerType() ||
5420 Arg1Ty->getPointeeType().withoutLocalFastQualifiers() != Context.CharTy)
5421 Diag(Arg1->getBeginLoc(), diag::err_typecheck_convert_incompatible)
5422 << Arg1->getType() << ConstCharPtrTy << 1 /* different class */
5423 << 0 /* qualifier difference */
5424 << 3 /* parameter mismatch */
5425 << 2 << Arg1->getType() << ConstCharPtrTy;
5426
5427 const QualType SizeTy = Context.getSizeType();
5428 if (Arg2Ty->getCanonicalTypeInternal().withoutLocalFastQualifiers() != SizeTy)
5429 Diag(Arg2->getBeginLoc(), diag::err_typecheck_convert_incompatible)
5430 << Arg2->getType() << SizeTy << 1 /* different class */
5431 << 0 /* qualifier difference */
5432 << 3 /* parameter mismatch */
5433 << 3 << Arg2->getType() << SizeTy;
5434
5435 return false;
5436}
5437
5438/// SemaBuiltinUnorderedCompare - Handle functions like __builtin_isgreater and
5439/// friends. This is declared to take (...), so we have to check everything.
5440bool Sema::SemaBuiltinUnorderedCompare(CallExpr *TheCall) {
5441 if (TheCall->getNumArgs() < 2)
5442 return Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args)
5443 << 0 << 2 << TheCall->getNumArgs() /*function call*/;
5444 if (TheCall->getNumArgs() > 2)
5445 return Diag(TheCall->getArg(2)->getBeginLoc(),
5446 diag::err_typecheck_call_too_many_args)
5447 << 0 /*function call*/ << 2 << TheCall->getNumArgs()
5448 << SourceRange(TheCall->getArg(2)->getBeginLoc(),
5449 (*(TheCall->arg_end() - 1))->getEndLoc());
5450
5451 ExprResult OrigArg0 = TheCall->getArg(0);
5452 ExprResult OrigArg1 = TheCall->getArg(1);
5453
5454 // Do standard promotions between the two arguments, returning their common
5455 // type.
5456 QualType Res = UsualArithmeticConversions(OrigArg0, OrigArg1, false);
5457 if (OrigArg0.isInvalid() || OrigArg1.isInvalid())
5458 return true;
5459
5460 // Make sure any conversions are pushed back into the call; this is
5461 // type safe since unordered compare builtins are declared as "_Bool
5462 // foo(...)".
5463 TheCall->setArg(0, OrigArg0.get());
5464 TheCall->setArg(1, OrigArg1.get());
5465
5466 if (OrigArg0.get()->isTypeDependent() || OrigArg1.get()->isTypeDependent())
5467 return false;
5468
5469 // If the common type isn't a real floating type, then the arguments were
5470 // invalid for this operation.
5471 if (Res.isNull() || !Res->isRealFloatingType())
5472 return Diag(OrigArg0.get()->getBeginLoc(),
5473 diag::err_typecheck_call_invalid_ordered_compare)
5474 << OrigArg0.get()->getType() << OrigArg1.get()->getType()
5475 << SourceRange(OrigArg0.get()->getBeginLoc(),
5476 OrigArg1.get()->getEndLoc());
5477
5478 return false;
5479}
5480
5481/// SemaBuiltinSemaBuiltinFPClassification - Handle functions like
5482/// __builtin_isnan and friends. This is declared to take (...), so we have
5483/// to check everything. We expect the last argument to be a floating point
5484/// value.
5485bool Sema::SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs) {
5486 if (TheCall->getNumArgs() < NumArgs)
5487 return Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args)
5488 << 0 << NumArgs << TheCall->getNumArgs() /*function call*/;
5489 if (TheCall->getNumArgs() > NumArgs)
5490 return Diag(TheCall->getArg(NumArgs)->getBeginLoc(),
5491 diag::err_typecheck_call_too_many_args)
5492 << 0 /*function call*/ << NumArgs << TheCall->getNumArgs()
5493 << SourceRange(TheCall->getArg(NumArgs)->getBeginLoc(),
5494 (*(TheCall->arg_end() - 1))->getEndLoc());
5495
5496 Expr *OrigArg = TheCall->getArg(NumArgs-1);
5497
5498 if (OrigArg->isTypeDependent())
5499 return false;
5500
5501 // This operation requires a non-_Complex floating-point number.
5502 if (!OrigArg->getType()->isRealFloatingType())
5503 return Diag(OrigArg->getBeginLoc(),
5504 diag::err_typecheck_call_invalid_unary_fp)
5505 << OrigArg->getType() << OrigArg->getSourceRange();
5506
5507 // If this is an implicit conversion from float -> float, double, or
5508 // long double, remove it.
5509 if (ImplicitCastExpr *Cast = dyn_cast<ImplicitCastExpr>(OrigArg)) {
5510 // Only remove standard FloatCasts, leaving other casts inplace
5511 if (Cast->getCastKind() == CK_FloatingCast) {
5512 Expr *CastArg = Cast->getSubExpr();
5513 if (CastArg->getType()->isSpecificBuiltinType(BuiltinType::Float)) {
5514 assert((((Cast->getType()->isSpecificBuiltinType(BuiltinType::
Double) || Cast->getType()->isSpecificBuiltinType(BuiltinType
::Float) || Cast->getType()->isSpecificBuiltinType(BuiltinType
::LongDouble)) && "promotion from float to either float, double, or long double is "
"the only expected cast here") ? static_cast<void> (0)
: __assert_fail ("(Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) || Cast->getType()->isSpecificBuiltinType(BuiltinType::Float) || Cast->getType()->isSpecificBuiltinType(BuiltinType::LongDouble)) && \"promotion from float to either float, double, or long double is \" \"the only expected cast here\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 5519, __PRETTY_FUNCTION__))
5515 (Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) ||(((Cast->getType()->isSpecificBuiltinType(BuiltinType::
Double) || Cast->getType()->isSpecificBuiltinType(BuiltinType
::Float) || Cast->getType()->isSpecificBuiltinType(BuiltinType
::LongDouble)) && "promotion from float to either float, double, or long double is "
"the only expected cast here") ? static_cast<void> (0)
: __assert_fail ("(Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) || Cast->getType()->isSpecificBuiltinType(BuiltinType::Float) || Cast->getType()->isSpecificBuiltinType(BuiltinType::LongDouble)) && \"promotion from float to either float, double, or long double is \" \"the only expected cast here\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 5519, __PRETTY_FUNCTION__))
5516 Cast->getType()->isSpecificBuiltinType(BuiltinType::Float) ||(((Cast->getType()->isSpecificBuiltinType(BuiltinType::
Double) || Cast->getType()->isSpecificBuiltinType(BuiltinType
::Float) || Cast->getType()->isSpecificBuiltinType(BuiltinType
::LongDouble)) && "promotion from float to either float, double, or long double is "
"the only expected cast here") ? static_cast<void> (0)
: __assert_fail ("(Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) || Cast->getType()->isSpecificBuiltinType(BuiltinType::Float) || Cast->getType()->isSpecificBuiltinType(BuiltinType::LongDouble)) && \"promotion from float to either float, double, or long double is \" \"the only expected cast here\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 5519, __PRETTY_FUNCTION__))
5517 Cast->getType()->isSpecificBuiltinType(BuiltinType::LongDouble)) &&(((Cast->getType()->isSpecificBuiltinType(BuiltinType::
Double) || Cast->getType()->isSpecificBuiltinType(BuiltinType
::Float) || Cast->getType()->isSpecificBuiltinType(BuiltinType
::LongDouble)) && "promotion from float to either float, double, or long double is "
"the only expected cast here") ? static_cast<void> (0)
: __assert_fail ("(Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) || Cast->getType()->isSpecificBuiltinType(BuiltinType::Float) || Cast->getType()->isSpecificBuiltinType(BuiltinType::LongDouble)) && \"promotion from float to either float, double, or long double is \" \"the only expected cast here\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 5519, __PRETTY_FUNCTION__))
5518 "promotion from float to either float, double, or long double is "(((Cast->getType()->isSpecificBuiltinType(BuiltinType::
Double) || Cast->getType()->isSpecificBuiltinType(BuiltinType
::Float) || Cast->getType()->isSpecificBuiltinType(BuiltinType
::LongDouble)) && "promotion from float to either float, double, or long double is "
"the only expected cast here") ? static_cast<void> (0)
: __assert_fail ("(Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) || Cast->getType()->isSpecificBuiltinType(BuiltinType::Float) || Cast->getType()->isSpecificBuiltinType(BuiltinType::LongDouble)) && \"promotion from float to either float, double, or long double is \" \"the only expected cast here\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 5519, __PRETTY_FUNCTION__))
5519 "the only expected cast here")(((Cast->getType()->isSpecificBuiltinType(BuiltinType::
Double) || Cast->getType()->isSpecificBuiltinType(BuiltinType
::Float) || Cast->getType()->isSpecificBuiltinType(BuiltinType
::LongDouble)) && "promotion from float to either float, double, or long double is "
"the only expected cast here") ? static_cast<void> (0)
: __assert_fail ("(Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) || Cast->getType()->isSpecificBuiltinType(BuiltinType::Float) || Cast->getType()->isSpecificBuiltinType(BuiltinType::LongDouble)) && \"promotion from float to either float, double, or long double is \" \"the only expected cast here\""
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/Sema/SemaChecking.cpp"
, 5519, __PRETTY_FUNCTION__))
;
5520 Cast->setSubExpr(nullptr);
5521 TheCall->setArg(NumArgs-1, CastArg);
5522 }
5523 }
5524 }
5525
5526 return false;
5527}
5528
5529// Customized Sema Checking for VSX builtins that have the following signature:
5530// vector [...] builtinName(vector [...], vector [...], const int);
5531// Which takes the same type of vectors (any legal vector type) for the first
5532// two arguments and takes compile time constant for the third argument.
5533// Example builtins are :
5534// vector double vec_xxpermdi(vector double, vector double, int);
5535// vector short vec_xxsldwi(vector short, vector short, int);
5536bool Sema::SemaBuiltinVSX(CallExpr *TheCall) {
5537 unsigned ExpectedNumArgs = 3;
5538 if (TheCall->getNumArgs() < ExpectedNumArgs)
5539 return Diag(TheCall->getEndLoc(),
5540 diag::err_typecheck_call_too_few_args_at_least)
5541 << 0 /*function call*/ << ExpectedNumArgs << TheCall->getNumArgs()
5542 << TheCall->getSourceRange();
5543
5544 if (TheCall->getNumArgs() > ExpectedNumArgs)
5545 return Diag(TheCall->getEndLoc(),
5546 diag::err_typecheck_call_too_many_args_at_most)
5547 << 0 /*function call*/ << ExpectedNumArgs << TheCall->getNumArgs()
5548 << TheCall->getSourceRange();
5549
5550 // Check the third argument is a compile time constant
5551 llvm::APSInt Value;
5552 if(!TheCall->getArg(2)->isIntegerConstantExpr(Value, Context))
5553 return Diag(TheCall->getBeginLoc(),
5554 diag::err_vsx_builtin_nonconstant_argument)
5555 << 3 /* argument index */ << TheCall->getDirectCallee()
5556 << SourceRange(TheCall->getArg(2)->getBeginLoc(),
5557 TheCall->getArg(2)->getEndLoc());
5558
5559 QualType Arg1Ty = TheCall->getArg(0)->getType();
5560 QualType Arg2Ty = TheCall->getArg(1)->getType();
5561
5562 // Check the type of argument 1 and argument 2 are vectors.
5563 SourceLocation BuiltinLoc = TheCall->getBeginLoc();
5564 if ((!Arg1Ty->isVectorType() && !Arg1Ty->isDependentType()) ||
5565 (!Arg2Ty->isVectorType() && !Arg2Ty->isDependentType())) {
5566 return Diag(BuiltinLoc, diag::err_vec_builtin_non_vector)
5567 << TheCall->getDirectCallee()
5568 << SourceRange(TheCall->getArg(0)->getBeginLoc(),
5569 TheCall->getArg(1)->getEndLoc());
5570 }
5571
5572 // Check the first two arguments are the same type.
5573 if (!Context.hasSameUnqualifiedType(Arg1Ty, Arg2Ty)) {
5574 return Diag(BuiltinLoc, diag::err_vec_builtin_incompatible_vector)
5575 << TheCall->getDirectCallee()
5576 << SourceRange(TheCall->getArg(0)->getBeginLoc(),
5577 TheCall->getArg(1)->getEndLoc());
5578 }
5579
5580 // When default clang type checking is turned off and the customized type
5581 // checking is used, the returning type of the function must be explicitly
5582 // set. Otherwise it is _Bool by default.
5583 TheCall->setType(Arg1Ty);
5584
5585 return false;
5586}
5587
5588/// SemaBuiltinShuffleVector - Handle __builtin_shufflevector.
5589// This is declared to take (...), so we have to check everything.
5590ExprResult Sema::SemaBuiltinShuffleVector(CallExpr *TheCall) {
5591 if (TheCall->getNumArgs() < 2)
5592 return ExprError(Diag(TheCall->getEndLoc(),
5593 diag::err_typecheck_call_too_few_args_at_least)
5594 << 0 /*function call*/ << 2 << TheCall->getNumArgs()
5595 << TheCall->getSourceRange());
5596
5597 // Determine which of the following types of shufflevector we're checking:
5598 // 1) unary, vector mask: (lhs, mask)
5599 // 2) binary, scalar mask: (lhs, rhs, index, ..., index)
5600 QualType resType = TheCall->getArg(0)->getType();
5601 unsigned numElements = 0;
5602
5603 if (!TheCall->getArg(0)->isTypeDependent() &&
5604 !TheCall->getArg(1)->isTypeDependent()) {
5605 QualType LHSType = TheCall->getArg(0)->getType();
5606 QualType RHSType = TheCall->getArg(1)->getType();
5607
5608 if (!LHSType->isVectorType() || !RHSType->isVectorType())
5609 return ExprError(
5610 Diag(TheCall->getBeginLoc(), diag::err_vec_builtin_non_vector)
5611 << TheCall->getDirectCallee()
5612 << SourceRange(TheCall->getArg(0)->getBeginLoc(),
5613 TheCall->getArg(1)->getEndLoc()));
5614
5615 numElements = LHSType->getAs<VectorType>()->getNumElements();
5616 unsigned numResElements = TheCall->getNumArgs() - 2;
5617
5618 // Check to see if we have a call with 2 vector arguments, the unary shuffle
5619 // with mask. If so, verify that RHS is an integer vector type with the
5620 // same number of elts as lhs.
5621 if (TheCall->getNumArgs() == 2) {
5622 if (!RHSType->hasIntegerRepresentation() ||
5623 RHSType->getAs<VectorType>()->getNumElements() != numElements)
5624 return ExprError(Diag(TheCall->getBeginLoc(),
5625 diag::err_vec_builtin_incompatible_vector)
5626 << TheCall->getDirectCallee()
5627 << SourceRange(TheCall->getArg(1)->getBeginLoc(),
5628 TheCall->getArg(1)->getEndLoc()));
5629 } else if (!Context.hasSameUnqualifiedType(LHSType, RHSType)) {
5630 return ExprError(Diag(TheCall->getBeginLoc(),
5631 diag::err_vec_builtin_incompatible_vector)
5632 << TheCall->getDirectCallee()
5633 << SourceRange(TheCall->getArg(0)->getBeginLoc(),
5634 TheCall->getArg(1)->getEndLoc()));
5635 } else if (numElements != numResElements) {
5636 QualType eltType = LHSType->getAs<VectorType>()->getElementType();
5637 resType = Context.getVectorType(eltType, numResElements,
5638 VectorType::GenericVector);
5639 }
5640 }
5641
5642 for (unsigned i = 2; i < TheCall->getNumArgs(); i++) {
5643 if (TheCall->getArg(i)->isTypeDependent() ||
5644 TheCall->getArg(i)->isValueDependent())
5645 continue;
5646
5647 llvm::APSInt Result(32);
5648 if (!TheCall->getArg(i)->isIntegerConstantExpr(Result, Context))
5649 return ExprError(Diag(TheCall->getBeginLoc(),
5650 diag::err_shufflevector_nonconstant_argument)
5651 << TheCall->getArg(i)->getSourceRange());
5652
5653 // Allow -1 which will be translated to undef in the IR.
5654 if (Result.isSigned() && Result.isAllOnesValue())
5655 continue;
5656
5657 if (Result.getActiveBits() > 64 || Result.getZExtValue() >= numElements*2)
5658 return ExprError(Diag(TheCall->getBeginLoc(),
5659 diag::err_shufflevector_argument_too_large)
5660 << TheCall->getArg(i)->getSourceRange());
5661 }
5662
5663 SmallVector<Expr*, 32> exprs;
5664
5665 for (unsigned i = 0, e = TheCall->getNumArgs(); i != e; i++) {
5666 exprs.push_back(TheCall->getArg(i));
5667 TheCall->setArg(i, nullptr);
5668 }
5669
5670 return new (Context) ShuffleVectorExpr(Context, exprs, resType,
5671 TheCall->getCallee()->getBeginLoc(),
5672 TheCall->getRParenLoc());
5673}
5674
5675/// SemaConvertVectorExpr - Handle __builtin_convertvector
5676ExprResult Sema::SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo,
5677 SourceLocation BuiltinLoc,
5678 SourceLocation RParenLoc) {
5679 ExprValueKind VK = VK_RValue;
5680 ExprObjectKind OK = OK_Ordinary;
5681 QualType DstTy = TInfo->getType();
5682 QualType SrcTy = E->getType();
5683
5684 if (!SrcTy->isVectorType() && !SrcTy->isDependentType())
5685 return ExprError(Diag(BuiltinLoc,
5686 diag::err_convertvector_non_vector)
5687 << E->getSourceRange());
5688 if (!DstTy->isVectorType() && !DstTy->isDependentType())
5689 return ExprError(Diag(BuiltinLoc,
5690 diag::err_convertvector_non_vector_type));
5691
5692 if (!SrcTy->isDependentType() && !DstTy->isDependentType()) {
5693 unsigned SrcElts = SrcTy->getAs<VectorType>()->getNumElements();
5694 unsigned DstElts = DstTy->getAs<VectorType>()->getNumElements();
5695 if (SrcElts != DstElts)
5696 return ExprError(Diag(BuiltinLoc,
5697 diag::err_convertvector_incompatible_vector)
5698 << E->getSourceRange());
5699 }
5700
5701 return new (Context)
5702 ConvertVectorExpr(E, TInfo, DstTy, VK, OK, BuiltinLoc, RParenLoc);
5703}
5704
5705/// SemaBuiltinPrefetch - Handle __builtin_prefetch.
5706// This is declared to take (const void*, ...) and can take two