clang  8.0.0svn
SemaChecking.cpp
Go to the documentation of this file.
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"
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"
33 #include "clang/AST/Stmt.h"
34 #include "clang/AST/TemplateBase.h"
35 #include "clang/AST/Type.h"
36 #include "clang/AST/TypeLoc.h"
40 #include "clang/Basic/CharInfo.h"
41 #include "clang/Basic/Diagnostic.h"
43 #include "clang/Basic/LLVM.h"
50 #include "clang/Basic/Specifiers.h"
51 #include "clang/Basic/SyncScope.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.
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"
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 
99 using namespace clang;
100 using namespace sema;
101 
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.
110 static 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.
130 static 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 
156 static 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.
180 static 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 
194 static 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  }
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  }
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 
239 static 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();
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 
277 static 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 
340 static 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 
362 static 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.
368 static 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() !=
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 
401 static 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 
410 static 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.
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.
451 static bool checkOpenCLEnqueueIntType(Sema &S, Expr *E,
452  const QualType &IntType);
453 
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.
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, ...)
513 static 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,
600  S.Diag(TheCall->getArg(4)->getBeginLoc(),
601  diag::err_opencl_builtin_expected_type)
602  << TheCall->getDirectCallee()
604  return true;
605  }
606 
607  // Sixth argument is always passed as a pointer to clk_event_t.
608  if (!Arg5->isNullPointerConstant(S.Context,
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()
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.
632 static OpenCLAccessAttr *getOpenCLArgAccess(const Decl *D) {
633  return D->getAttr<OpenCLAccessAttr>();
634 }
635 
636 /// Returns true if pipe element type is different from the pointer.
637 static 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.
687 static 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.
710 static 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.
765 static 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.
794 static 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.
817 static 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.
836 static 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");
873  }
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.
882 static bool
883 CheckBuiltinTargetSupport(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 
895 Sema::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;
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 &&
920  "Wrong # arguments to builtin CFStringMakeConstantString");
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:
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.
1424 static 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;
1440  return shift ? 127 : (1 << IsQuad) - 1;
1442  assert(!shift && "cannot shift float types!");
1443  return (4 << IsQuad) - 1;
1445  assert(!shift && "cannot shift float types!");
1446  return (2 << IsQuad) - 1;
1448  assert(!shift && "cannot shift float types!");
1449  return (1 << IsQuad) - 1;
1450  }
1451  llvm_unreachable("Invalid NeonTypeFlag!");
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.
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;
1482  break;
1484  return Context.HalfTy;
1486  return Context.FloatTy;
1488  return Context.DoubleTy;
1489  }
1490  llvm_unreachable("Invalid NeonTypeFlag!");
1491 }
1492 
1493 bool 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 =
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 
1561 bool Sema::CheckARMBuiltinExclusiveCall(unsigned BuiltinID, CallExpr *TheCall,
1562  unsigned MaxWidth) {
1563  assert((BuiltinID == ARM::BI__builtin_arm_ldrex ||
1564  BuiltinID == ARM::BI__builtin_arm_ldaex ||
1565  BuiltinID == ARM::BI__builtin_arm_strex ||
1566  BuiltinID == ARM::BI__builtin_arm_stlex ||
1567  BuiltinID == AArch64::BI__builtin_arm_ldrex ||
1568  BuiltinID == AArch64::BI__builtin_arm_ldaex ||
1569  BuiltinID == AArch64::BI__builtin_arm_strex ||
1570  BuiltinID == AArch64::BI__builtin_arm_stlex) &&
1571  "unexpected ARM builtin");
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");
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:
1645  // okay
1646  break;
1647 
1648  case Qualifiers::OCL_Weak:
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);
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 
1676 bool 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 
1726 bool 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  if (BuiltinID == AArch64::BI__getReg)
1753  return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31);
1754 
1755  if (CheckNeonBuiltinFunctionCall(BuiltinID, TheCall))
1756  return true;
1757 
1758  // For intrinsics which take an immediate value as part of the instruction,
1759  // range check them here.
1760  unsigned i = 0, l = 0, u = 0;
1761  switch (BuiltinID) {
1762  default: return false;
1763  case AArch64::BI__builtin_arm_dmb:
1764  case AArch64::BI__builtin_arm_dsb:
1765  case AArch64::BI__builtin_arm_isb: l = 0; u = 15; break;
1766  }
1767 
1768  return SemaBuiltinConstantArgRange(TheCall, i, l, u + l);
1769 }
1770 
1771 bool Sema::CheckHexagonBuiltinCpu(unsigned BuiltinID, CallExpr *TheCall) {
1772  static const std::map<unsigned, std::vector<StringRef>> ValidCPU = {
1773  { Hexagon::BI__builtin_HEXAGON_A6_vcmpbeq_notany, {"v65"} },
1774  { Hexagon::BI__builtin_HEXAGON_A6_vminub_RdP, {"v62", "v65"} },
1775  { Hexagon::BI__builtin_HEXAGON_M6_vabsdiffb, {"v62", "v65"} },
1776  { Hexagon::BI__builtin_HEXAGON_M6_vabsdiffub, {"v62", "v65"} },
1777  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_acc, {"v60", "v62", "v65"} },
1778  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_and, {"v60", "v62", "v65"} },
1779  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_nac, {"v60", "v62", "v65"} },
1780  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_or, {"v60", "v62", "v65"} },
1781  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p, {"v60", "v62", "v65"} },
1782  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_xacc, {"v60", "v62", "v65"} },
1783  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_acc, {"v60", "v62", "v65"} },
1784  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_and, {"v60", "v62", "v65"} },
1785  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_nac, {"v60", "v62", "v65"} },
1786  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_or, {"v60", "v62", "v65"} },
1787  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r, {"v60", "v62", "v65"} },
1788  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_xacc, {"v60", "v62", "v65"} },
1789  { Hexagon::BI__builtin_HEXAGON_S6_vsplatrbp, {"v62", "v65"} },
1790  { Hexagon::BI__builtin_HEXAGON_S6_vtrunehb_ppp, {"v62", "v65"} },
1791  { Hexagon::BI__builtin_HEXAGON_S6_vtrunohb_ppp, {"v62", "v65"} },
1792  };
1793 
1794  static const std::map<unsigned, std::vector<StringRef>> ValidHVX = {
1795  { Hexagon::BI__builtin_HEXAGON_V6_extractw, {"v60", "v62", "v65"} },
1796  { Hexagon::BI__builtin_HEXAGON_V6_extractw_128B, {"v60", "v62", "v65"} },
1797  { Hexagon::BI__builtin_HEXAGON_V6_hi, {"v60", "v62", "v65"} },
1798  { Hexagon::BI__builtin_HEXAGON_V6_hi_128B, {"v60", "v62", "v65"} },
1799  { Hexagon::BI__builtin_HEXAGON_V6_lo, {"v60", "v62", "v65"} },
1800  { Hexagon::BI__builtin_HEXAGON_V6_lo_128B, {"v60", "v62", "v65"} },
1801  { Hexagon::BI__builtin_HEXAGON_V6_lvsplatb, {"v62", "v65"} },
1802  { Hexagon::BI__builtin_HEXAGON_V6_lvsplatb_128B, {"v62", "v65"} },
1803  { Hexagon::BI__builtin_HEXAGON_V6_lvsplath, {"v62", "v65"} },
1804  { Hexagon::BI__builtin_HEXAGON_V6_lvsplath_128B, {"v62", "v65"} },
1805  { Hexagon::BI__builtin_HEXAGON_V6_lvsplatw, {"v60", "v62", "v65"} },
1806  { Hexagon::BI__builtin_HEXAGON_V6_lvsplatw_128B, {"v60", "v62", "v65"} },
1807  { Hexagon::BI__builtin_HEXAGON_V6_pred_and, {"v60", "v62", "v65"} },
1808  { Hexagon::BI__builtin_HEXAGON_V6_pred_and_128B, {"v60", "v62", "v65"} },
1809  { Hexagon::BI__builtin_HEXAGON_V6_pred_and_n, {"v60", "v62", "v65"} },
1810  { Hexagon::BI__builtin_HEXAGON_V6_pred_and_n_128B, {"v60", "v62", "v65"} },
1811  { Hexagon::BI__builtin_HEXAGON_V6_pred_not, {"v60", "v62", "v65"} },
1812  { Hexagon::BI__builtin_HEXAGON_V6_pred_not_128B, {"v60", "v62", "v65"} },
1813  { Hexagon::BI__builtin_HEXAGON_V6_pred_or, {"v60", "v62", "v65"} },
1814  { Hexagon::BI__builtin_HEXAGON_V6_pred_or_128B, {"v60", "v62", "v65"} },
1815  { Hexagon::BI__builtin_HEXAGON_V6_pred_or_n, {"v60", "v62", "v65"} },
1816  { Hexagon::BI__builtin_HEXAGON_V6_pred_or_n_128B, {"v60", "v62", "v65"} },
1817  { Hexagon::BI__builtin_HEXAGON_V6_pred_scalar2, {"v60", "v62", "v65"} },
1818  { Hexagon::BI__builtin_HEXAGON_V6_pred_scalar2_128B, {"v60", "v62", "v65"} },
1819  { Hexagon::BI__builtin_HEXAGON_V6_pred_scalar2v2, {"v62", "v65"} },
1820  { Hexagon::BI__builtin_HEXAGON_V6_pred_scalar2v2_128B, {"v62", "v65"} },
1821  { Hexagon::BI__builtin_HEXAGON_V6_pred_xor, {"v60", "v62", "v65"} },
1822  { Hexagon::BI__builtin_HEXAGON_V6_pred_xor_128B, {"v60", "v62", "v65"} },
1823  { Hexagon::BI__builtin_HEXAGON_V6_shuffeqh, {"v62", "v65"} },
1824  { Hexagon::BI__builtin_HEXAGON_V6_shuffeqh_128B, {"v62", "v65"} },
1825  { Hexagon::BI__builtin_HEXAGON_V6_shuffeqw, {"v62", "v65"} },
1826  { Hexagon::BI__builtin_HEXAGON_V6_shuffeqw_128B, {"v62", "v65"} },
1827  { Hexagon::BI__builtin_HEXAGON_V6_vabsb, {"v65"} },
1828  { Hexagon::BI__builtin_HEXAGON_V6_vabsb_128B, {"v65"} },
1829  { Hexagon::BI__builtin_HEXAGON_V6_vabsb_sat, {"v65"} },
1830  { Hexagon::BI__builtin_HEXAGON_V6_vabsb_sat_128B, {"v65"} },
1831  { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffh, {"v60", "v62", "v65"} },
1832  { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffh_128B, {"v60", "v62", "v65"} },
1833  { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffub, {"v60", "v62", "v65"} },
1834  { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffub_128B, {"v60", "v62", "v65"} },
1835  { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffuh, {"v60", "v62", "v65"} },
1836  { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffuh_128B, {"v60", "v62", "v65"} },
1837  { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffw, {"v60", "v62", "v65"} },
1838  { Hexagon::BI__builtin_HEXAGON_V6_vabsdiffw_128B, {"v60", "v62", "v65"} },
1839  { Hexagon::BI__builtin_HEXAGON_V6_vabsh, {"v60", "v62", "v65"} },
1840  { Hexagon::BI__builtin_HEXAGON_V6_vabsh_128B, {"v60", "v62", "v65"} },
1841  { Hexagon::BI__builtin_HEXAGON_V6_vabsh_sat, {"v60", "v62", "v65"} },
1842  { Hexagon::BI__builtin_HEXAGON_V6_vabsh_sat_128B, {"v60", "v62", "v65"} },
1843  { Hexagon::BI__builtin_HEXAGON_V6_vabsw, {"v60", "v62", "v65"} },
1844  { Hexagon::BI__builtin_HEXAGON_V6_vabsw_128B, {"v60", "v62", "v65"} },
1845  { Hexagon::BI__builtin_HEXAGON_V6_vabsw_sat, {"v60", "v62", "v65"} },
1846  { Hexagon::BI__builtin_HEXAGON_V6_vabsw_sat_128B, {"v60", "v62", "v65"} },
1847  { Hexagon::BI__builtin_HEXAGON_V6_vaddb, {"v60", "v62", "v65"} },
1848  { Hexagon::BI__builtin_HEXAGON_V6_vaddb_128B, {"v60", "v62", "v65"} },
1849  { Hexagon::BI__builtin_HEXAGON_V6_vaddb_dv, {"v60", "v62", "v65"} },
1850  { Hexagon::BI__builtin_HEXAGON_V6_vaddb_dv_128B, {"v60", "v62", "v65"} },
1851  { Hexagon::BI__builtin_HEXAGON_V6_vaddbsat, {"v62", "v65"} },
1852  { Hexagon::BI__builtin_HEXAGON_V6_vaddbsat_128B, {"v62", "v65"} },
1853  { Hexagon::BI__builtin_HEXAGON_V6_vaddbsat_dv, {"v62", "v65"} },
1854  { Hexagon::BI__builtin_HEXAGON_V6_vaddbsat_dv_128B, {"v62", "v65"} },
1855  { Hexagon::BI__builtin_HEXAGON_V6_vaddcarry, {"v62", "v65"} },
1856  { Hexagon::BI__builtin_HEXAGON_V6_vaddcarry_128B, {"v62", "v65"} },
1857  { Hexagon::BI__builtin_HEXAGON_V6_vaddclbh, {"v62", "v65"} },
1858  { Hexagon::BI__builtin_HEXAGON_V6_vaddclbh_128B, {"v62", "v65"} },
1859  { Hexagon::BI__builtin_HEXAGON_V6_vaddclbw, {"v62", "v65"} },
1860  { Hexagon::BI__builtin_HEXAGON_V6_vaddclbw_128B, {"v62", "v65"} },
1861  { Hexagon::BI__builtin_HEXAGON_V6_vaddh, {"v60", "v62", "v65"} },
1862  { Hexagon::BI__builtin_HEXAGON_V6_vaddh_128B, {"v60", "v62", "v65"} },
1863  { Hexagon::BI__builtin_HEXAGON_V6_vaddh_dv, {"v60", "v62", "v65"} },
1864  { Hexagon::BI__builtin_HEXAGON_V6_vaddh_dv_128B, {"v60", "v62", "v65"} },
1865  { Hexagon::BI__builtin_HEXAGON_V6_vaddhsat, {"v60", "v62", "v65"} },
1866  { Hexagon::BI__builtin_HEXAGON_V6_vaddhsat_128B, {"v60", "v62", "v65"} },
1867  { Hexagon::BI__builtin_HEXAGON_V6_vaddhsat_dv, {"v60", "v62", "v65"} },
1868  { Hexagon::BI__builtin_HEXAGON_V6_vaddhsat_dv_128B, {"v60", "v62", "v65"} },
1869  { Hexagon::BI__builtin_HEXAGON_V6_vaddhw, {"v60", "v62", "v65"} },
1870  { Hexagon::BI__builtin_HEXAGON_V6_vaddhw_128B, {"v60", "v62", "v65"} },
1871  { Hexagon::BI__builtin_HEXAGON_V6_vaddhw_acc, {"v62", "v65"} },
1872  { Hexagon::BI__builtin_HEXAGON_V6_vaddhw_acc_128B, {"v62", "v65"} },
1873  { Hexagon::BI__builtin_HEXAGON_V6_vaddubh, {"v60", "v62", "v65"} },
1874  { Hexagon::BI__builtin_HEXAGON_V6_vaddubh_128B, {"v60", "v62", "v65"} },
1875  { Hexagon::BI__builtin_HEXAGON_V6_vaddubh_acc, {"v62", "v65"} },
1876  { Hexagon::BI__builtin_HEXAGON_V6_vaddubh_acc_128B, {"v62", "v65"} },
1877  { Hexagon::BI__builtin_HEXAGON_V6_vaddubsat, {"v60", "v62", "v65"} },
1878  { Hexagon::BI__builtin_HEXAGON_V6_vaddubsat_128B, {"v60", "v62", "v65"} },
1879  { Hexagon::BI__builtin_HEXAGON_V6_vaddubsat_dv, {"v60", "v62", "v65"} },
1880  { Hexagon::BI__builtin_HEXAGON_V6_vaddubsat_dv_128B, {"v60", "v62", "v65"} },
1881  { Hexagon::BI__builtin_HEXAGON_V6_vaddububb_sat, {"v62", "v65"} },
1882  { Hexagon::BI__builtin_HEXAGON_V6_vaddububb_sat_128B, {"v62", "v65"} },
1883  { Hexagon::BI__builtin_HEXAGON_V6_vadduhsat, {"v60", "v62", "v65"} },
1884  { Hexagon::BI__builtin_HEXAGON_V6_vadduhsat_128B, {"v60", "v62", "v65"} },
1885  { Hexagon::BI__builtin_HEXAGON_V6_vadduhsat_dv, {"v60", "v62", "v65"} },
1886  { Hexagon::BI__builtin_HEXAGON_V6_vadduhsat_dv_128B, {"v60", "v62", "v65"} },
1887  { Hexagon::BI__builtin_HEXAGON_V6_vadduhw, {"v60", "v62", "v65"} },
1888  { Hexagon::BI__builtin_HEXAGON_V6_vadduhw_128B, {"v60", "v62", "v65"} },
1889  { Hexagon::BI__builtin_HEXAGON_V6_vadduhw_acc, {"v62", "v65"} },
1890  { Hexagon::BI__builtin_HEXAGON_V6_vadduhw_acc_128B, {"v62", "v65"} },
1891  { Hexagon::BI__builtin_HEXAGON_V6_vadduwsat, {"v62", "v65"} },
1892  { Hexagon::BI__builtin_HEXAGON_V6_vadduwsat_128B, {"v62", "v65"} },
1893  { Hexagon::BI__builtin_HEXAGON_V6_vadduwsat_dv, {"v62", "v65"} },
1894  { Hexagon::BI__builtin_HEXAGON_V6_vadduwsat_dv_128B, {"v62", "v65"} },
1895  { Hexagon::BI__builtin_HEXAGON_V6_vaddw, {"v60", "v62", "v65"} },
1896  { Hexagon::BI__builtin_HEXAGON_V6_vaddw_128B, {"v60", "v62", "v65"} },
1897  { Hexagon::BI__builtin_HEXAGON_V6_vaddw_dv, {"v60", "v62", "v65"} },
1898  { Hexagon::BI__builtin_HEXAGON_V6_vaddw_dv_128B, {"v60", "v62", "v65"} },
1899  { Hexagon::BI__builtin_HEXAGON_V6_vaddwsat, {"v60", "v62", "v65"} },
1900  { Hexagon::BI__builtin_HEXAGON_V6_vaddwsat_128B, {"v60", "v62", "v65"} },
1901  { Hexagon::BI__builtin_HEXAGON_V6_vaddwsat_dv, {"v60", "v62", "v65"} },
1902  { Hexagon::BI__builtin_HEXAGON_V6_vaddwsat_dv_128B, {"v60", "v62", "v65"} },
1903  { Hexagon::BI__builtin_HEXAGON_V6_valignb, {"v60", "v62", "v65"} },
1904  { Hexagon::BI__builtin_HEXAGON_V6_valignb_128B, {"v60", "v62", "v65"} },
1905  { Hexagon::BI__builtin_HEXAGON_V6_valignbi, {"v60", "v62", "v65"} },
1906  { Hexagon::BI__builtin_HEXAGON_V6_valignbi_128B, {"v60", "v62", "v65"} },
1907  { Hexagon::BI__builtin_HEXAGON_V6_vand, {"v60", "v62", "v65"} },
1908  { Hexagon::BI__builtin_HEXAGON_V6_vand_128B, {"v60", "v62", "v65"} },
1909  { Hexagon::BI__builtin_HEXAGON_V6_vandnqrt, {"v62", "v65"} },
1910  { Hexagon::BI__builtin_HEXAGON_V6_vandnqrt_128B, {"v62", "v65"} },
1911  { Hexagon::BI__builtin_HEXAGON_V6_vandnqrt_acc, {"v62", "v65"} },
1912  { Hexagon::BI__builtin_HEXAGON_V6_vandnqrt_acc_128B, {"v62", "v65"} },
1913  { Hexagon::BI__builtin_HEXAGON_V6_vandqrt, {"v60", "v62", "v65"} },
1914  { Hexagon::BI__builtin_HEXAGON_V6_vandqrt_128B, {"v60", "v62", "v65"} },
1915  { Hexagon::BI__builtin_HEXAGON_V6_vandqrt_acc, {"v60", "v62", "v65"} },
1916  { Hexagon::BI__builtin_HEXAGON_V6_vandqrt_acc_128B, {"v60", "v62", "v65"} },
1917  { Hexagon::BI__builtin_HEXAGON_V6_vandvnqv, {"v62", "v65"} },
1918  { Hexagon::BI__builtin_HEXAGON_V6_vandvnqv_128B, {"v62", "v65"} },
1919  { Hexagon::BI__builtin_HEXAGON_V6_vandvqv, {"v62", "v65"} },
1920  { Hexagon::BI__builtin_HEXAGON_V6_vandvqv_128B, {"v62", "v65"} },
1921  { Hexagon::BI__builtin_HEXAGON_V6_vandvrt, {"v60", "v62", "v65"} },
1922  { Hexagon::BI__builtin_HEXAGON_V6_vandvrt_128B, {"v60", "v62", "v65"} },
1923  { Hexagon::BI__builtin_HEXAGON_V6_vandvrt_acc, {"v60", "v62", "v65"} },
1924  { Hexagon::BI__builtin_HEXAGON_V6_vandvrt_acc_128B, {"v60", "v62", "v65"} },
1925  { Hexagon::BI__builtin_HEXAGON_V6_vaslh, {"v60", "v62", "v65"} },
1926  { Hexagon::BI__builtin_HEXAGON_V6_vaslh_128B, {"v60", "v62", "v65"} },
1927  { Hexagon::BI__builtin_HEXAGON_V6_vaslh_acc, {"v65"} },
1928  { Hexagon::BI__builtin_HEXAGON_V6_vaslh_acc_128B, {"v65"} },
1929  { Hexagon::BI__builtin_HEXAGON_V6_vaslhv, {"v60", "v62", "v65"} },
1930  { Hexagon::BI__builtin_HEXAGON_V6_vaslhv_128B, {"v60", "v62", "v65"} },
1931  { Hexagon::BI__builtin_HEXAGON_V6_vaslw, {"v60", "v62", "v65"} },
1932  { Hexagon::BI__builtin_HEXAGON_V6_vaslw_128B, {"v60", "v62", "v65"} },
1933  { Hexagon::BI__builtin_HEXAGON_V6_vaslw_acc, {"v60", "v62", "v65"} },
1934  { Hexagon::BI__builtin_HEXAGON_V6_vaslw_acc_128B, {"v60", "v62", "v65"} },
1935  { Hexagon::BI__builtin_HEXAGON_V6_vaslwv, {"v60", "v62", "v65"} },
1936  { Hexagon::BI__builtin_HEXAGON_V6_vaslwv_128B, {"v60", "v62", "v65"} },
1937  { Hexagon::BI__builtin_HEXAGON_V6_vasrh, {"v60", "v62", "v65"} },
1938  { Hexagon::BI__builtin_HEXAGON_V6_vasrh_128B, {"v60", "v62", "v65"} },
1939  { Hexagon::BI__builtin_HEXAGON_V6_vasrh_acc, {"v65"} },
1940  { Hexagon::BI__builtin_HEXAGON_V6_vasrh_acc_128B, {"v65"} },
1941  { Hexagon::BI__builtin_HEXAGON_V6_vasrhbrndsat, {"v60", "v62", "v65"} },
1942  { Hexagon::BI__builtin_HEXAGON_V6_vasrhbrndsat_128B, {"v60", "v62", "v65"} },
1943  { Hexagon::BI__builtin_HEXAGON_V6_vasrhbsat, {"v62", "v65"} },
1944  { Hexagon::BI__builtin_HEXAGON_V6_vasrhbsat_128B, {"v62", "v65"} },
1945  { Hexagon::BI__builtin_HEXAGON_V6_vasrhubrndsat, {"v60", "v62", "v65"} },
1946  { Hexagon::BI__builtin_HEXAGON_V6_vasrhubrndsat_128B, {"v60", "v62", "v65"} },
1947  { Hexagon::BI__builtin_HEXAGON_V6_vasrhubsat, {"v60", "v62", "v65"} },
1948  { Hexagon::BI__builtin_HEXAGON_V6_vasrhubsat_128B, {"v60", "v62", "v65"} },
1949  { Hexagon::BI__builtin_HEXAGON_V6_vasrhv, {"v60", "v62", "v65"} },
1950  { Hexagon::BI__builtin_HEXAGON_V6_vasrhv_128B, {"v60", "v62", "v65"} },
1951  { Hexagon::BI__builtin_HEXAGON_V6_vasruhubrndsat, {"v65"} },
1952  { Hexagon::BI__builtin_HEXAGON_V6_vasruhubrndsat_128B, {"v65"} },
1953  { Hexagon::BI__builtin_HEXAGON_V6_vasruhubsat, {"v65"} },
1954  { Hexagon::BI__builtin_HEXAGON_V6_vasruhubsat_128B, {"v65"} },
1955  { Hexagon::BI__builtin_HEXAGON_V6_vasruwuhrndsat, {"v62", "v65"} },
1956  { Hexagon::BI__builtin_HEXAGON_V6_vasruwuhrndsat_128B, {"v62", "v65"} },
1957  { Hexagon::BI__builtin_HEXAGON_V6_vasruwuhsat, {"v65"} },
1958  { Hexagon::BI__builtin_HEXAGON_V6_vasruwuhsat_128B, {"v65"} },
1959  { Hexagon::BI__builtin_HEXAGON_V6_vasrw, {"v60", "v62", "v65"} },
1960  { Hexagon::BI__builtin_HEXAGON_V6_vasrw_128B, {"v60", "v62", "v65"} },
1961  { Hexagon::BI__builtin_HEXAGON_V6_vasrw_acc, {"v60", "v62", "v65"} },
1962  { Hexagon::BI__builtin_HEXAGON_V6_vasrw_acc_128B, {"v60", "v62", "v65"} },
1963  { Hexagon::BI__builtin_HEXAGON_V6_vasrwh, {"v60", "v62", "v65"} },
1964  { Hexagon::BI__builtin_HEXAGON_V6_vasrwh_128B, {"v60", "v62", "v65"} },
1965  { Hexagon::BI__builtin_HEXAGON_V6_vasrwhrndsat, {"v60", "v62", "v65"} },
1966  { Hexagon::BI__builtin_HEXAGON_V6_vasrwhrndsat_128B, {"v60", "v62", "v65"} },
1967  { Hexagon::BI__builtin_HEXAGON_V6_vasrwhsat, {"v60", "v62", "v65"} },
1968  { Hexagon::BI__builtin_HEXAGON_V6_vasrwhsat_128B, {"v60", "v62", "v65"} },
1969  { Hexagon::BI__builtin_HEXAGON_V6_vasrwuhrndsat, {"v62", "v65"} },
1970  { Hexagon::BI__builtin_HEXAGON_V6_vasrwuhrndsat_128B, {"v62", "v65"} },
1971  { Hexagon::BI__builtin_HEXAGON_V6_vasrwuhsat, {"v60", "v62", "v65"} },
1972  { Hexagon::BI__builtin_HEXAGON_V6_vasrwuhsat_128B, {"v60", "v62", "v65"} },
1973  { Hexagon::BI__builtin_HEXAGON_V6_vasrwv, {"v60", "v62", "v65"} },
1974  { Hexagon::BI__builtin_HEXAGON_V6_vasrwv_128B, {"v60", "v62", "v65"} },
1975  { Hexagon::BI__builtin_HEXAGON_V6_vassign, {"v60", "v62", "v65"} },
1976  { Hexagon::BI__builtin_HEXAGON_V6_vassign_128B, {"v60", "v62", "v65"} },
1977  { Hexagon::BI__builtin_HEXAGON_V6_vassignp, {"v60", "v62", "v65"} },
1978  { Hexagon::BI__builtin_HEXAGON_V6_vassignp_128B, {"v60", "v62", "v65"} },
1979  { Hexagon::BI__builtin_HEXAGON_V6_vavgb, {"v65"} },
1980  { Hexagon::BI__builtin_HEXAGON_V6_vavgb_128B, {"v65"} },
1981  { Hexagon::BI__builtin_HEXAGON_V6_vavgbrnd, {"v65"} },
1982  { Hexagon::BI__builtin_HEXAGON_V6_vavgbrnd_128B, {"v65"} },
1983  { Hexagon::BI__builtin_HEXAGON_V6_vavgh, {"v60", "v62", "v65"} },
1984  { Hexagon::BI__builtin_HEXAGON_V6_vavgh_128B, {"v60", "v62", "v65"} },
1985  { Hexagon::BI__builtin_HEXAGON_V6_vavghrnd, {"v60", "v62", "v65"} },
1986  { Hexagon::BI__builtin_HEXAGON_V6_vavghrnd_128B, {"v60", "v62", "v65"} },
1987  { Hexagon::BI__builtin_HEXAGON_V6_vavgub, {"v60", "v62", "v65"} },
1988  { Hexagon::BI__builtin_HEXAGON_V6_vavgub_128B, {"v60", "v62", "v65"} },
1989  { Hexagon::BI__builtin_HEXAGON_V6_vavgubrnd, {"v60", "v62", "v65"} },
1990  { Hexagon::BI__builtin_HEXAGON_V6_vavgubrnd_128B, {"v60", "v62", "v65"} },
1991  { Hexagon::BI__builtin_HEXAGON_V6_vavguh, {"v60", "v62", "v65"} },
1992  { Hexagon::BI__builtin_HEXAGON_V6_vavguh_128B, {"v60", "v62", "v65"} },
1993  { Hexagon::BI__builtin_HEXAGON_V6_vavguhrnd, {"v60", "v62", "v65"} },
1994  { Hexagon::BI__builtin_HEXAGON_V6_vavguhrnd_128B, {"v60", "v62", "v65"} },
1995  { Hexagon::BI__builtin_HEXAGON_V6_vavguw, {"v65"} },
1996  { Hexagon::BI__builtin_HEXAGON_V6_vavguw_128B, {"v65"} },
1997  { Hexagon::BI__builtin_HEXAGON_V6_vavguwrnd, {"v65"} },
1998  { Hexagon::BI__builtin_HEXAGON_V6_vavguwrnd_128B, {"v65"} },
1999  { Hexagon::BI__builtin_HEXAGON_V6_vavgw, {"v60", "v62", "v65"} },
2000  { Hexagon::BI__builtin_HEXAGON_V6_vavgw_128B, {"v60", "v62", "v65"} },
2001  { Hexagon::BI__builtin_HEXAGON_V6_vavgwrnd, {"v60", "v62", "v65"} },
2002  { Hexagon::BI__builtin_HEXAGON_V6_vavgwrnd_128B, {"v60", "v62", "v65"} },
2003  { Hexagon::BI__builtin_HEXAGON_V6_vcl0h, {"v60", "v62", "v65"} },
2004  { Hexagon::BI__builtin_HEXAGON_V6_vcl0h_128B, {"v60", "v62", "v65"} },
2005  { Hexagon::BI__builtin_HEXAGON_V6_vcl0w, {"v60", "v62", "v65"} },
2006  { Hexagon::BI__builtin_HEXAGON_V6_vcl0w_128B, {"v60", "v62", "v65"} },
2007  { Hexagon::BI__builtin_HEXAGON_V6_vcombine, {"v60", "v62", "v65"} },
2008  { Hexagon::BI__builtin_HEXAGON_V6_vcombine_128B, {"v60", "v62", "v65"} },
2009  { Hexagon::BI__builtin_HEXAGON_V6_vd0, {"v60", "v62", "v65"} },
2010  { Hexagon::BI__builtin_HEXAGON_V6_vd0_128B, {"v60", "v62", "v65"} },
2011  { Hexagon::BI__builtin_HEXAGON_V6_vdd0, {"v65"} },
2012  { Hexagon::BI__builtin_HEXAGON_V6_vdd0_128B, {"v65"} },
2013  { Hexagon::BI__builtin_HEXAGON_V6_vdealb, {"v60", "v62", "v65"} },
2014  { Hexagon::BI__builtin_HEXAGON_V6_vdealb_128B, {"v60", "v62", "v65"} },
2015  { Hexagon::BI__builtin_HEXAGON_V6_vdealb4w, {"v60", "v62", "v65"} },
2016  { Hexagon::BI__builtin_HEXAGON_V6_vdealb4w_128B, {"v60", "v62", "v65"} },
2017  { Hexagon::BI__builtin_HEXAGON_V6_vdealh, {"v60", "v62", "v65"} },
2018  { Hexagon::BI__builtin_HEXAGON_V6_vdealh_128B, {"v60", "v62", "v65"} },
2019  { Hexagon::BI__builtin_HEXAGON_V6_vdealvdd, {"v60", "v62", "v65"} },
2020  { Hexagon::BI__builtin_HEXAGON_V6_vdealvdd_128B, {"v60", "v62", "v65"} },
2021  { Hexagon::BI__builtin_HEXAGON_V6_vdelta, {"v60", "v62", "v65"} },
2022  { Hexagon::BI__builtin_HEXAGON_V6_vdelta_128B, {"v60", "v62", "v65"} },
2023  { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus, {"v60", "v62", "v65"} },
2024  { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus_128B, {"v60", "v62", "v65"} },
2025  { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus_acc, {"v60", "v62", "v65"} },
2026  { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus_acc_128B, {"v60", "v62", "v65"} },
2027  { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus_dv, {"v60", "v62", "v65"} },
2028  { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus_dv_128B, {"v60", "v62", "v65"} },
2029  { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus_dv_acc, {"v60", "v62", "v65"} },
2030  { Hexagon::BI__builtin_HEXAGON_V6_vdmpybus_dv_acc_128B, {"v60", "v62", "v65"} },
2031  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb, {"v60", "v62", "v65"} },
2032  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb_128B, {"v60", "v62", "v65"} },
2033  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb_acc, {"v60", "v62", "v65"} },
2034  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb_acc_128B, {"v60", "v62", "v65"} },
2035  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb_dv, {"v60", "v62", "v65"} },
2036  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb_dv_128B, {"v60", "v62", "v65"} },
2037  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb_dv_acc, {"v60", "v62", "v65"} },
2038  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhb_dv_acc_128B, {"v60", "v62", "v65"} },
2039  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhisat, {"v60", "v62", "v65"} },
2040  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhisat_128B, {"v60", "v62", "v65"} },
2041  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhisat_acc, {"v60", "v62", "v65"} },
2042  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhisat_acc_128B, {"v60", "v62", "v65"} },
2043  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsat, {"v60", "v62", "v65"} },
2044  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsat_128B, {"v60", "v62", "v65"} },
2045  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsat_acc, {"v60", "v62", "v65"} },
2046  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsat_acc_128B, {"v60", "v62", "v65"} },
2047  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsuisat, {"v60", "v62", "v65"} },
2048  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsuisat_128B, {"v60", "v62", "v65"} },
2049  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsuisat_acc, {"v60", "v62", "v65"} },
2050  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsuisat_acc_128B, {"v60", "v62", "v65"} },
2051  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsusat, {"v60", "v62", "v65"} },
2052  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsusat_128B, {"v60", "v62", "v65"} },
2053  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsusat_acc, {"v60", "v62", "v65"} },
2054  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhsusat_acc_128B, {"v60", "v62", "v65"} },
2055  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhvsat, {"v60", "v62", "v65"} },
2056  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhvsat_128B, {"v60", "v62", "v65"} },
2057  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhvsat_acc, {"v60", "v62", "v65"} },
2058  { Hexagon::BI__builtin_HEXAGON_V6_vdmpyhvsat_acc_128B, {"v60", "v62", "v65"} },
2059  { Hexagon::BI__builtin_HEXAGON_V6_vdsaduh, {"v60", "v62", "v65"} },
2060  { Hexagon::BI__builtin_HEXAGON_V6_vdsaduh_128B, {"v60", "v62", "v65"} },
2061  { Hexagon::BI__builtin_HEXAGON_V6_vdsaduh_acc, {"v60", "v62", "v65"} },
2062  { Hexagon::BI__builtin_HEXAGON_V6_vdsaduh_acc_128B, {"v60", "v62", "v65"} },
2063  { Hexagon::BI__builtin_HEXAGON_V6_veqb, {"v60", "v62", "v65"} },
2064  { Hexagon::BI__builtin_HEXAGON_V6_veqb_128B, {"v60", "v62", "v65"} },
2065  { Hexagon::BI__builtin_HEXAGON_V6_veqb_and, {"v60", "v62", "v65"} },
2066  { Hexagon::BI__builtin_HEXAGON_V6_veqb_and_128B, {"v60", "v62", "v65"} },
2067  { Hexagon::BI__builtin_HEXAGON_V6_veqb_or, {"v60", "v62", "v65"} },
2068  { Hexagon::BI__builtin_HEXAGON_V6_veqb_or_128B, {"v60", "v62", "v65"} },
2069  { Hexagon::BI__builtin_HEXAGON_V6_veqb_xor, {"v60", "v62", "v65"} },
2070  { Hexagon::BI__builtin_HEXAGON_V6_veqb_xor_128B, {"v60", "v62", "v65"} },
2071  { Hexagon::BI__builtin_HEXAGON_V6_veqh, {"v60", "v62", "v65"} },
2072  { Hexagon::BI__builtin_HEXAGON_V6_veqh_128B, {"v60", "v62", "v65"} },
2073  { Hexagon::BI__builtin_HEXAGON_V6_veqh_and, {"v60", "v62", "v65"} },
2074  { Hexagon::BI__builtin_HEXAGON_V6_veqh_and_128B, {"v60", "v62", "v65"} },
2075  { Hexagon::BI__builtin_HEXAGON_V6_veqh_or, {"v60", "v62", "v65"} },
2076  { Hexagon::BI__builtin_HEXAGON_V6_veqh_or_128B, {"v60", "v62", "v65"} },
2077  { Hexagon::BI__builtin_HEXAGON_V6_veqh_xor, {"v60", "v62", "v65"} },
2078  { Hexagon::BI__builtin_HEXAGON_V6_veqh_xor_128B, {"v60", "v62", "v65"} },
2079  { Hexagon::BI__builtin_HEXAGON_V6_veqw, {"v60", "v62", "v65"} },
2080  { Hexagon::BI__builtin_HEXAGON_V6_veqw_128B, {"v60", "v62", "v65"} },
2081  { Hexagon::BI__builtin_HEXAGON_V6_veqw_and, {"v60", "v62", "v65"} },
2082  { Hexagon::BI__builtin_HEXAGON_V6_veqw_and_128B, {"v60", "v62", "v65"} },
2083  { Hexagon::BI__builtin_HEXAGON_V6_veqw_or, {"v60", "v62", "v65"} },
2084  { Hexagon::BI__builtin_HEXAGON_V6_veqw_or_128B, {"v60", "v62", "v65"} },
2085  { Hexagon::BI__builtin_HEXAGON_V6_veqw_xor, {"v60", "v62", "v65"} },
2086  { Hexagon::BI__builtin_HEXAGON_V6_veqw_xor_128B, {"v60", "v62", "v65"} },
2087  { Hexagon::BI__builtin_HEXAGON_V6_vgtb, {"v60", "v62", "v65"} },
2088  { Hexagon::BI__builtin_HEXAGON_V6_vgtb_128B, {"v60", "v62", "v65"} },
2089  { Hexagon::BI__builtin_HEXAGON_V6_vgtb_and, {"v60", "v62", "v65"} },
2090  { Hexagon::BI__builtin_HEXAGON_V6_vgtb_and_128B, {"v60", "v62", "v65"} },
2091  { Hexagon::BI__builtin_HEXAGON_V6_vgtb_or, {"v60", "v62", "v65"} },
2092  { Hexagon::BI__builtin_HEXAGON_V6_vgtb_or_128B, {"v60", "v62", "v65"} },
2093  { Hexagon::BI__builtin_HEXAGON_V6_vgtb_xor, {"v60", "v62", "v65"} },
2094  { Hexagon::BI__builtin_HEXAGON_V6_vgtb_xor_128B, {"v60", "v62", "v65"} },
2095  { Hexagon::BI__builtin_HEXAGON_V6_vgth, {"v60", "v62", "v65"} },
2096  { Hexagon::BI__builtin_HEXAGON_V6_vgth_128B, {"v60", "v62", "v65"} },
2097  { Hexagon::BI__builtin_HEXAGON_V6_vgth_and, {"v60", "v62", "v65"} },
2098  { Hexagon::BI__builtin_HEXAGON_V6_vgth_and_128B, {"v60", "v62", "v65"} },
2099  { Hexagon::BI__builtin_HEXAGON_V6_vgth_or, {"v60", "v62", "v65"} },
2100  { Hexagon::BI__builtin_HEXAGON_V6_vgth_or_128B, {"v60", "v62", "v65"} },
2101  { Hexagon::BI__builtin_HEXAGON_V6_vgth_xor, {"v60", "v62", "v65"} },
2102  { Hexagon::BI__builtin_HEXAGON_V6_vgth_xor_128B, {"v60", "v62", "v65"} },
2103  { Hexagon::BI__builtin_HEXAGON_V6_vgtub, {"v60", "v62", "v65"} },
2104  { Hexagon::BI__builtin_HEXAGON_V6_vgtub_128B, {"v60", "v62", "v65"} },
2105  { Hexagon::BI__builtin_HEXAGON_V6_vgtub_and, {"v60", "v62", "v65"} },
2106  { Hexagon::BI__builtin_HEXAGON_V6_vgtub_and_128B, {"v60", "v62", "v65"} },
2107  { Hexagon::BI__builtin_HEXAGON_V6_vgtub_or, {"v60", "v62", "v65"} },
2108  { Hexagon::BI__builtin_HEXAGON_V6_vgtub_or_128B, {"v60", "v62", "v65"} },
2109  { Hexagon::BI__builtin_HEXAGON_V6_vgtub_xor, {"v60", "v62", "v65"} },
2110  { Hexagon::BI__builtin_HEXAGON_V6_vgtub_xor_128B, {"v60", "v62", "v65"} },
2111  { Hexagon::BI__builtin_HEXAGON_V6_vgtuh, {"v60", "v62", "v65"} },
2112  { Hexagon::BI__builtin_HEXAGON_V6_vgtuh_128B, {"v60", "v62", "v65"} },
2113  { Hexagon::BI__builtin_HEXAGON_V6_vgtuh_and, {"v60", "v62", "v65"} },
2114  { Hexagon::BI__builtin_HEXAGON_V6_vgtuh_and_128B, {"v60", "v62", "v65"} },
2115  { Hexagon::BI__builtin_HEXAGON_V6_vgtuh_or, {"v60", "v62", "v65"} },
2116  { Hexagon::BI__builtin_HEXAGON_V6_vgtuh_or_128B, {"v60", "v62", "v65"} },
2117  { Hexagon::BI__builtin_HEXAGON_V6_vgtuh_xor, {"v60", "v62", "v65"} },
2118  { Hexagon::BI__builtin_HEXAGON_V6_vgtuh_xor_128B, {"v60", "v62", "v65"} },
2119  { Hexagon::BI__builtin_HEXAGON_V6_vgtuw, {"v60", "v62", "v65"} },
2120  { Hexagon::BI__builtin_HEXAGON_V6_vgtuw_128B, {"v60", "v62", "v65"} },
2121  { Hexagon::BI__builtin_HEXAGON_V6_vgtuw_and, {"v60", "v62", "v65"} },
2122  { Hexagon::BI__builtin_HEXAGON_V6_vgtuw_and_128B, {"v60", "v62", "v65"} },
2123  { Hexagon::BI__builtin_HEXAGON_V6_vgtuw_or, {"v60", "v62", "v65"} },
2124  { Hexagon::BI__builtin_HEXAGON_V6_vgtuw_or_128B, {"v60", "v62", "v65"} },
2125  { Hexagon::BI__builtin_HEXAGON_V6_vgtuw_xor, {"v60", "v62", "v65"} },
2126  { Hexagon::BI__builtin_HEXAGON_V6_vgtuw_xor_128B, {"v60", "v62", "v65"} },
2127  { Hexagon::BI__builtin_HEXAGON_V6_vgtw, {"v60", "v62", "v65"} },
2128  { Hexagon::BI__builtin_HEXAGON_V6_vgtw_128B, {"v60", "v62", "v65"} },
2129  { Hexagon::BI__builtin_HEXAGON_V6_vgtw_and, {"v60", "v62", "v65"} },
2130  { Hexagon::BI__builtin_HEXAGON_V6_vgtw_and_128B, {"v60", "v62", "v65"} },
2131  { Hexagon::BI__builtin_HEXAGON_V6_vgtw_or, {"v60", "v62", "v65"} },
2132  { Hexagon::BI__builtin_HEXAGON_V6_vgtw_or_128B, {"v60", "v62", "v65"} },
2133  { Hexagon::BI__builtin_HEXAGON_V6_vgtw_xor, {"v60", "v62", "v65"} },
2134  { Hexagon::BI__builtin_HEXAGON_V6_vgtw_xor_128B, {"v60", "v62", "v65"} },
2135  { Hexagon::BI__builtin_HEXAGON_V6_vinsertwr, {"v60", "v62", "v65"} },
2136  { Hexagon::BI__builtin_HEXAGON_V6_vinsertwr_128B, {"v60", "v62", "v65"} },
2137  { Hexagon::BI__builtin_HEXAGON_V6_vlalignb, {"v60", "v62", "v65"} },
2138  { Hexagon::BI__builtin_HEXAGON_V6_vlalignb_128B, {"v60", "v62", "v65"} },
2139  { Hexagon::BI__builtin_HEXAGON_V6_vlalignbi, {"v60", "v62", "v65"} },
2140  { Hexagon::BI__builtin_HEXAGON_V6_vlalignbi_128B, {"v60", "v62", "v65"} },
2141  { Hexagon::BI__builtin_HEXAGON_V6_vlsrb, {"v62", "v65"} },
2142  { Hexagon::BI__builtin_HEXAGON_V6_vlsrb_128B, {"v62", "v65"} },
2143  { Hexagon::BI__builtin_HEXAGON_V6_vlsrh, {"v60", "v62", "v65"} },
2144  { Hexagon::BI__builtin_HEXAGON_V6_vlsrh_128B, {"v60", "v62", "v65"} },
2145  { Hexagon::BI__builtin_HEXAGON_V6_vlsrhv, {"v60", "v62", "v65"} },
2146  { Hexagon::BI__builtin_HEXAGON_V6_vlsrhv_128B, {"v60", "v62", "v65"} },
2147  { Hexagon::BI__builtin_HEXAGON_V6_vlsrw, {"v60", "v62", "v65"} },
2148  { Hexagon::BI__builtin_HEXAGON_V6_vlsrw_128B, {"v60", "v62", "v65"} },
2149  { Hexagon::BI__builtin_HEXAGON_V6_vlsrwv, {"v60", "v62", "v65"} },
2150  { Hexagon::BI__builtin_HEXAGON_V6_vlsrwv_128B, {"v60", "v62", "v65"} },
2151  { Hexagon::BI__builtin_HEXAGON_V6_vlut4, {"v65"} },
2152  { Hexagon::BI__builtin_HEXAGON_V6_vlut4_128B, {"v65"} },
2153  { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb, {"v60", "v62", "v65"} },
2154  { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_128B, {"v60", "v62", "v65"} },
2155  { Hexagon::BI__builtin_HEXAGON_V6_vlutvvbi, {"v62", "v65"} },
2156  { Hexagon::BI__builtin_HEXAGON_V6_vlutvvbi_128B, {"v62", "v65"} },
2157  { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_nm, {"v62", "v65"} },
2158  { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_nm_128B, {"v62", "v65"} },
2159  { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_oracc, {"v60", "v62", "v65"} },
2160  { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_oracc_128B, {"v60", "v62", "v65"} },
2161  { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_oracci, {"v62", "v65"} },
2162  { Hexagon::BI__builtin_HEXAGON_V6_vlutvvb_oracci_128B, {"v62", "v65"} },
2163  { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh, {"v60", "v62", "v65"} },
2164  { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_128B, {"v60", "v62", "v65"} },
2165  { Hexagon::BI__builtin_HEXAGON_V6_vlutvwhi, {"v62", "v65"} },
2166  { Hexagon::BI__builtin_HEXAGON_V6_vlutvwhi_128B, {"v62", "v65"} },
2167  { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_nm, {"v62", "v65"} },
2168  { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_nm_128B, {"v62", "v65"} },
2169  { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_oracc, {"v60", "v62", "v65"} },
2170  { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_oracc_128B, {"v60", "v62", "v65"} },
2171  { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_oracci, {"v62", "v65"} },
2172  { Hexagon::BI__builtin_HEXAGON_V6_vlutvwh_oracci_128B, {"v62", "v65"} },
2173  { Hexagon::BI__builtin_HEXAGON_V6_vmaxb, {"v62", "v65"} },
2174  { Hexagon::BI__builtin_HEXAGON_V6_vmaxb_128B, {"v62", "v65"} },
2175  { Hexagon::BI__builtin_HEXAGON_V6_vmaxh, {"v60", "v62", "v65"} },
2176  { Hexagon::BI__builtin_HEXAGON_V6_vmaxh_128B, {"v60", "v62", "v65"} },
2177  { Hexagon::BI__builtin_HEXAGON_V6_vmaxub, {"v60", "v62", "v65"} },
2178  { Hexagon::BI__builtin_HEXAGON_V6_vmaxub_128B, {"v60", "v62", "v65"} },
2179  { Hexagon::BI__builtin_HEXAGON_V6_vmaxuh, {"v60", "v62", "v65"} },
2180  { Hexagon::BI__builtin_HEXAGON_V6_vmaxuh_128B, {"v60", "v62", "v65"} },
2181  { Hexagon::BI__builtin_HEXAGON_V6_vmaxw, {"v60", "v62", "v65"} },
2182  { Hexagon::BI__builtin_HEXAGON_V6_vmaxw_128B, {"v60", "v62", "v65"} },
2183  { Hexagon::BI__builtin_HEXAGON_V6_vminb, {"v62", "v65"} },
2184  { Hexagon::BI__builtin_HEXAGON_V6_vminb_128B, {"v62", "v65"} },
2185  { Hexagon::BI__builtin_HEXAGON_V6_vminh, {"v60", "v62", "v65"} },
2186  { Hexagon::BI__builtin_HEXAGON_V6_vminh_128B, {"v60", "v62", "v65"} },
2187  { Hexagon::BI__builtin_HEXAGON_V6_vminub, {"v60", "v62", "v65"} },
2188  { Hexagon::BI__builtin_HEXAGON_V6_vminub_128B, {"v60", "v62", "v65"} },
2189  { Hexagon::BI__builtin_HEXAGON_V6_vminuh, {"v60", "v62", "v65"} },
2190  { Hexagon::BI__builtin_HEXAGON_V6_vminuh_128B, {"v60", "v62", "v65"} },
2191  { Hexagon::BI__builtin_HEXAGON_V6_vminw, {"v60", "v62", "v65"} },
2192  { Hexagon::BI__builtin_HEXAGON_V6_vminw_128B, {"v60", "v62", "v65"} },
2193  { Hexagon::BI__builtin_HEXAGON_V6_vmpabus, {"v60", "v62", "v65"} },
2194  { Hexagon::BI__builtin_HEXAGON_V6_vmpabus_128B, {"v60", "v62", "v65"} },
2195  { Hexagon::BI__builtin_HEXAGON_V6_vmpabus_acc, {"v60", "v62", "v65"} },
2196  { Hexagon::BI__builtin_HEXAGON_V6_vmpabus_acc_128B, {"v60", "v62", "v65"} },
2197  { Hexagon::BI__builtin_HEXAGON_V6_vmpabusv, {"v60", "v62", "v65"} },
2198  { Hexagon::BI__builtin_HEXAGON_V6_vmpabusv_128B, {"v60", "v62", "v65"} },
2199  { Hexagon::BI__builtin_HEXAGON_V6_vmpabuu, {"v65"} },
2200  { Hexagon::BI__builtin_HEXAGON_V6_vmpabuu_128B, {"v65"} },
2201  { Hexagon::BI__builtin_HEXAGON_V6_vmpabuu_acc, {"v65"} },
2202  { Hexagon::BI__builtin_HEXAGON_V6_vmpabuu_acc_128B, {"v65"} },
2203  { Hexagon::BI__builtin_HEXAGON_V6_vmpabuuv, {"v60", "v62", "v65"} },
2204  { Hexagon::BI__builtin_HEXAGON_V6_vmpabuuv_128B, {"v60", "v62", "v65"} },
2205  { Hexagon::BI__builtin_HEXAGON_V6_vmpahb, {"v60", "v62", "v65"} },
2206  { Hexagon::BI__builtin_HEXAGON_V6_vmpahb_128B, {"v60", "v62", "v65"} },
2207  { Hexagon::BI__builtin_HEXAGON_V6_vmpahb_acc, {"v60", "v62", "v65"} },
2208  { Hexagon::BI__builtin_HEXAGON_V6_vmpahb_acc_128B, {"v60", "v62", "v65"} },
2209  { Hexagon::BI__builtin_HEXAGON_V6_vmpahhsat, {"v65"} },
2210  { Hexagon::BI__builtin_HEXAGON_V6_vmpahhsat_128B, {"v65"} },
2211  { Hexagon::BI__builtin_HEXAGON_V6_vmpauhb, {"v62", "v65"} },
2212  { Hexagon::BI__builtin_HEXAGON_V6_vmpauhb_128B, {"v62", "v65"} },
2213  { Hexagon::BI__builtin_HEXAGON_V6_vmpauhb_acc, {"v62", "v65"} },
2214  { Hexagon::BI__builtin_HEXAGON_V6_vmpauhb_acc_128B, {"v62", "v65"} },
2215  { Hexagon::BI__builtin_HEXAGON_V6_vmpauhuhsat, {"v65"} },
2216  { Hexagon::BI__builtin_HEXAGON_V6_vmpauhuhsat_128B, {"v65"} },
2217  { Hexagon::BI__builtin_HEXAGON_V6_vmpsuhuhsat, {"v65"} },
2218  { Hexagon::BI__builtin_HEXAGON_V6_vmpsuhuhsat_128B, {"v65"} },
2219  { Hexagon::BI__builtin_HEXAGON_V6_vmpybus, {"v60", "v62", "v65"} },
2220  { Hexagon::BI__builtin_HEXAGON_V6_vmpybus_128B, {"v60", "v62", "v65"} },
2221  { Hexagon::BI__builtin_HEXAGON_V6_vmpybus_acc, {"v60", "v62", "v65"} },
2222  { Hexagon::BI__builtin_HEXAGON_V6_vmpybus_acc_128B, {"v60", "v62", "v65"} },
2223  { Hexagon::BI__builtin_HEXAGON_V6_vmpybusv, {"v60", "v62", "v65"} },
2224  { Hexagon::BI__builtin_HEXAGON_V6_vmpybusv_128B, {"v60", "v62", "v65"} },
2225  { Hexagon::BI__builtin_HEXAGON_V6_vmpybusv_acc, {"v60", "v62", "v65"} },
2226  { Hexagon::BI__builtin_HEXAGON_V6_vmpybusv_acc_128B, {"v60", "v62", "v65"} },
2227  { Hexagon::BI__builtin_HEXAGON_V6_vmpybv, {"v60", "v62", "v65"} },
2228  { Hexagon::BI__builtin_HEXAGON_V6_vmpybv_128B, {"v60", "v62", "v65"} },
2229  { Hexagon::BI__builtin_HEXAGON_V6_vmpybv_acc, {"v60", "v62", "v65"} },
2230  { Hexagon::BI__builtin_HEXAGON_V6_vmpybv_acc_128B, {"v60", "v62", "v65"} },
2231  { Hexagon::BI__builtin_HEXAGON_V6_vmpyewuh, {"v60", "v62", "v65"} },
2232  { Hexagon::BI__builtin_HEXAGON_V6_vmpyewuh_128B, {"v60", "v62", "v65"} },
2233  { Hexagon::BI__builtin_HEXAGON_V6_vmpyewuh_64, {"v62", "v65"} },
2234  { Hexagon::BI__builtin_HEXAGON_V6_vmpyewuh_64_128B, {"v62", "v65"} },
2235  { Hexagon::BI__builtin_HEXAGON_V6_vmpyh, {"v60", "v62", "v65"} },
2236  { Hexagon::BI__builtin_HEXAGON_V6_vmpyh_128B, {"v60", "v62", "v65"} },
2237  { Hexagon::BI__builtin_HEXAGON_V6_vmpyh_acc, {"v65"} },
2238  { Hexagon::BI__builtin_HEXAGON_V6_vmpyh_acc_128B, {"v65"} },
2239  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhsat_acc, {"v60", "v62", "v65"} },
2240  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhsat_acc_128B, {"v60", "v62", "v65"} },
2241  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhsrs, {"v60", "v62", "v65"} },
2242  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhsrs_128B, {"v60", "v62", "v65"} },
2243  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhss, {"v60", "v62", "v65"} },
2244  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhss_128B, {"v60", "v62", "v65"} },
2245  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhus, {"v60", "v62", "v65"} },
2246  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhus_128B, {"v60", "v62", "v65"} },
2247  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhus_acc, {"v60", "v62", "v65"} },
2248  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhus_acc_128B, {"v60", "v62", "v65"} },
2249  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhv, {"v60", "v62", "v65"} },
2250  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhv_128B, {"v60", "v62", "v65"} },
2251  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhv_acc, {"v60", "v62", "v65"} },
2252  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhv_acc_128B, {"v60", "v62", "v65"} },
2253  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhvsrs, {"v60", "v62", "v65"} },
2254  { Hexagon::BI__builtin_HEXAGON_V6_vmpyhvsrs_128B, {"v60", "v62", "v65"} },
2255  { Hexagon::BI__builtin_HEXAGON_V6_vmpyieoh, {"v60", "v62", "v65"} },
2256  { Hexagon::BI__builtin_HEXAGON_V6_vmpyieoh_128B, {"v60", "v62", "v65"} },
2257  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiewh_acc, {"v60", "v62", "v65"} },
2258  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiewh_acc_128B, {"v60", "v62", "v65"} },
2259  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiewuh, {"v60", "v62", "v65"} },
2260  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiewuh_128B, {"v60", "v62", "v65"} },
2261  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiewuh_acc, {"v60", "v62", "v65"} },
2262  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiewuh_acc_128B, {"v60", "v62", "v65"} },
2263  { Hexagon::BI__builtin_HEXAGON_V6_vmpyih, {"v60", "v62", "v65"} },
2264  { Hexagon::BI__builtin_HEXAGON_V6_vmpyih_128B, {"v60", "v62", "v65"} },
2265  { Hexagon::BI__builtin_HEXAGON_V6_vmpyih_acc, {"v60", "v62", "v65"} },
2266  { Hexagon::BI__builtin_HEXAGON_V6_vmpyih_acc_128B, {"v60", "v62", "v65"} },
2267  { Hexagon::BI__builtin_HEXAGON_V6_vmpyihb, {"v60", "v62", "v65"} },
2268  { Hexagon::BI__builtin_HEXAGON_V6_vmpyihb_128B, {"v60", "v62", "v65"} },
2269  { Hexagon::BI__builtin_HEXAGON_V6_vmpyihb_acc, {"v60", "v62", "v65"} },
2270  { Hexagon::BI__builtin_HEXAGON_V6_vmpyihb_acc_128B, {"v60", "v62", "v65"} },
2271  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiowh, {"v60", "v62", "v65"} },
2272  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiowh_128B, {"v60", "v62", "v65"} },
2273  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwb, {"v60", "v62", "v65"} },
2274  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwb_128B, {"v60", "v62", "v65"} },
2275  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwb_acc, {"v60", "v62", "v65"} },
2276  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwb_acc_128B, {"v60", "v62", "v65"} },
2277  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwh, {"v60", "v62", "v65"} },
2278  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwh_128B, {"v60", "v62", "v65"} },
2279  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwh_acc, {"v60", "v62", "v65"} },
2280  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwh_acc_128B, {"v60", "v62", "v65"} },
2281  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwub, {"v62", "v65"} },
2282  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwub_128B, {"v62", "v65"} },
2283  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwub_acc, {"v62", "v65"} },
2284  { Hexagon::BI__builtin_HEXAGON_V6_vmpyiwub_acc_128B, {"v62", "v65"} },
2285  { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh, {"v60", "v62", "v65"} },
2286  { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_128B, {"v60", "v62", "v65"} },
2287  { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_64_acc, {"v62", "v65"} },
2288  { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_64_acc_128B, {"v62", "v65"} },
2289  { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_rnd, {"v60", "v62", "v65"} },
2290  { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_rnd_128B, {"v60", "v62", "v65"} },
2291  { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_rnd_sacc, {"v60", "v62", "v65"} },
2292  { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_rnd_sacc_128B, {"v60", "v62", "v65"} },
2293  { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_sacc, {"v60", "v62", "v65"} },
2294  { Hexagon::BI__builtin_HEXAGON_V6_vmpyowh_sacc_128B, {"v60", "v62", "v65"} },
2295  { Hexagon::BI__builtin_HEXAGON_V6_vmpyub, {"v60", "v62", "v65"} },
2296  { Hexagon::BI__builtin_HEXAGON_V6_vmpyub_128B, {"v60", "v62", "v65"} },
2297  { Hexagon::BI__builtin_HEXAGON_V6_vmpyub_acc, {"v60", "v62", "v65"} },
2298  { Hexagon::BI__builtin_HEXAGON_V6_vmpyub_acc_128B, {"v60", "v62", "v65"} },
2299  { Hexagon::BI__builtin_HEXAGON_V6_vmpyubv, {"v60", "v62", "v65"} },
2300  { Hexagon::BI__builtin_HEXAGON_V6_vmpyubv_128B, {"v60", "v62", "v65"} },
2301  { Hexagon::BI__builtin_HEXAGON_V6_vmpyubv_acc, {"v60", "v62", "v65"} },
2302  { Hexagon::BI__builtin_HEXAGON_V6_vmpyubv_acc_128B, {"v60", "v62", "v65"} },
2303  { Hexagon::BI__builtin_HEXAGON_V6_vmpyuh, {"v60", "v62", "v65"} },
2304  { Hexagon::BI__builtin_HEXAGON_V6_vmpyuh_128B, {"v60", "v62", "v65"} },
2305  { Hexagon::BI__builtin_HEXAGON_V6_vmpyuh_acc, {"v60", "v62", "v65"} },
2306  { Hexagon::BI__builtin_HEXAGON_V6_vmpyuh_acc_128B, {"v60", "v62", "v65"} },
2307  { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhe, {"v65"} },
2308  { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhe_128B, {"v65"} },
2309  { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhe_acc, {"v65"} },
2310  { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhe_acc_128B, {"v65"} },
2311  { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhv, {"v60", "v62", "v65"} },
2312  { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhv_128B, {"v60", "v62", "v65"} },
2313  { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhv_acc, {"v60", "v62", "v65"} },
2314  { Hexagon::BI__builtin_HEXAGON_V6_vmpyuhv_acc_128B, {"v60", "v62", "v65"} },
2315  { Hexagon::BI__builtin_HEXAGON_V6_vmux, {"v60", "v62", "v65"} },
2316  { Hexagon::BI__builtin_HEXAGON_V6_vmux_128B, {"v60", "v62", "v65"} },
2317  { Hexagon::BI__builtin_HEXAGON_V6_vnavgb, {"v65"} },
2318  { Hexagon::BI__builtin_HEXAGON_V6_vnavgb_128B, {"v65"} },
2319  { Hexagon::BI__builtin_HEXAGON_V6_vnavgh, {"v60", "v62", "v65"} },
2320  { Hexagon::BI__builtin_HEXAGON_V6_vnavgh_128B, {"v60", "v62", "v65"} },
2321  { Hexagon::BI__builtin_HEXAGON_V6_vnavgub, {"v60", "v62", "v65"} },
2322  { Hexagon::BI__builtin_HEXAGON_V6_vnavgub_128B, {"v60", "v62", "v65"} },
2323  { Hexagon::BI__builtin_HEXAGON_V6_vnavgw, {"v60", "v62", "v65"} },
2324  { Hexagon::BI__builtin_HEXAGON_V6_vnavgw_128B, {"v60", "v62", "v65"} },
2325  { Hexagon::BI__builtin_HEXAGON_V6_vnormamth, {"v60", "v62", "v65"} },
2326  { Hexagon::BI__builtin_HEXAGON_V6_vnormamth_128B, {"v60", "v62", "v65"} },
2327  { Hexagon::BI__builtin_HEXAGON_V6_vnormamtw, {"v60", "v62", "v65"} },
2328  { Hexagon::BI__builtin_HEXAGON_V6_vnormamtw_128B, {"v60", "v62", "v65"} },
2329  { Hexagon::BI__builtin_HEXAGON_V6_vnot, {"v60", "v62", "v65"} },
2330  { Hexagon::BI__builtin_HEXAGON_V6_vnot_128B, {"v60", "v62", "v65"} },
2331  { Hexagon::BI__builtin_HEXAGON_V6_vor, {"v60", "v62", "v65"} },
2332  { Hexagon::BI__builtin_HEXAGON_V6_vor_128B, {"v60", "v62", "v65"} },
2333  { Hexagon::BI__builtin_HEXAGON_V6_vpackeb, {"v60", "v62", "v65"} },
2334  { Hexagon::BI__builtin_HEXAGON_V6_vpackeb_128B, {"v60", "v62", "v65"} },
2335  { Hexagon::BI__builtin_HEXAGON_V6_vpackeh, {"v60", "v62", "v65"} },
2336  { Hexagon::BI__builtin_HEXAGON_V6_vpackeh_128B, {"v60", "v62", "v65"} },
2337  { Hexagon::BI__builtin_HEXAGON_V6_vpackhb_sat, {"v60", "v62", "v65"} },
2338  { Hexagon::BI__builtin_HEXAGON_V6_vpackhb_sat_128B, {"v60", "v62", "v65"} },
2339  { Hexagon::BI__builtin_HEXAGON_V6_vpackhub_sat, {"v60", "v62", "v65"} },
2340  { Hexagon::BI__builtin_HEXAGON_V6_vpackhub_sat_128B, {"v60", "v62", "v65"} },
2341  { Hexagon::BI__builtin_HEXAGON_V6_vpackob, {"v60", "v62", "v65"} },
2342  { Hexagon::BI__builtin_HEXAGON_V6_vpackob_128B, {"v60", "v62", "v65"} },
2343  { Hexagon::BI__builtin_HEXAGON_V6_vpackoh, {"v60", "v62", "v65"} },
2344  { Hexagon::BI__builtin_HEXAGON_V6_vpackoh_128B, {"v60", "v62", "v65"} },
2345  { Hexagon::BI__builtin_HEXAGON_V6_vpackwh_sat, {"v60", "v62", "v65"} },
2346  { Hexagon::BI__builtin_HEXAGON_V6_vpackwh_sat_128B, {"v60", "v62", "v65"} },
2347  { Hexagon::BI__builtin_HEXAGON_V6_vpackwuh_sat, {"v60", "v62", "v65"} },
2348  { Hexagon::BI__builtin_HEXAGON_V6_vpackwuh_sat_128B, {"v60", "v62", "v65"} },
2349  { Hexagon::BI__builtin_HEXAGON_V6_vpopcounth, {"v60", "v62", "v65"} },
2350  { Hexagon::BI__builtin_HEXAGON_V6_vpopcounth_128B, {"v60", "v62", "v65"} },
2351  { Hexagon::BI__builtin_HEXAGON_V6_vprefixqb, {"v65"} },
2352  { Hexagon::BI__builtin_HEXAGON_V6_vprefixqb_128B, {"v65"} },
2353  { Hexagon::BI__builtin_HEXAGON_V6_vprefixqh, {"v65"} },
2354  { Hexagon::BI__builtin_HEXAGON_V6_vprefixqh_128B, {"v65"} },
2355  { Hexagon::BI__builtin_HEXAGON_V6_vprefixqw, {"v65"} },
2356  { Hexagon::BI__builtin_HEXAGON_V6_vprefixqw_128B, {"v65"} },
2357  { Hexagon::BI__builtin_HEXAGON_V6_vrdelta, {"v60", "v62", "v65"} },
2358  { Hexagon::BI__builtin_HEXAGON_V6_vrdelta_128B, {"v60", "v62", "v65"} },
2359  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybub_rtt, {"v65"} },
2360  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybub_rtt_128B, {"v65"} },
2361  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybub_rtt_acc, {"v65"} },
2362  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybub_rtt_acc_128B, {"v65"} },
2363  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybus, {"v60", "v62", "v65"} },
2364  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybus_128B, {"v60", "v62", "v65"} },
2365  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybus_acc, {"v60", "v62", "v65"} },
2366  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybus_acc_128B, {"v60", "v62", "v65"} },
2367  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi, {"v60", "v62", "v65"} },
2368  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_128B, {"v60", "v62", "v65"} },
2369  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_acc, {"v60", "v62", "v65"} },
2370  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_acc_128B, {"v60", "v62", "v65"} },
2371  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusv, {"v60", "v62", "v65"} },
2372  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusv_128B, {"v60", "v62", "v65"} },
2373  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusv_acc, {"v60", "v62", "v65"} },
2374  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusv_acc_128B, {"v60", "v62", "v65"} },
2375  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybv, {"v60", "v62", "v65"} },
2376  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybv_128B, {"v60", "v62", "v65"} },
2377  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybv_acc, {"v60", "v62", "v65"} },
2378  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybv_acc_128B, {"v60", "v62", "v65"} },
2379  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub, {"v60", "v62", "v65"} },
2380  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub_128B, {"v60", "v62", "v65"} },
2381  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub_acc, {"v60", "v62", "v65"} },
2382  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub_acc_128B, {"v60", "v62", "v65"} },
2383  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi, {"v60", "v62", "v65"} },
2384  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_128B, {"v60", "v62", "v65"} },
2385  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_acc, {"v60", "v62", "v65"} },
2386  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_acc_128B, {"v60", "v62", "v65"} },
2387  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub_rtt, {"v65"} },
2388  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub_rtt_128B, {"v65"} },
2389  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub_rtt_acc, {"v65"} },
2390  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyub_rtt_acc_128B, {"v65"} },
2391  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubv, {"v60", "v62", "v65"} },
2392  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubv_128B, {"v60", "v62", "v65"} },
2393  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubv_acc, {"v60", "v62", "v65"} },
2394  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubv_acc_128B, {"v60", "v62", "v65"} },
2395  { Hexagon::BI__builtin_HEXAGON_V6_vror, {"v60", "v62", "v65"} },
2396  { Hexagon::BI__builtin_HEXAGON_V6_vror_128B, {"v60", "v62", "v65"} },
2397  { Hexagon::BI__builtin_HEXAGON_V6_vroundhb, {"v60", "v62", "v65"} },
2398  { Hexagon::BI__builtin_HEXAGON_V6_vroundhb_128B, {"v60", "v62", "v65"} },
2399  { Hexagon::BI__builtin_HEXAGON_V6_vroundhub, {"v60", "v62", "v65"} },
2400  { Hexagon::BI__builtin_HEXAGON_V6_vroundhub_128B, {"v60", "v62", "v65"} },
2401  { Hexagon::BI__builtin_HEXAGON_V6_vrounduhub, {"v62", "v65"} },
2402  { Hexagon::BI__builtin_HEXAGON_V6_vrounduhub_128B, {"v62", "v65"} },
2403  { Hexagon::BI__builtin_HEXAGON_V6_vrounduwuh, {"v62", "v65"} },
2404  { Hexagon::BI__builtin_HEXAGON_V6_vrounduwuh_128B, {"v62", "v65"} },
2405  { Hexagon::BI__builtin_HEXAGON_V6_vroundwh, {"v60", "v62", "v65"} },
2406  { Hexagon::BI__builtin_HEXAGON_V6_vroundwh_128B, {"v60", "v62", "v65"} },
2407  { Hexagon::BI__builtin_HEXAGON_V6_vroundwuh, {"v60", "v62", "v65"} },
2408  { Hexagon::BI__builtin_HEXAGON_V6_vroundwuh_128B, {"v60", "v62", "v65"} },
2409  { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi, {"v60", "v62", "v65"} },
2410  { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_128B, {"v60", "v62", "v65"} },
2411  { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_acc, {"v60", "v62", "v65"} },
2412  { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_acc_128B, {"v60", "v62", "v65"} },
2413  { Hexagon::BI__builtin_HEXAGON_V6_vsathub, {"v60", "v62", "v65"} },
2414  { Hexagon::BI__builtin_HEXAGON_V6_vsathub_128B, {"v60", "v62", "v65"} },
2415  { Hexagon::BI__builtin_HEXAGON_V6_vsatuwuh, {"v62", "v65"} },
2416  { Hexagon::BI__builtin_HEXAGON_V6_vsatuwuh_128B, {"v62", "v65"} },
2417  { Hexagon::BI__builtin_HEXAGON_V6_vsatwh, {"v60", "v62", "v65"} },
2418  { Hexagon::BI__builtin_HEXAGON_V6_vsatwh_128B, {"v60", "v62", "v65"} },
2419  { Hexagon::BI__builtin_HEXAGON_V6_vsb, {"v60", "v62", "v65"} },
2420  { Hexagon::BI__builtin_HEXAGON_V6_vsb_128B, {"v60", "v62", "v65"} },
2421  { Hexagon::BI__builtin_HEXAGON_V6_vsh, {"v60", "v62", "v65"} },
2422  { Hexagon::BI__builtin_HEXAGON_V6_vsh_128B, {"v60", "v62", "v65"} },
2423  { Hexagon::BI__builtin_HEXAGON_V6_vshufeh, {"v60", "v62", "v65"} },
2424  { Hexagon::BI__builtin_HEXAGON_V6_vshufeh_128B, {"v60", "v62", "v65"} },
2425  { Hexagon::BI__builtin_HEXAGON_V6_vshuffb, {"v60", "v62", "v65"} },
2426  { Hexagon::BI__builtin_HEXAGON_V6_vshuffb_128B, {"v60", "v62", "v65"} },
2427  { Hexagon::BI__builtin_HEXAGON_V6_vshuffeb, {"v60", "v62", "v65"} },
2428  { Hexagon::BI__builtin_HEXAGON_V6_vshuffeb_128B, {"v60", "v62", "v65"} },
2429  { Hexagon::BI__builtin_HEXAGON_V6_vshuffh, {"v60", "v62", "v65"} },
2430  { Hexagon::BI__builtin_HEXAGON_V6_vshuffh_128B, {"v60", "v62", "v65"} },
2431  { Hexagon::BI__builtin_HEXAGON_V6_vshuffob, {"v60", "v62", "v65"} },
2432  { Hexagon::BI__builtin_HEXAGON_V6_vshuffob_128B, {"v60", "v62", "v65"} },
2433  { Hexagon::BI__builtin_HEXAGON_V6_vshuffvdd, {"v60", "v62", "v65"} },
2434  { Hexagon::BI__builtin_HEXAGON_V6_vshuffvdd_128B, {"v60", "v62", "v65"} },
2435  { Hexagon::BI__builtin_HEXAGON_V6_vshufoeb, {"v60", "v62", "v65"} },
2436  { Hexagon::BI__builtin_HEXAGON_V6_vshufoeb_128B, {"v60", "v62", "v65"} },
2437  { Hexagon::BI__builtin_HEXAGON_V6_vshufoeh, {"v60", "v62", "v65"} },
2438  { Hexagon::BI__builtin_HEXAGON_V6_vshufoeh_128B, {"v60", "v62", "v65"} },
2439  { Hexagon::BI__builtin_HEXAGON_V6_vshufoh, {"v60", "v62", "v65"} },
2440  { Hexagon::BI__builtin_HEXAGON_V6_vshufoh_128B, {"v60", "v62", "v65"} },
2441  { Hexagon::BI__builtin_HEXAGON_V6_vsubb, {"v60", "v62", "v65"} },
2442  { Hexagon::BI__builtin_HEXAGON_V6_vsubb_128B, {"v60", "v62", "v65"} },
2443  { Hexagon::BI__builtin_HEXAGON_V6_vsubb_dv, {"v60", "v62", "v65"} },
2444  { Hexagon::BI__builtin_HEXAGON_V6_vsubb_dv_128B, {"v60", "v62", "v65"} },
2445  { Hexagon::BI__builtin_HEXAGON_V6_vsubbsat, {"v62", "v65"} },
2446  { Hexagon::BI__builtin_HEXAGON_V6_vsubbsat_128B, {"v62", "v65"} },
2447  { Hexagon::BI__builtin_HEXAGON_V6_vsubbsat_dv, {"v62", "v65"} },
2448  { Hexagon::BI__builtin_HEXAGON_V6_vsubbsat_dv_128B, {"v62", "v65"} },
2449  { Hexagon::BI__builtin_HEXAGON_V6_vsubcarry, {"v62", "v65"} },
2450  { Hexagon::BI__builtin_HEXAGON_V6_vsubcarry_128B, {"v62", "v65"} },
2451  { Hexagon::BI__builtin_HEXAGON_V6_vsubh, {"v60", "v62", "v65"} },
2452  { Hexagon::BI__builtin_HEXAGON_V6_vsubh_128B, {"v60", "v62", "v65"} },
2453  { Hexagon::BI__builtin_HEXAGON_V6_vsubh_dv, {"v60", "v62", "v65"} },
2454  { Hexagon::BI__builtin_HEXAGON_V6_vsubh_dv_128B, {"v60", "v62", "v65"} },
2455  { Hexagon::BI__builtin_HEXAGON_V6_vsubhsat, {"v60", "v62", "v65"} },
2456  { Hexagon::BI__builtin_HEXAGON_V6_vsubhsat_128B, {"v60", "v62", "v65"} },
2457  { Hexagon::BI__builtin_HEXAGON_V6_vsubhsat_dv, {"v60", "v62", "v65"} },
2458  { Hexagon::BI__builtin_HEXAGON_V6_vsubhsat_dv_128B, {"v60", "v62", "v65"} },
2459  { Hexagon::BI__builtin_HEXAGON_V6_vsubhw, {"v60", "v62", "v65"} },
2460  { Hexagon::BI__builtin_HEXAGON_V6_vsubhw_128B, {"v60", "v62", "v65"} },
2461  { Hexagon::BI__builtin_HEXAGON_V6_vsububh, {"v60", "v62", "v65"} },
2462  { Hexagon::BI__builtin_HEXAGON_V6_vsububh_128B, {"v60", "v62", "v65"} },
2463  { Hexagon::BI__builtin_HEXAGON_V6_vsububsat, {"v60", "v62", "v65"} },
2464  { Hexagon::BI__builtin_HEXAGON_V6_vsububsat_128B, {"v60", "v62", "v65"} },
2465  { Hexagon::BI__builtin_HEXAGON_V6_vsububsat_dv, {"v60", "v62", "v65"} },
2466  { Hexagon::BI__builtin_HEXAGON_V6_vsububsat_dv_128B, {"v60", "v62", "v65"} },
2467  { Hexagon::BI__builtin_HEXAGON_V6_vsubububb_sat, {"v62", "v65"} },
2468  { Hexagon::BI__builtin_HEXAGON_V6_vsubububb_sat_128B, {"v62", "v65"} },
2469  { Hexagon::BI__builtin_HEXAGON_V6_vsubuhsat, {"v60", "v62", "v65"} },
2470  { Hexagon::BI__builtin_HEXAGON_V6_vsubuhsat_128B, {"v60", "v62", "v65"} },
2471  { Hexagon::BI__builtin_HEXAGON_V6_vsubuhsat_dv, {"v60", "v62", "v65"} },
2472  { Hexagon::BI__builtin_HEXAGON_V6_vsubuhsat_dv_128B, {"v60", "v62", "v65"} },
2473  { Hexagon::BI__builtin_HEXAGON_V6_vsubuhw, {"v60", "v62", "v65"} },
2474  { Hexagon::BI__builtin_HEXAGON_V6_vsubuhw_128B, {"v60", "v62", "v65"} },
2475  { Hexagon::BI__builtin_HEXAGON_V6_vsubuwsat, {"v62", "v65"} },
2476  { Hexagon::BI__builtin_HEXAGON_V6_vsubuwsat_128B, {"v62", "v65"} },
2477  { Hexagon::BI__builtin_HEXAGON_V6_vsubuwsat_dv, {"v62", "v65"} },
2478  { Hexagon::BI__builtin_HEXAGON_V6_vsubuwsat_dv_128B, {"v62", "v65"} },
2479  { Hexagon::BI__builtin_HEXAGON_V6_vsubw, {"v60", "v62", "v65"} },
2480  { Hexagon::BI__builtin_HEXAGON_V6_vsubw_128B, {"v60", "v62", "v65"} },
2481  { Hexagon::BI__builtin_HEXAGON_V6_vsubw_dv, {"v60", "v62", "v65"} },
2482  { Hexagon::BI__builtin_HEXAGON_V6_vsubw_dv_128B, {"v60", "v62", "v65"} },
2483  { Hexagon::BI__builtin_HEXAGON_V6_vsubwsat, {"v60", "v62", "v65"} },
2484  { Hexagon::BI__builtin_HEXAGON_V6_vsubwsat_128B, {"v60", "v62", "v65"} },
2485  { Hexagon::BI__builtin_HEXAGON_V6_vsubwsat_dv, {"v60", "v62", "v65"} },
2486  { Hexagon::BI__builtin_HEXAGON_V6_vsubwsat_dv_128B, {"v60", "v62", "v65"} },
2487  { Hexagon::BI__builtin_HEXAGON_V6_vswap, {"v60", "v62", "v65"} },
2488  { Hexagon::BI__builtin_HEXAGON_V6_vswap_128B, {"v60", "v62", "v65"} },
2489  { Hexagon::BI__builtin_HEXAGON_V6_vtmpyb, {"v60", "v62", "v65"} },
2490  { Hexagon::BI__builtin_HEXAGON_V6_vtmpyb_128B, {"v60", "v62", "v65"} },
2491  { Hexagon::BI__builtin_HEXAGON_V6_vtmpyb_acc, {"v60", "v62", "v65"} },
2492  { Hexagon::BI__builtin_HEXAGON_V6_vtmpyb_acc_128B, {"v60", "v62", "v65"} },
2493  { Hexagon::BI__builtin_HEXAGON_V6_vtmpybus, {"v60", "v62", "v65"} },
2494  { Hexagon::BI__builtin_HEXAGON_V6_vtmpybus_128B, {"v60", "v62", "v65"} },
2495  { Hexagon::BI__builtin_HEXAGON_V6_vtmpybus_acc, {"v60", "v62", "v65"} },
2496  { Hexagon::BI__builtin_HEXAGON_V6_vtmpybus_acc_128B, {"v60", "v62", "v65"} },
2497  { Hexagon::BI__builtin_HEXAGON_V6_vtmpyhb, {"v60", "v62", "v65"} },
2498  { Hexagon::BI__builtin_HEXAGON_V6_vtmpyhb_128B, {"v60", "v62", "v65"} },
2499  { Hexagon::BI__builtin_HEXAGON_V6_vtmpyhb_acc, {"v60", "v62", "v65"} },
2500  { Hexagon::BI__builtin_HEXAGON_V6_vtmpyhb_acc_128B, {"v60", "v62", "v65"} },
2501  { Hexagon::BI__builtin_HEXAGON_V6_vunpackb, {"v60", "v62", "v65"} },
2502  { Hexagon::BI__builtin_HEXAGON_V6_vunpackb_128B, {"v60", "v62", "v65"} },
2503  { Hexagon::BI__builtin_HEXAGON_V6_vunpackh, {"v60", "v62", "v65"} },
2504  { Hexagon::BI__builtin_HEXAGON_V6_vunpackh_128B, {"v60", "v62", "v65"} },
2505  { Hexagon::BI__builtin_HEXAGON_V6_vunpackob, {"v60", "v62", "v65"} },
2506  { Hexagon::BI__builtin_HEXAGON_V6_vunpackob_128B, {"v60", "v62", "v65"} },
2507  { Hexagon::BI__builtin_HEXAGON_V6_vunpackoh, {"v60", "v62", "v65"} },
2508  { Hexagon::BI__builtin_HEXAGON_V6_vunpackoh_128B, {"v60", "v62", "v65"} },
2509  { Hexagon::BI__builtin_HEXAGON_V6_vunpackub, {"v60", "v62", "v65"} },
2510  { Hexagon::BI__builtin_HEXAGON_V6_vunpackub_128B, {"v60", "v62", "v65"} },
2511  { Hexagon::BI__builtin_HEXAGON_V6_vunpackuh, {"v60", "v62", "v65"} },
2512  { Hexagon::BI__builtin_HEXAGON_V6_vunpackuh_128B, {"v60", "v62", "v65"} },
2513  { Hexagon::BI__builtin_HEXAGON_V6_vxor, {"v60", "v62", "v65"} },
2514  { Hexagon::BI__builtin_HEXAGON_V6_vxor_128B, {"v60", "v62", "v65"} },
2515  { Hexagon::BI__builtin_HEXAGON_V6_vzb, {"v60", "v62", "v65"} },
2516  { Hexagon::BI__builtin_HEXAGON_V6_vzb_128B, {"v60", "v62", "v65"} },
2517  { Hexagon::BI__builtin_HEXAGON_V6_vzh, {"v60", "v62", "v65"} },
2518  { Hexagon::BI__builtin_HEXAGON_V6_vzh_128B, {"v60", "v62", "v65"} },
2519  };
2520 
2521  const TargetInfo &TI = Context.getTargetInfo();
2522 
2523  auto FC = ValidCPU.find(BuiltinID);
2524  if (FC != ValidCPU.end()) {
2525  const TargetOptions &Opts = TI.getTargetOpts();
2526  StringRef CPU = Opts.CPU;
2527  if (!CPU.empty()) {
2528  assert(CPU.startswith("hexagon") && "Unexpected CPU name");
2529  CPU.consume_front("hexagon");
2530  if (llvm::none_of(FC->second, [CPU](StringRef S) { return S == CPU; }))
2531  return Diag(TheCall->getBeginLoc(),
2532  diag::err_hexagon_builtin_unsupported_cpu);
2533  }
2534  }
2535 
2536  auto FH = ValidHVX.find(BuiltinID);
2537  if (FH != ValidHVX.end()) {
2538  if (!TI.hasFeature("hvx"))
2539  return Diag(TheCall->getBeginLoc(),
2540  diag::err_hexagon_builtin_requires_hvx);
2541 
2542  bool IsValid = llvm::any_of(FH->second,
2543  [&TI] (StringRef V) {
2544  std::string F = "hvx" + V.str();
2545  return TI.hasFeature(F);
2546  });
2547  if (!IsValid)
2548  return Diag(TheCall->getBeginLoc(),
2549  diag::err_hexagon_builtin_unsupported_hvx);
2550  }
2551 
2552  return false;
2553 }
2554 
2555 bool Sema::CheckHexagonBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall) {
2556  struct ArgInfo {
2557  ArgInfo(unsigned O, bool S, unsigned W, unsigned A)
2558  : OpNum(O), IsSigned(S), BitWidth(W), Align(A) {}
2559  unsigned OpNum = 0;
2560  bool IsSigned = false;
2561  unsigned BitWidth = 0;
2562  unsigned Align = 0;
2563  };
2564 
2565  static const std::map<unsigned, std::vector<ArgInfo>> Infos = {
2566  { Hexagon::BI__builtin_circ_ldd, {{ 3, true, 4, 3 }} },
2567  { Hexagon::BI__builtin_circ_ldw, {{ 3, true, 4, 2 }} },
2568  { Hexagon::BI__builtin_circ_ldh, {{ 3, true, 4, 1 }} },
2569  { Hexagon::BI__builtin_circ_lduh, {{ 3, true, 4, 0 }} },
2570  { Hexagon::BI__builtin_circ_ldb, {{ 3, true, 4, 0 }} },
2571  { Hexagon::BI__builtin_circ_ldub, {{ 3, true, 4, 0 }} },
2572  { Hexagon::BI__builtin_circ_std, {{ 3, true, 4, 3 }} },
2573  { Hexagon::BI__builtin_circ_stw, {{ 3, true, 4, 2 }} },
2574  { Hexagon::BI__builtin_circ_sth, {{ 3, true, 4, 1 }} },
2575  { Hexagon::BI__builtin_circ_sthhi, {{ 3, true, 4, 1 }} },
2576  { Hexagon::BI__builtin_circ_stb, {{ 3, true, 4, 0 }} },
2577 
2578  { Hexagon::BI__builtin_HEXAGON_L2_loadrub_pci, {{ 1, true, 4, 0 }} },
2579  { Hexagon::BI__builtin_HEXAGON_L2_loadrb_pci, {{ 1, true, 4, 0 }} },
2580  { Hexagon::BI__builtin_HEXAGON_L2_loadruh_pci, {{ 1, true, 4, 1 }} },
2581  { Hexagon::BI__builtin_HEXAGON_L2_loadrh_pci, {{ 1, true, 4, 1 }} },
2582  { Hexagon::BI__builtin_HEXAGON_L2_loadri_pci, {{ 1, true, 4, 2 }} },
2583  { Hexagon::BI__builtin_HEXAGON_L2_loadrd_pci, {{ 1, true, 4, 3 }} },
2584  { Hexagon::BI__builtin_HEXAGON_S2_storerb_pci, {{ 1, true, 4, 0 }} },
2585  { Hexagon::BI__builtin_HEXAGON_S2_storerh_pci, {{ 1, true, 4, 1 }} },
2586  { Hexagon::BI__builtin_HEXAGON_S2_storerf_pci, {{ 1, true, 4, 1 }} },
2587  { Hexagon::BI__builtin_HEXAGON_S2_storeri_pci, {{ 1, true, 4, 2 }} },
2588  { Hexagon::BI__builtin_HEXAGON_S2_storerd_pci, {{ 1, true, 4, 3 }} },
2589 
2590  { Hexagon::BI__builtin_HEXAGON_A2_combineii, {{ 1, true, 8, 0 }} },
2591  { Hexagon::BI__builtin_HEXAGON_A2_tfrih, {{ 1, false, 16, 0 }} },
2592  { Hexagon::BI__builtin_HEXAGON_A2_tfril, {{ 1, false, 16, 0 }} },
2593  { Hexagon::BI__builtin_HEXAGON_A2_tfrpi, {{ 0, true, 8, 0 }} },
2594  { Hexagon::BI__builtin_HEXAGON_A4_bitspliti, {{ 1, false, 5, 0 }} },
2595  { Hexagon::BI__builtin_HEXAGON_A4_cmpbeqi, {{ 1, false, 8, 0 }} },
2596  { Hexagon::BI__builtin_HEXAGON_A4_cmpbgti, {{ 1, true, 8, 0 }} },
2597  { Hexagon::BI__builtin_HEXAGON_A4_cround_ri, {{ 1, false, 5, 0 }} },
2598  { Hexagon::BI__builtin_HEXAGON_A4_round_ri, {{ 1, false, 5, 0 }} },
2599  { Hexagon::BI__builtin_HEXAGON_A4_round_ri_sat, {{ 1, false, 5, 0 }} },
2600  { Hexagon::BI__builtin_HEXAGON_A4_vcmpbeqi, {{ 1, false, 8, 0 }} },
2601  { Hexagon::BI__builtin_HEXAGON_A4_vcmpbgti, {{ 1, true, 8, 0 }} },
2602  { Hexagon::BI__builtin_HEXAGON_A4_vcmpbgtui, {{ 1, false, 7, 0 }} },
2603  { Hexagon::BI__builtin_HEXAGON_A4_vcmpheqi, {{ 1, true, 8, 0 }} },
2604  { Hexagon::BI__builtin_HEXAGON_A4_vcmphgti, {{ 1, true, 8, 0 }} },
2605  { Hexagon::BI__builtin_HEXAGON_A4_vcmphgtui, {{ 1, false, 7, 0 }} },
2606  { Hexagon::BI__builtin_HEXAGON_A4_vcmpweqi, {{ 1, true, 8, 0 }} },
2607  { Hexagon::BI__builtin_HEXAGON_A4_vcmpwgti, {{ 1, true, 8, 0 }} },
2608  { Hexagon::BI__builtin_HEXAGON_A4_vcmpwgtui, {{ 1, false, 7, 0 }} },
2609  { Hexagon::BI__builtin_HEXAGON_C2_bitsclri, {{ 1, false, 6, 0 }} },
2610  { Hexagon::BI__builtin_HEXAGON_C2_muxii, {{ 2, true, 8, 0 }} },
2611  { Hexagon::BI__builtin_HEXAGON_C4_nbitsclri, {{ 1, false, 6, 0 }} },
2612  { Hexagon::BI__builtin_HEXAGON_F2_dfclass, {{ 1, false, 5, 0 }} },
2613  { Hexagon::BI__builtin_HEXAGON_F2_dfimm_n, {{ 0, false, 10, 0 }} },
2614  { Hexagon::BI__builtin_HEXAGON_F2_dfimm_p, {{ 0, false, 10, 0 }} },
2615  { Hexagon::BI__builtin_HEXAGON_F2_sfclass, {{ 1, false, 5, 0 }} },
2616  { Hexagon::BI__builtin_HEXAGON_F2_sfimm_n, {{ 0, false, 10, 0 }} },
2617  { Hexagon::BI__builtin_HEXAGON_F2_sfimm_p, {{ 0, false, 10, 0 }} },
2618  { Hexagon::BI__builtin_HEXAGON_M4_mpyri_addi, {{ 2, false, 6, 0 }} },
2619  { Hexagon::BI__builtin_HEXAGON_M4_mpyri_addr_u2, {{ 1, false, 6, 2 }} },
2620  { Hexagon::BI__builtin_HEXAGON_S2_addasl_rrri, {{ 2, false, 3, 0 }} },
2621  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_acc, {{ 2, false, 6, 0 }} },
2622  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_and, {{ 2, false, 6, 0 }} },
2623  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p, {{ 1, false, 6, 0 }} },
2624  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_nac, {{ 2, false, 6, 0 }} },
2625  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_or, {{ 2, false, 6, 0 }} },
2626  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_xacc, {{ 2, false, 6, 0 }} },
2627  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_acc, {{ 2, false, 5, 0 }} },
2628  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_and, {{ 2, false, 5, 0 }} },
2629  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r, {{ 1, false, 5, 0 }} },
2630  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_nac, {{ 2, false, 5, 0 }} },
2631  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_or, {{ 2, false, 5, 0 }} },
2632  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_sat, {{ 1, false, 5, 0 }} },
2633  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_xacc, {{ 2, false, 5, 0 }} },
2634  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_vh, {{ 1, false, 4, 0 }} },
2635  { Hexagon::BI__builtin_HEXAGON_S2_asl_i_vw, {{ 1, false, 5, 0 }} },
2636  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_acc, {{ 2, false, 6, 0 }} },
2637  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_and, {{ 2, false, 6, 0 }} },
2638  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p, {{ 1, false, 6, 0 }} },
2639  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_nac, {{ 2, false, 6, 0 }} },
2640  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_or, {{ 2, false, 6, 0 }} },
2641  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_rnd_goodsyntax,
2642  {{ 1, false, 6, 0 }} },
2643  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_rnd, {{ 1, false, 6, 0 }} },
2644  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_acc, {{ 2, false, 5, 0 }} },
2645  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_and, {{ 2, false, 5, 0 }} },
2646  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r, {{ 1, false, 5, 0 }} },
2647  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_nac, {{ 2, false, 5, 0 }} },
2648  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_or, {{ 2, false, 5, 0 }} },
2649  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_rnd_goodsyntax,
2650  {{ 1, false, 5, 0 }} },
2651  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_rnd, {{ 1, false, 5, 0 }} },
2652  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_svw_trun, {{ 1, false, 5, 0 }} },
2653  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_vh, {{ 1, false, 4, 0 }} },
2654  { Hexagon::BI__builtin_HEXAGON_S2_asr_i_vw, {{ 1, false, 5, 0 }} },
2655  { Hexagon::BI__builtin_HEXAGON_S2_clrbit_i, {{ 1, false, 5, 0 }} },
2656  { Hexagon::BI__builtin_HEXAGON_S2_extractu, {{ 1, false, 5, 0 },
2657  { 2, false, 5, 0 }} },
2658  { Hexagon::BI__builtin_HEXAGON_S2_extractup, {{ 1, false, 6, 0 },
2659  { 2, false, 6, 0 }} },
2660  { Hexagon::BI__builtin_HEXAGON_S2_insert, {{ 2, false, 5, 0 },
2661  { 3, false, 5, 0 }} },
2662  { Hexagon::BI__builtin_HEXAGON_S2_insertp, {{ 2, false, 6, 0 },
2663  { 3, false, 6, 0 }} },
2664  { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_acc, {{ 2, false, 6, 0 }} },
2665  { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_and, {{ 2, false, 6, 0 }} },
2666  { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p, {{ 1, false, 6, 0 }} },
2667  { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_nac, {{ 2, false, 6, 0 }} },
2668  { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_or, {{ 2, false, 6, 0 }} },
2669  { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_xacc, {{ 2, false, 6, 0 }} },
2670  { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_acc, {{ 2, false, 5, 0 }} },
2671  { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_and, {{ 2, false, 5, 0 }} },
2672  { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r, {{ 1, false, 5, 0 }} },
2673  { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_nac, {{ 2, false, 5, 0 }} },
2674  { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_or, {{ 2, false, 5, 0 }} },
2675  { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_xacc, {{ 2, false, 5, 0 }} },
2676  { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_vh, {{ 1, false, 4, 0 }} },
2677  { Hexagon::BI__builtin_HEXAGON_S2_lsr_i_vw, {{ 1, false, 5, 0 }} },
2678  { Hexagon::BI__builtin_HEXAGON_S2_setbit_i, {{ 1, false, 5, 0 }} },
2679  { Hexagon::BI__builtin_HEXAGON_S2_tableidxb_goodsyntax,
2680  {{ 2, false, 4, 0 },
2681  { 3, false, 5, 0 }} },
2682  { Hexagon::BI__builtin_HEXAGON_S2_tableidxd_goodsyntax,
2683  {{ 2, false, 4, 0 },
2684  { 3, false, 5, 0 }} },
2685  { Hexagon::BI__builtin_HEXAGON_S2_tableidxh_goodsyntax,
2686  {{ 2, false, 4, 0 },
2687  { 3, false, 5, 0 }} },
2688  { Hexagon::BI__builtin_HEXAGON_S2_tableidxw_goodsyntax,
2689  {{ 2, false, 4, 0 },
2690  { 3, false, 5, 0 }} },
2691  { Hexagon::BI__builtin_HEXAGON_S2_togglebit_i, {{ 1, false, 5, 0 }} },
2692  { Hexagon::BI__builtin_HEXAGON_S2_tstbit_i, {{ 1, false, 5, 0 }} },
2693  { Hexagon::BI__builtin_HEXAGON_S2_valignib, {{ 2, false, 3, 0 }} },
2694  { Hexagon::BI__builtin_HEXAGON_S2_vspliceib, {{ 2, false, 3, 0 }} },
2695  { Hexagon::BI__builtin_HEXAGON_S4_addi_asl_ri, {{ 2, false, 5, 0 }} },
2696  { Hexagon::BI__builtin_HEXAGON_S4_addi_lsr_ri, {{ 2, false, 5, 0 }} },
2697  { Hexagon::BI__builtin_HEXAGON_S4_andi_asl_ri, {{ 2, false, 5, 0 }} },
2698  { Hexagon::BI__builtin_HEXAGON_S4_andi_lsr_ri, {{ 2, false, 5, 0 }} },
2699  { Hexagon::BI__builtin_HEXAGON_S4_clbaddi, {{ 1, true , 6, 0 }} },
2700  { Hexagon::BI__builtin_HEXAGON_S4_clbpaddi, {{ 1, true, 6, 0 }} },
2701  { Hexagon::BI__builtin_HEXAGON_S4_extract, {{ 1, false, 5, 0 },
2702  { 2, false, 5, 0 }} },
2703  { Hexagon::BI__builtin_HEXAGON_S4_extractp, {{ 1, false, 6, 0 },
2704  { 2, false, 6, 0 }} },
2705  { Hexagon::BI__builtin_HEXAGON_S4_lsli, {{ 0, true, 6, 0 }} },
2706  { Hexagon::BI__builtin_HEXAGON_S4_ntstbit_i, {{ 1, false, 5, 0 }} },
2707  { Hexagon::BI__builtin_HEXAGON_S4_ori_asl_ri, {{ 2, false, 5, 0 }} },
2708  { Hexagon::BI__builtin_HEXAGON_S4_ori_lsr_ri, {{ 2, false, 5, 0 }} },
2709  { Hexagon::BI__builtin_HEXAGON_S4_subi_asl_ri, {{ 2, false, 5, 0 }} },
2710  { Hexagon::BI__builtin_HEXAGON_S4_subi_lsr_ri, {{ 2, false, 5, 0 }} },
2711  { Hexagon::BI__builtin_HEXAGON_S4_vrcrotate_acc, {{ 3, false, 2, 0 }} },
2712  { Hexagon::BI__builtin_HEXAGON_S4_vrcrotate, {{ 2, false, 2, 0 }} },
2713  { Hexagon::BI__builtin_HEXAGON_S5_asrhub_rnd_sat_goodsyntax,
2714  {{ 1, false, 4, 0 }} },
2715  { Hexagon::BI__builtin_HEXAGON_S5_asrhub_sat, {{ 1, false, 4, 0 }} },
2716  { Hexagon::BI__builtin_HEXAGON_S5_vasrhrnd_goodsyntax,
2717  {{ 1, false, 4, 0 }} },
2718  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p, {{ 1, false, 6, 0 }} },
2719  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_acc, {{ 2, false, 6, 0 }} },
2720  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_and, {{ 2, false, 6, 0 }} },
2721  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_nac, {{ 2, false, 6, 0 }} },
2722  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_or, {{ 2, false, 6, 0 }} },
2723  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_p_xacc, {{ 2, false, 6, 0 }} },
2724  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r, {{ 1, false, 5, 0 }} },
2725  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_acc, {{ 2, false, 5, 0 }} },
2726  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_and, {{ 2, false, 5, 0 }} },
2727  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_nac, {{ 2, false, 5, 0 }} },
2728  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_or, {{ 2, false, 5, 0 }} },
2729  { Hexagon::BI__builtin_HEXAGON_S6_rol_i_r_xacc, {{ 2, false, 5, 0 }} },
2730  { Hexagon::BI__builtin_HEXAGON_V6_valignbi, {{ 2, false, 3, 0 }} },
2731  { Hexagon::BI__builtin_HEXAGON_V6_valignbi_128B, {{ 2, false, 3, 0 }} },
2732  { Hexagon::BI__builtin_HEXAGON_V6_vlalignbi, {{ 2, false, 3, 0 }} },
2733  { Hexagon::BI__builtin_HEXAGON_V6_vlalignbi_128B, {{ 2, false, 3, 0 }} },
2734  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi, {{ 2, false, 1, 0 }} },
2735  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_128B, {{ 2, false, 1, 0 }} },
2736  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_acc, {{ 3, false, 1, 0 }} },
2737  { Hexagon::BI__builtin_HEXAGON_V6_vrmpybusi_acc_128B,
2738  {{ 3, false, 1, 0 }} },
2739  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi, {{ 2, false, 1, 0 }} },
2740  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_128B, {{ 2, false, 1, 0 }} },
2741  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_acc, {{ 3, false, 1, 0 }} },
2742  { Hexagon::BI__builtin_HEXAGON_V6_vrmpyubi_acc_128B,
2743  {{ 3, false, 1, 0 }} },
2744  { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi, {{ 2, false, 1, 0 }} },
2745  { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_128B, {{ 2, false, 1, 0 }} },
2746  { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_acc, {{ 3, false, 1, 0 }} },
2747  { Hexagon::BI__builtin_HEXAGON_V6_vrsadubi_acc_128B,
2748  {{ 3, false, 1, 0 }} },
2749  };
2750 
2751  auto F = Infos.find(BuiltinID);
2752  if (F == Infos.end())
2753  return false;
2754 
2755  bool Error = false;
2756 
2757  for (const ArgInfo &A : F->second) {
2758  int32_t Min = A.IsSigned ? -(1 << (A.BitWidth-1)) : 0;
2759  int32_t Max = (1 << (A.IsSigned ? A.BitWidth-1 : A.BitWidth)) - 1;
2760  if (!A.Align) {
2761  Error |= SemaBuiltinConstantArgRange(TheCall, A.OpNum, Min, Max);
2762  } else {
2763  unsigned M = 1 << A.Align;
2764  Min *= M;
2765  Max *= M;
2766  Error |= SemaBuiltinConstantArgRange(TheCall, A.OpNum, Min, Max) |
2767  SemaBuiltinConstantArgMultiple(TheCall, A.OpNum, M);
2768  }
2769  }
2770  return Error;
2771 }
2772 
2773 bool Sema::CheckHexagonBuiltinFunctionCall(unsigned BuiltinID,
2774  CallExpr *TheCall) {
2775  return CheckHexagonBuiltinCpu(BuiltinID, TheCall) ||
2776  CheckHexagonBuiltinArgument(BuiltinID, TheCall);
2777 }
2778 
2779 
2780 // CheckMipsBuiltinFunctionCall - Checks the constant value passed to the
2781 // intrinsic is correct. The switch statement is ordered by DSP, MSA. The
2782 // ordering for DSP is unspecified. MSA is ordered by the data format used
2783 // by the underlying instruction i.e., df/m, df/n and then by size.
2784 //
2785 // FIXME: The size tests here should instead be tablegen'd along with the
2786 // definitions from include/clang/Basic/BuiltinsMips.def.
2787 // FIXME: GCC is strict on signedness for some of these intrinsics, we should
2788 // be too.
2789 bool Sema::CheckMipsBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
2790  unsigned i = 0, l = 0, u = 0, m = 0;
2791  switch (BuiltinID) {
2792  default: return false;
2793  case Mips::BI__builtin_mips_wrdsp: i = 1; l = 0; u = 63; break;
2794  case Mips::BI__builtin_mips_rddsp: i = 0; l = 0; u = 63; break;
2795  case Mips::BI__builtin_mips_append: i = 2; l = 0; u = 31; break;
2796  case Mips::BI__builtin_mips_balign: i = 2; l = 0; u = 3; break;
2797  case Mips::BI__builtin_mips_precr_sra_ph_w: i = 2; l = 0; u = 31; break;
2798  case Mips::BI__builtin_mips_precr_sra_r_ph_w: i = 2; l = 0; u = 31; break;
2799  case Mips::BI__builtin_mips_prepend: i = 2; l = 0; u = 31; break;
2800  // MSA instrinsics. Instructions (which the intrinsics maps to) which use the
2801  // df/m field.
2802  // These intrinsics take an unsigned 3 bit immediate.
2803  case Mips::BI__builtin_msa_bclri_b:
2804  case Mips::BI__builtin_msa_bnegi_b:
2805  case Mips::BI__builtin_msa_bseti_b:
2806  case Mips::BI__builtin_msa_sat_s_b:
2807  case Mips::BI__builtin_msa_sat_u_b:
2808  case Mips::BI__builtin_msa_slli_b:
2809  case Mips::BI__builtin_msa_srai_b:
2810  case Mips::BI__builtin_msa_srari_b:
2811  case Mips::BI__builtin_msa_srli_b:
2812  case Mips::BI__builtin_msa_srlri_b: i = 1; l = 0; u = 7; break;
2813  case Mips::BI__builtin_msa_binsli_b:
2814  case Mips::BI__builtin_msa_binsri_b: i = 2; l = 0; u = 7; break;
2815  // These intrinsics take an unsigned 4 bit immediate.
2816  case Mips::BI__builtin_msa_bclri_h:
2817  case Mips::BI__builtin_msa_bnegi_h:
2818  case Mips::BI__builtin_msa_bseti_h:
2819  case Mips::BI__builtin_msa_sat_s_h:
2820  case Mips::BI__builtin_msa_sat_u_h:
2821  case Mips::BI__builtin_msa_slli_h:
2822  case Mips::BI__builtin_msa_srai_h:
2823  case Mips::BI__builtin_msa_srari_h:
2824  case Mips::BI__builtin_msa_srli_h:
2825  case Mips::BI__builtin_msa_srlri_h: i = 1; l = 0; u = 15; break;
2826  case Mips::BI__builtin_msa_binsli_h:
2827  case Mips::BI__builtin_msa_binsri_h: i = 2; l = 0; u = 15; break;
2828  // These intrinsics take an unsigned 5 bit immediate.
2829  // The first block of intrinsics actually have an unsigned 5 bit field,
2830  // not a df/n field.
2831  case Mips::BI__builtin_msa_clei_u_b:
2832  case Mips::BI__builtin_msa_clei_u_h:
2833  case Mips::BI__builtin_msa_clei_u_w:
2834  case Mips::BI__builtin_msa_clei_u_d:
2835  case Mips::BI__builtin_msa_clti_u_b:
2836  case Mips::BI__builtin_msa_clti_u_h:
2837  case Mips::BI__builtin_msa_clti_u_w:
2838  case Mips::BI__builtin_msa_clti_u_d:
2839  case Mips::BI__builtin_msa_maxi_u_b:
2840  case Mips::BI__builtin_msa_maxi_u_h:
2841  case Mips::BI__builtin_msa_maxi_u_w:
2842  case Mips::BI__builtin_msa_maxi_u_d:
2843  case Mips::BI__builtin_msa_mini_u_b:
2844  case Mips::BI__builtin_msa_mini_u_h:
2845  case Mips::BI__builtin_msa_mini_u_w:
2846  case Mips::BI__builtin_msa_mini_u_d:
2847  case Mips::BI__builtin_msa_addvi_b:
2848  case Mips::BI__builtin_msa_addvi_h:
2849  case Mips::BI__builtin_msa_addvi_w:
2850  case Mips::BI__builtin_msa_addvi_d:
2851  case Mips::BI__builtin_msa_bclri_w:
2852  case Mips::BI__builtin_msa_bnegi_w:
2853  case Mips::BI__builtin_msa_bseti_w:
2854  case Mips::BI__builtin_msa_sat_s_w:
2855  case Mips::BI__builtin_msa_sat_u_w:
2856  case Mips::BI__builtin_msa_slli_w:
2857  case Mips::BI__builtin_msa_srai_w:
2858  case Mips::BI__builtin_msa_srari_w:
2859  case Mips::BI__builtin_msa_srli_w:
2860  case Mips::BI__builtin_msa_srlri_w:
2861  case Mips::BI__builtin_msa_subvi_b:
2862  case Mips::BI__builtin_msa_subvi_h:
2863  case Mips::BI__builtin_msa_subvi_w:
2864  case Mips::BI__builtin_msa_subvi_d: i = 1; l = 0; u = 31; break;
2865  case Mips::BI__builtin_msa_binsli_w:
2866  case Mips::BI__builtin_msa_binsri_w: i = 2; l = 0; u = 31; break;
2867  // These intrinsics take an unsigned 6 bit immediate.
2868  case Mips::BI__builtin_msa_bclri_d:
2869  case Mips::BI__builtin_msa_bnegi_d:
2870  case Mips::BI__builtin_msa_bseti_d:
2871  case Mips::BI__builtin_msa_sat_s_d:
2872  case Mips::BI__builtin_msa_sat_u_d:
2873  case Mips::BI__builtin_msa_slli_d:
2874  case Mips::BI__builtin_msa_srai_d:
2875  case Mips::BI__builtin_msa_srari_d:
2876  case Mips::BI__builtin_msa_srli_d:
2877  case Mips::BI__builtin_msa_srlri_d: i = 1; l = 0; u = 63; break;
2878  case Mips::BI__builtin_msa_binsli_d:
2879  case Mips::BI__builtin_msa_binsri_d: i = 2; l = 0; u = 63; break;
2880  // These intrinsics take a signed 5 bit immediate.
2881  case Mips::BI__builtin_msa_ceqi_b:
2882  case Mips::BI__builtin_msa_ceqi_h:
2883  case Mips::BI__builtin_msa_ceqi_w:
2884  case Mips::BI__builtin_msa_ceqi_d:
2885  case Mips::BI__builtin_msa_clti_s_b:
2886  case Mips::BI__builtin_msa_clti_s_h:
2887  case Mips::BI__builtin_msa_clti_s_w:
2888  case Mips::BI__builtin_msa_clti_s_d:
2889  case Mips::BI__builtin_msa_clei_s_b:
2890  case Mips::BI__builtin_msa_clei_s_h:
2891  case Mips::BI__builtin_msa_clei_s_w:
2892  case Mips::BI__builtin_msa_clei_s_d:
2893  case Mips::BI__builtin_msa_maxi_s_b:
2894  case Mips::BI__builtin_msa_maxi_s_h:
2895  case Mips::BI__builtin_msa_maxi_s_w:
2896  case Mips::BI__builtin_msa_maxi_s_d:
2897  case Mips::BI__builtin_msa_mini_s_b:
2898  case Mips::BI__builtin_msa_mini_s_h:
2899  case Mips::BI__builtin_msa_mini_s_w:
2900  case Mips::BI__builtin_msa_mini_s_d: i = 1; l = -16; u = 15; break;
2901  // These intrinsics take an unsigned 8 bit immediate.
2902  case Mips::BI__builtin_msa_andi_b:
2903  case Mips::BI__builtin_msa_nori_b:
2904  case Mips::BI__builtin_msa_ori_b:
2905  case Mips::BI__builtin_msa_shf_b:
2906  case Mips::BI__builtin_msa_shf_h:
2907  case Mips::BI__builtin_msa_shf_w:
2908  case Mips::BI__builtin_msa_xori_b: i = 1; l = 0; u = 255; break;
2909  case Mips::BI__builtin_msa_bseli_b:
2910  case Mips::BI__builtin_msa_bmnzi_b:
2911  case Mips::BI__builtin_msa_bmzi_b: i = 2; l = 0; u = 255; break;
2912  // df/n format
2913  // These intrinsics take an unsigned 4 bit immediate.
2914  case Mips::BI__builtin_msa_copy_s_b:
2915  case Mips::BI__builtin_msa_copy_u_b:
2916  case Mips::BI__builtin_msa_insve_b:
2917  case Mips::BI__builtin_msa_splati_b: i = 1; l = 0; u = 15; break;
2918  case Mips::BI__builtin_msa_sldi_b: i = 2; l = 0; u = 15; break;
2919  // These intrinsics take an unsigned 3 bit immediate.
2920  case Mips::BI__builtin_msa_copy_s_h:
2921  case Mips::BI__builtin_msa_copy_u_h:
2922  case Mips::BI__builtin_msa_insve_h:
2923  case Mips::BI__builtin_msa_splati_h: i = 1; l = 0; u = 7; break;
2924  case Mips::BI__builtin_msa_sldi_h: i = 2; l = 0; u = 7; break;
2925  // These intrinsics take an unsigned 2 bit immediate.
2926  case Mips::BI__builtin_msa_copy_s_w:
2927  case Mips::BI__builtin_msa_copy_u_w:
2928  case Mips::BI__builtin_msa_insve_w:
2929  case Mips::BI__builtin_msa_splati_w: i = 1; l = 0; u = 3; break;
2930  case Mips::BI__builtin_msa_sldi_w: i = 2; l = 0; u = 3; break;
2931  // These intrinsics take an unsigned 1 bit immediate.
2932  case Mips::BI__builtin_msa_copy_s_d:
2933  case Mips::BI__builtin_msa_copy_u_d:
2934  case Mips::BI__builtin_msa_insve_d:
2935  case Mips::BI__builtin_msa_splati_d: i = 1; l = 0; u = 1; break;
2936  case Mips::BI__builtin_msa_sldi_d: i = 2; l = 0; u = 1; break;
2937  // Memory offsets and immediate loads.
2938  // These intrinsics take a signed 10 bit immediate.
2939  case Mips::BI__builtin_msa_ldi_b: i = 0; l = -128; u = 255; break;
2940  case Mips::BI__builtin_msa_ldi_h:
2941  case Mips::BI__builtin_msa_ldi_w:
2942  case Mips::BI__builtin_msa_ldi_d: i = 0; l = -512; u = 511; break;
2943  case Mips::BI__builtin_msa_ld_b: i = 1; l = -512; u = 511; m = 16; break;
2944  case Mips::BI__builtin_msa_ld_h: i = 1; l = -1024; u = 1022; m = 16; break;
2945  case Mips::BI__builtin_msa_ld_w: i = 1; l = -2048; u = 2044; m = 16; break;
2946  case Mips::BI__builtin_msa_ld_d: i = 1; l = -4096; u = 4088; m = 16; break;
2947  case Mips::BI__builtin_msa_st_b: i = 2; l = -512; u = 511; m = 16; break;
2948  case Mips::BI__builtin_msa_st_h: i = 2; l = -1024; u = 1022; m = 16; break;
2949  case Mips::BI__builtin_msa_st_w: i = 2; l = -2048; u = 2044; m = 16; break;
2950  case Mips::BI__builtin_msa_st_d: i = 2; l = -4096; u = 4088; m = 16; break;
2951  }
2952 
2953  if (!m)
2954  return SemaBuiltinConstantArgRange(TheCall, i, l, u);
2955 
2956  return SemaBuiltinConstantArgRange(TheCall, i, l, u) ||
2957  SemaBuiltinConstantArgMultiple(TheCall, i, m);
2958 }
2959 
2960 bool Sema::CheckPPCBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
2961  unsigned i = 0, l = 0, u = 0;
2962  bool Is64BitBltin = BuiltinID == PPC::BI__builtin_divde ||
2963  BuiltinID == PPC::BI__builtin_divdeu ||
2964  BuiltinID == PPC::BI__builtin_bpermd;
2965  bool IsTarget64Bit = Context.getTargetInfo()
2966  .getTypeWidth(Context
2967  .getTargetInfo()
2968  .getIntPtrType()) == 64;
2969  bool IsBltinExtDiv = BuiltinID == PPC::BI__builtin_divwe ||
2970  BuiltinID == PPC::BI__builtin_divweu ||
2971  BuiltinID == PPC::BI__builtin_divde ||
2972  BuiltinID == PPC::BI__builtin_divdeu;
2973 
2974  if (Is64BitBltin && !IsTarget64Bit)
2975  return Diag(TheCall->getBeginLoc(), diag::err_64_bit_builtin_32_bit_tgt)
2976  << TheCall->getSourceRange();
2977 
2978  if ((IsBltinExtDiv && !Context.getTargetInfo().hasFeature("extdiv")) ||
2979  (BuiltinID == PPC::BI__builtin_bpermd &&
2980  !Context.getTargetInfo().hasFeature("bpermd")))
2981  return Diag(TheCall->getBeginLoc(), diag::err_ppc_builtin_only_on_pwr7)
2982  << TheCall->getSourceRange();
2983 
2984  auto SemaVSXCheck = [&](CallExpr *TheCall) -> bool {
2985  if (!Context.getTargetInfo().hasFeature("vsx"))
2986  return Diag(TheCall->getBeginLoc(), diag::err_ppc_builtin_only_on_pwr7)
2987  << TheCall->getSourceRange();
2988  return false;
2989  };
2990 
2991  switch (BuiltinID) {
2992  default: return false;
2993  case PPC::BI__builtin_altivec_crypto_vshasigmaw:
2994  case PPC::BI__builtin_altivec_crypto_vshasigmad:
2995  return SemaBuiltinConstantArgRange(TheCall, 1, 0, 1) ||
2996  SemaBuiltinConstantArgRange(TheCall, 2, 0, 15);
2997  case PPC::BI__builtin_tbegin:
2998  case PPC::BI__builtin_tend: i = 0; l = 0; u = 1; break;
2999  case PPC::BI__builtin_tsr: i = 0; l = 0; u = 7; break;
3000  case PPC::BI__builtin_tabortwc:
3001  case PPC::BI__builtin_tabortdc: i = 0; l = 0; u = 31; break;
3002  case PPC::BI__builtin_tabortwci:
3003  case PPC::BI__builtin_tabortdci:
3004  return SemaBuiltinConstantArgRange(TheCall, 0, 0, 31) ||
3005  SemaBuiltinConstantArgRange(TheCall, 2, 0, 31);
3006  case PPC::BI__builtin_vsx_xxpermdi:
3007  case PPC::BI__builtin_vsx_xxsldwi:
3008  return SemaBuiltinVSX(TheCall);
3009  case PPC::BI__builtin_unpack_vector_int128:
3010  return SemaVSXCheck(TheCall) ||
3011  SemaBuiltinConstantArgRange(TheCall, 1, 0, 1);
3012  case PPC::BI__builtin_pack_vector_int128:
3013  return SemaVSXCheck(TheCall);
3014  }
3015  return SemaBuiltinConstantArgRange(TheCall, i, l, u);
3016 }
3017 
3018 bool Sema::CheckSystemZBuiltinFunctionCall(unsigned BuiltinID,
3019  CallExpr *TheCall) {
3020  if (BuiltinID == SystemZ::BI__builtin_tabort) {
3021  Expr *Arg = TheCall->getArg(0);
3022  llvm::APSInt AbortCode(32);
3023  if (Arg->isIntegerConstantExpr(AbortCode, Context) &&
3024  AbortCode.getSExtValue() >= 0 && AbortCode.getSExtValue() < 256)
3025  return Diag(Arg->getBeginLoc(), diag::err_systemz_invalid_tabort_code)
3026  << Arg->getSourceRange();
3027  }
3028 
3029  // For intrinsics which take an immediate value as part of the instruction,
3030  // range check them here.
3031  unsigned i = 0, l = 0, u = 0;
3032  switch (BuiltinID) {
3033  default: return false;
3034  case SystemZ::BI__builtin_s390_lcbb: i = 1; l = 0; u = 15; break;
3035  case SystemZ::BI__builtin_s390_verimb:
3036  case SystemZ::BI__builtin_s390_verimh:
3037  case SystemZ::BI__builtin_s390_verimf:
3038  case SystemZ::BI__builtin_s390_verimg: i = 3; l = 0; u = 255; break;
3039  case SystemZ::BI__builtin_s390_vfaeb:
3040  case SystemZ::BI__builtin_s390_vfaeh:
3041  case SystemZ::BI__builtin_s390_vfaef:
3042  case SystemZ::BI__builtin_s390_vfaebs:
3043  case SystemZ::BI__builtin_s390_vfaehs:
3044  case SystemZ::BI__builtin_s390_vfaefs:
3045  case SystemZ::BI__builtin_s390_vfaezb:
3046  case SystemZ::BI__builtin_s390_vfaezh:
3047  case SystemZ::BI__builtin_s390_vfaezf:
3048  case SystemZ::BI__builtin_s390_vfaezbs:
3049  case SystemZ::BI__builtin_s390_vfaezhs:
3050  case SystemZ::BI__builtin_s390_vfaezfs: i = 2; l = 0; u = 15; break;
3051  case SystemZ::BI__builtin_s390_vfisb:
3052  case SystemZ::BI__builtin_s390_vfidb:
3053  return SemaBuiltinConstantArgRange(TheCall, 1, 0, 15) ||
3054  SemaBuiltinConstantArgRange(TheCall, 2, 0, 15);
3055  case SystemZ::BI__builtin_s390_vftcisb:
3056  case SystemZ::BI__builtin_s390_vftcidb: i = 1; l = 0; u = 4095; break;
3057  case SystemZ::BI__builtin_s390_vlbb: i = 1; l = 0; u = 15; break;
3058  case SystemZ::BI__builtin_s390_vpdi: i = 2; l = 0; u = 15; break;
3059  case SystemZ::BI__builtin_s390_vsldb: i = 2; l = 0; u = 15; break;
3060  case SystemZ::BI__builtin_s390_vstrcb:
3061  case SystemZ::BI__builtin_s390_vstrch:
3062  case SystemZ::BI__builtin_s390_vstrcf:
3063  case SystemZ::BI__builtin_s390_vstrczb:
3064  case SystemZ::BI__builtin_s390_vstrczh:
3065  case SystemZ::BI__builtin_s390_vstrczf:
3066  case SystemZ::BI__builtin_s390_vstrcbs:
3067  case SystemZ::BI__builtin_s390_vstrchs:
3068  case SystemZ::BI__builtin_s390_vstrcfs:
3069  case SystemZ::BI__builtin_s390_vstrczbs:
3070  case SystemZ::BI__builtin_s390_vstrczhs:
3071  case SystemZ::BI__builtin_s390_vstrczfs: i = 3; l = 0; u = 15; break;
3072  case SystemZ::BI__builtin_s390_vmslg: i = 3; l = 0; u = 15; break;
3073  case SystemZ::BI__builtin_s390_vfminsb:
3074  case SystemZ::BI__builtin_s390_vfmaxsb:
3075  case SystemZ::BI__builtin_s390_vfmindb:
3076  case SystemZ::BI__builtin_s390_vfmaxdb: i = 2; l = 0; u = 15; break;
3077  }
3078  return SemaBuiltinConstantArgRange(TheCall, i, l, u);
3079 }
3080 
3081 /// SemaBuiltinCpuSupports - Handle __builtin_cpu_supports(char *).
3082 /// This checks that the target supports __builtin_cpu_supports and
3083 /// that the string argument is constant and valid.
3084 static bool SemaBuiltinCpuSupports(Sema &S, CallExpr *TheCall) {
3085  Expr *Arg = TheCall->getArg(0);
3086 
3087  // Check if the argument is a string literal.
3088  if (!isa<StringLiteral>(Arg->IgnoreParenImpCasts()))
3089  return S.Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
3090  << Arg->getSourceRange();
3091 
3092  // Check the contents of the string.
3093  StringRef Feature =
3094  cast<StringLiteral>(Arg->IgnoreParenImpCasts())->getString();
3095  if (!S.Context.getTargetInfo().validateCpuSupports(Feature))
3096  return S.Diag(TheCall->getBeginLoc(), diag::err_invalid_cpu_supports)
3097  << Arg->getSourceRange();
3098  return false;
3099 }
3100 
3101 /// SemaBuiltinCpuIs - Handle __builtin_cpu_is(char *).
3102 /// This checks that the target supports __builtin_cpu_is and
3103 /// that the string argument is constant and valid.
3104 static bool SemaBuiltinCpuIs(Sema &S, CallExpr *TheCall) {
3105  Expr *Arg = TheCall->getArg(0);
3106 
3107  // Check if the argument is a string literal.
3108  if (!isa<StringLiteral>(Arg->IgnoreParenImpCasts()))
3109  return S.Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
3110  << Arg->getSourceRange();
3111 
3112  // Check the contents of the string.
3113  StringRef Feature =
3114  cast<StringLiteral>(Arg->IgnoreParenImpCasts())->getString();
3115  if (!S.Context.getTargetInfo().validateCpuIs(Feature))
3116  return S.Diag(TheCall->getBeginLoc(), diag::err_invalid_cpu_is)
3117  << Arg->getSourceRange();
3118  return false;
3119 }
3120 
3121 // Check if the rounding mode is legal.
3122 bool Sema::CheckX86BuiltinRoundingOrSAE(unsigned BuiltinID, CallExpr *TheCall) {
3123  // Indicates if this instruction has rounding control or just SAE.
3124  bool HasRC = false;
3125 
3126  unsigned ArgNum = 0;
3127  switch (BuiltinID) {
3128  default:
3129  return false;
3130  case X86::BI__builtin_ia32_vcvttsd2si32:
3131  case X86::BI__builtin_ia32_vcvttsd2si64:
3132  case X86::BI__builtin_ia32_vcvttsd2usi32:
3133  case X86::BI__builtin_ia32_vcvttsd2usi64:
3134  case X86::BI__builtin_ia32_vcvttss2si32:
3135  case X86::BI__builtin_ia32_vcvttss2si64:
3136  case X86::BI__builtin_ia32_vcvttss2usi32:
3137  case X86::BI__builtin_ia32_vcvttss2usi64:
3138  ArgNum = 1;
3139  break;
3140  case X86::BI__builtin_ia32_maxpd512:
3141  case X86::BI__builtin_ia32_maxps512:
3142  case X86::BI__builtin_ia32_minpd512:
3143  case X86::BI__builtin_ia32_minps512:
3144  ArgNum = 2;
3145  break;
3146  case X86::BI__builtin_ia32_cvtps2pd512_mask:
3147  case X86::BI__builtin_ia32_cvttpd2dq512_mask:
3148  case X86::BI__builtin_ia32_cvttpd2qq512_mask:
3149  case X86::BI__builtin_ia32_cvttpd2udq512_mask:
3150  case X86::BI__builtin_ia32_cvttpd2uqq512_mask:
3151  case X86::BI__builtin_ia32_cvttps2dq512_mask:
3152  case X86::BI__builtin_ia32_cvttps2qq512_mask:
3153  case X86::BI__builtin_ia32_cvttps2udq512_mask:
3154  case X86::BI__builtin_ia32_cvttps2uqq512_mask:
3155  case X86::BI__builtin_ia32_exp2pd_mask:
3156  case X86::BI__builtin_ia32_exp2ps_mask:
3157  case X86::BI__builtin_ia32_getexppd512_mask:
3158  case X86::BI__builtin_ia32_getexpps512_mask:
3159  case X86::BI__builtin_ia32_rcp28pd_mask:
3160  case X86::BI__builtin_ia32_rcp28ps_mask:
3161  case X86::BI__builtin_ia32_rsqrt28pd_mask:
3162  case X86::BI__builtin_ia32_rsqrt28ps_mask:
3163  case X86::BI__builtin_ia32_vcomisd:
3164  case X86::BI__builtin_ia32_vcomiss:
3165  case X86::BI__builtin_ia32_vcvtph2ps512_mask:
3166  ArgNum = 3;
3167  break;
3168  case X86::BI__builtin_ia32_cmppd512_mask:
3169  case X86::BI__builtin_ia32_cmpps512_mask:
3170  case X86::BI__builtin_ia32_cmpsd_mask:
3171  case X86::BI__builtin_ia32_cmpss_mask:
3172  case X86::BI__builtin_ia32_cvtss2sd_round_mask:
3173  case X86::BI__builtin_ia32_getexpsd128_round_mask:
3174  case X86::BI__builtin_ia32_getexpss128_round_mask:
3175  case X86::BI__builtin_ia32_maxsd_round_mask:
3176  case X86::BI__builtin_ia32_maxss_round_mask:
3177  case X86::BI__builtin_ia32_minsd_round_mask:
3178  case X86::BI__builtin_ia32_minss_round_mask:
3179  case X86::BI__builtin_ia32_rcp28sd_round_mask:
3180  case X86::BI__builtin_ia32_rcp28ss_round_mask:
3181  case X86::BI__builtin_ia32_reducepd512_mask:
3182  case X86::BI__builtin_ia32_reduceps512_mask:
3183  case X86::BI__builtin_ia32_rndscalepd_mask:
3184  case X86::BI__builtin_ia32_rndscaleps_mask:
3185  case X86::BI__builtin_ia32_rsqrt28sd_round_mask:
3186  case X86::BI__builtin_ia32_rsqrt28ss_round_mask:
3187  ArgNum = 4;
3188  break;
3189  case X86::BI__builtin_ia32_fixupimmpd512_mask:
3190  case X86::BI__builtin_ia32_fixupimmpd512_maskz:
3191  case X86::BI__builtin_ia32_fixupimmps512_mask:
3192  case X86::BI__builtin_ia32_fixupimmps512_maskz:
3193  case X86::BI__builtin_ia32_fixupimmsd_mask:
3194  case X86::BI__builtin_ia32_fixupimmsd_maskz:
3195  case X86::BI__builtin_ia32_fixupimmss_mask:
3196  case X86::BI__builtin_ia32_fixupimmss_maskz:
3197  case X86::BI__builtin_ia32_rangepd512_mask:
3198  case X86::BI__builtin_ia32_rangeps512_mask:
3199  case X86::BI__builtin_ia32_rangesd128_round_mask:
3200  case X86::BI__builtin_ia32_rangess128_round_mask:
3201  case X86::BI__builtin_ia32_reducesd_mask:
3202  case X86::BI__builtin_ia32_reducess_mask:
3203  case X86::BI__builtin_ia32_rndscalesd_round_mask:
3204  case X86::BI__builtin_ia32_rndscaless_round_mask:
3205  ArgNum = 5;
3206  break;
3207  case X86::BI__builtin_ia32_vcvtsd2si64:
3208  case X86::BI__builtin_ia32_vcvtsd2si32:
3209  case X86::BI__builtin_ia32_vcvtsd2usi32:
3210  case X86::BI__builtin_ia32_vcvtsd2usi64:
3211  case X86::BI__builtin_ia32_vcvtss2si32:
3212  case X86::BI__builtin_ia32_vcvtss2si64:
3213  case X86::BI__builtin_ia32_vcvtss2usi32:
3214  case X86::BI__builtin_ia32_vcvtss2usi64:
3215  case X86::BI__builtin_ia32_sqrtpd512:
3216  case X86::BI__builtin_ia32_sqrtps512:
3217  ArgNum = 1;
3218  HasRC = true;
3219  break;
3220  case X86::BI__builtin_ia32_addpd512:
3221  case X86::BI__builtin_ia32_addps512:
3222  case X86::BI__builtin_ia32_divpd512:
3223  case X86::BI__builtin_ia32_divps512:
3224  case X86::BI__builtin_ia32_mulpd512:
3225  case X86::BI__builtin_ia32_mulps512:
3226  case X86::BI__builtin_ia32_subpd512:
3227  case X86::BI__builtin_ia32_subps512:
3228  case X86::BI__builtin_ia32_cvtsi2sd64:
3229  case X86::BI__builtin_ia32_cvtsi2ss32:
3230  case X86::BI__builtin_ia32_cvtsi2ss64:
3231  case X86::BI__builtin_ia32_cvtusi2sd64:
3232  case X86::BI__builtin_ia32_cvtusi2ss32:
3233  case X86::BI__builtin_ia32_cvtusi2ss64:
3234  ArgNum = 2;
3235  HasRC = true;
3236  break;
3237  case X86::BI__builtin_ia32_cvtdq2ps512_mask:
3238  case X86::BI__builtin_ia32_cvtudq2ps512_mask:
3239  case X86::BI__builtin_ia32_cvtpd2ps512_mask:
3240  case X86::BI__builtin_ia32_cvtpd2qq512_mask:
3241  case X86::BI__builtin_ia32_cvtpd2uqq512_mask:
3242  case X86::BI__builtin_ia32_cvtps2qq512_mask:
3243  case X86::BI__builtin_ia32_cvtps2uqq512_mask:
3244  case X86::BI__builtin_ia32_cvtqq2pd512_mask:
3245  case X86::BI__builtin_ia32_cvtqq2ps512_mask:
3246  case X86::BI__builtin_ia32_cvtuqq2pd512_mask:
3247  case X86::BI__builtin_ia32_cvtuqq2ps512_mask:
3248  ArgNum = 3;
3249  HasRC = true;
3250  break;
3251  case X86::BI__builtin_ia32_addss_round_mask:
3252  case X86::BI__builtin_ia32_addsd_round_mask:
3253  case X86::BI__builtin_ia32_divss_round_mask:
3254  case X86::BI__builtin_ia32_divsd_round_mask:
3255  case X86::BI__builtin_ia32_mulss_round_mask:
3256  case X86::BI__builtin_ia32_mulsd_round_mask:
3257  case X86::BI__builtin_ia32_subss_round_mask:
3258  case X86::BI__builtin_ia32_subsd_round_mask:
3259  case X86::BI__builtin_ia32_scalefpd512_mask:
3260  case X86::BI__builtin_ia32_scalefps512_mask:
3261  case X86::BI__builtin_ia32_scalefsd_round_mask:
3262  case X86::BI__builtin_ia32_scalefss_round_mask:
3263  case X86::BI__builtin_ia32_getmantpd512_mask:
3264  case X86::BI__builtin_ia32_getmantps512_mask:
3265  case X86::BI__builtin_ia32_cvtsd2ss_round_mask:
3266  case X86::BI__builtin_ia32_sqrtsd_round_mask:
3267  case X86::BI__builtin_ia32_sqrtss_round_mask:
3268  case X86::BI__builtin_ia32_vfmaddsd3_mask:
3269  case X86::BI__builtin_ia32_vfmaddsd3_maskz:
3270  case X86::BI__builtin_ia32_vfmaddsd3_mask3:
3271  case X86::BI__builtin_ia32_vfmaddss3_mask:
3272  case X86::BI__builtin_ia32_vfmaddss3_maskz:
3273  case X86::BI__builtin_ia32_vfmaddss3_mask3:
3274  case X86::BI__builtin_ia32_vfmaddpd512_mask:
3275  case X86::BI__builtin_ia32_vfmaddpd512_maskz:
3276  case X86::BI__builtin_ia32_vfmaddpd512_mask3:
3277  case X86::BI__builtin_ia32_vfmsubpd512_mask3:
3278  case X86::BI__builtin_ia32_vfmaddps512_mask:
3279  case X86::BI__builtin_ia32_vfmaddps512_maskz:
3280  case X86::BI__builtin_ia32_vfmaddps512_mask3:
3281  case X86::BI__builtin_ia32_vfmsubps512_mask3:
3282  case X86::BI__builtin_ia32_vfmaddsubpd512_mask:
3283  case X86::BI__builtin_ia32_vfmaddsubpd512_maskz:
3284  case X86::BI__builtin_ia32_vfmaddsubpd512_mask3:
3285  case X86::BI__builtin_ia32_vfmsubaddpd512_mask3:
3286  case X86::BI__builtin_ia32_vfmaddsubps512_mask:
3287  case X86::BI__builtin_ia32_vfmaddsubps512_maskz:
3288  case X86::BI__builtin_ia32_vfmaddsubps512_mask3:
3289  case X86::BI__builtin_ia32_vfmsubaddps512_mask3:
3290  ArgNum = 4;
3291  HasRC = true;
3292  break;
3293  case X86::BI__builtin_ia32_getmantsd_round_mask:
3294  case X86::BI__builtin_ia32_getmantss_round_mask:
3295  ArgNum = 5;
3296  HasRC = true;
3297  break;
3298  }
3299 
3300  llvm::APSInt Result;
3301 
3302  // We can't check the value of a dependent argument.
3303  Expr *Arg = TheCall->getArg(ArgNum);
3304  if (Arg->isTypeDependent() || Arg->isValueDependent())
3305  return false;
3306 
3307  // Check constant-ness first.
3308  if (SemaBuiltinConstantArg(TheCall, ArgNum, Result))
3309  return true;
3310 
3311  // Make sure rounding mode is either ROUND_CUR_DIRECTION or ROUND_NO_EXC bit
3312  // is set. If the intrinsic has rounding control(bits 1:0), make sure its only
3313  // combined with ROUND_NO_EXC.
3314  if (Result == 4/*ROUND_CUR_DIRECTION*/ ||
3315  Result == 8/*ROUND_NO_EXC*/ ||
3316  (HasRC && Result.getZExtValue() >= 8 && Result.getZExtValue() <= 11))
3317  return false;
3318 
3319  return Diag(TheCall->getBeginLoc(), diag::err_x86_builtin_invalid_rounding)
3320  << Arg->getSourceRange();
3321 }
3322 
3323 // Check if the gather/scatter scale is legal.
3324 bool Sema::CheckX86BuiltinGatherScatterScale(unsigned BuiltinID,
3325  CallExpr *TheCall) {
3326  unsigned ArgNum = 0;
3327  switch (BuiltinID) {
3328  default:
3329  return false;
3330  case X86::BI__builtin_ia32_gatherpfdpd:
3331  case X86::BI__builtin_ia32_gatherpfdps:
3332  case X86::BI__builtin_ia32_gatherpfqpd:
3333  case X86::BI__builtin_ia32_gatherpfqps:
3334  case X86::BI__builtin_ia32_scatterpfdpd:
3335  case X86::BI__builtin_ia32_scatterpfdps:
3336  case X86::BI__builtin_ia32_scatterpfqpd:
3337  case X86::BI__builtin_ia32_scatterpfqps:
3338  ArgNum = 3;
3339  break;
3340  case X86::BI__builtin_ia32_gatherd_pd:
3341  case X86::BI__builtin_ia32_gatherd_pd256:
3342  case X86::BI__builtin_ia32_gatherq_pd:
3343  case X86::BI__builtin_ia32_gatherq_pd256:
3344  case X86::BI__builtin_ia32_gatherd_ps:
3345  case X86::BI__builtin_ia32_gatherd_ps256:
3346  case X86::BI__builtin_ia32_gatherq_ps:
3347  case X86::BI__builtin_ia32_gatherq_ps256:
3348  case X86::BI__builtin_ia32_gatherd_q:
3349  case X86::BI__builtin_ia32_gatherd_q256:
3350  case X86::BI__builtin_ia32_gatherq_q:
3351  case X86::BI__builtin_ia32_gatherq_q256:
3352  case X86::BI__builtin_ia32_gatherd_d:
3353  case X86::BI__builtin_ia32_gatherd_d256:
3354  case X86::BI__builtin_ia32_gatherq_d:
3355  case X86::BI__builtin_ia32_gatherq_d256:
3356  case X86::BI__builtin_ia32_gather3div2df:
3357  case X86::BI__builtin_ia32_gather3div2di:
3358  case X86::BI__builtin_ia32_gather3div4df:
3359  case X86::BI__builtin_ia32_gather3div4di:
3360  case X86::BI__builtin_ia32_gather3div4sf:
3361  case X86::BI__builtin_ia32_gather3div4si:
3362  case X86::BI__builtin_ia32_gather3div8sf:
3363  case X86::BI__builtin_ia32_gather3div8si:
3364  case X86::BI__builtin_ia32_gather3siv2df:
3365  case X86::BI__builtin_ia32_gather3siv2di:
3366  case X86::BI__builtin_ia32_gather3siv4df:
3367  case X86::BI__builtin_ia32_gather3siv4di:
3368  case X86::BI__builtin_ia32_gather3siv4sf:
3369  case X86::BI__builtin_ia32_gather3siv4si:
3370  case X86::BI__builtin_ia32_gather3siv8sf:
3371  case X86::BI__builtin_ia32_gather3siv8si:
3372  case X86::BI__builtin_ia32_gathersiv8df:
3373  case X86::BI__builtin_ia32_gathersiv16sf:
3374  case X86::BI__builtin_ia32_gatherdiv8df:
3375  case X86::BI__builtin_ia32_gatherdiv16sf:
3376  case X86::BI__builtin_ia32_gathersiv8di:
3377  case X86::BI__builtin_ia32_gathersiv16si:
3378  case X86::BI__builtin_ia32_gatherdiv8di:
3379  case X86::BI__builtin_ia32_gatherdiv16si:
3380  case X86::BI__builtin_ia32_scatterdiv2df:
3381  case X86::BI__builtin_ia32_scatterdiv2di:
3382  case X86::BI__builtin_ia32_scatterdiv4df:
3383  case X86::BI__builtin_ia32_scatterdiv4di:
3384  case X86::BI__builtin_ia32_scatterdiv4sf:
3385  case X86::BI__builtin_ia32_scatterdiv4si:
3386  case X86::BI__builtin_ia32_scatterdiv8sf:
3387  case X86::BI__builtin_ia32_scatterdiv8si:
3388  case X86::BI__builtin_ia32_scattersiv2df:
3389  case X86::BI__builtin_ia32_scattersiv2di:
3390  case X86::BI__builtin_ia32_scattersiv4df:
3391  case X86::BI__builtin_ia32_scattersiv4di:
3392  case X86::BI__builtin_ia32_scattersiv4sf:
3393  case X86::BI__builtin_ia32_scattersiv4si:
3394  case X86::BI__builtin_ia32_scattersiv8sf:
3395  case X86::BI__builtin_ia32_scattersiv8si:
3396  case X86::BI__builtin_ia32_scattersiv8df:
3397  case X86::BI__builtin_ia32_scattersiv16sf:
3398  case X86::BI__builtin_ia32_scatterdiv8df:
3399  case X86::BI__builtin_ia32_scatterdiv16sf:
3400  case X86::BI__builtin_ia32_scattersiv8di:
3401  case X86::BI__builtin_ia32_scattersiv16si:
3402  case X86::BI__builtin_ia32_scatterdiv8di:
3403  case X86::BI__builtin_ia32_scatterdiv16si:
3404  ArgNum = 4;
3405  break;
3406  }
3407 
3408  llvm::APSInt Result;
3409 
3410  // We can't check the value of a dependent argument.
3411  Expr *Arg = TheCall->getArg(ArgNum);
3412  if (Arg->isTypeDependent() || Arg->isValueDependent())
3413  return false;
3414 
3415  // Check constant-ness first.
3416  if (SemaBuiltinConstantArg(TheCall, ArgNum, Result))
3417  return true;
3418 
3419  if (Result == 1 || Result == 2 || Result == 4 || Result == 8)
3420  return false;
3421 
3422  return Diag(TheCall->getBeginLoc(), diag::err_x86_builtin_invalid_scale)
3423  << Arg->getSourceRange();
3424 }
3425 
3426 static bool isX86_32Builtin(unsigned BuiltinID) {
3427  // These builtins only work on x86-32 targets.
3428  switch (BuiltinID) {
3429  case X86::BI__builtin_ia32_readeflags_u32:
3430  case X86::BI__builtin_ia32_writeeflags_u32:
3431  return true;
3432  }
3433 
3434  return false;
3435 }
3436 
3437 bool Sema::CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
3438  if (BuiltinID == X86::BI__builtin_cpu_supports)
3439  return SemaBuiltinCpuSupports(*this, TheCall);
3440 
3441  if (BuiltinID == X86::BI__builtin_cpu_is)
3442  return SemaBuiltinCpuIs(*this, TheCall);
3443 
3444  // Check for 32-bit only builtins on a 64-bit target.
3445  const llvm::Triple &TT = Context.getTargetInfo().getTriple();
3446  if (TT.getArch() != llvm::Triple::x86 && isX86_32Builtin(BuiltinID))
3447  return Diag(TheCall->getCallee()->getBeginLoc(),
3448  diag::err_32_bit_builtin_64_bit_tgt);
3449 
3450  // If the intrinsic has rounding or SAE make sure its valid.
3451  if (CheckX86BuiltinRoundingOrSAE(BuiltinID, TheCall))
3452  return true;
3453 
3454  // If the intrinsic has a gather/scatter scale immediate make sure its valid.
3455  if (CheckX86BuiltinGatherScatterScale(BuiltinID, TheCall))
3456  return true;
3457 
3458  // For intrinsics which take an immediate value as part of the instruction,
3459  // range check them here.
3460  int i = 0, l = 0, u = 0;
3461  switch (BuiltinID) {
3462  default:
3463  return false;
3464  case X86::BI__builtin_ia32_vec_ext_v2si:
3465  case X86::BI__builtin_ia32_vec_ext_v2di:
3466  case X86::BI__builtin_ia32_vextractf128_pd256:
3467  case X86::BI__builtin_ia32_vextractf128_ps256:
3468  case X86::BI__builtin_ia32_vextractf128_si256:
3469  case X86::BI__builtin_ia32_extract128i256:
3470  case X86::BI__builtin_ia32_extractf64x4_mask:
3471  case X86::BI__builtin_ia32_extracti64x4_mask:
3472  case X86::BI__builtin_ia32_extractf32x8_mask:
3473  case X86::BI__builtin_ia32_extracti32x8_mask:
3474  case X86::BI__builtin_ia32_extractf64x2_256_mask:
3475  case X86::BI__builtin_ia32_extracti64x2_256_mask:
3476  case X86::BI__builtin_ia32_extractf32x4_256_mask:
3477  case X86::BI__builtin_ia32_extracti32x4_256_mask:
3478  i = 1; l = 0; u = 1;
3479  break;
3480  case X86::BI__builtin_ia32_vec_set_v2di:
3481  case X86::BI__builtin_ia32_vinsertf128_pd256:
3482  case X86::BI__builtin_ia32_vinsertf128_ps256:
3483  case X86::BI__builtin_ia32_vinsertf128_si256:
3484  case X86::BI__builtin_ia32_insert128i256:
3485  case X86::BI__builtin_ia32_insertf32x8:
3486  case X86::BI__builtin_ia32_inserti32x8:
3487  case X86::BI__builtin_ia32_insertf64x4:
3488  case X86::BI__builtin_ia32_inserti64x4:
3489  case X86::BI__builtin_ia32_insertf64x2_256:
3490  case X86::BI__builtin_ia32_inserti64x2_256:
3491  case X86::BI__builtin_ia32_insertf32x4_256:
3492  case X86::BI__builtin_ia32_inserti32x4_256:
3493  i = 2; l = 0; u = 1;
3494  break;
3495  case X86::BI__builtin_ia32_vpermilpd:
3496  case X86::BI__builtin_ia32_vec_ext_v4hi:
3497  case X86::BI__builtin_ia32_vec_ext_v4si:
3498  case X86::BI__builtin_ia32_vec_ext_v4sf:
3499  case X86::BI__builtin_ia32_vec_ext_v4di:
3500  case X86::BI__builtin_ia32_extractf32x4_mask:
3501  case X86::BI__builtin_ia32_extracti32x4_mask:
3502  case X86::BI__builtin_ia32_extractf64x2_512_mask:
3503  case X86::BI__builtin_ia32_extracti64x2_512_mask:
3504  i = 1; l = 0; u = 3;
3505  break;
3506  case X86::BI_mm_prefetch:
3507  case X86::BI__builtin_ia32_vec_ext_v8hi:
3508  case X86::BI__builtin_ia32_vec_ext_v8si:
3509  i = 1; l = 0; u = 7;
3510  break;
3511  case X86::BI__builtin_ia32_sha1rnds4:
3512  case X86::BI__builtin_ia32_blendpd:
3513  case X86::BI__builtin_ia32_shufpd:
3514  case X86::BI__builtin_ia32_vec_set_v4hi:
3515  case X86::BI__builtin_ia32_vec_set_v4si:
3516  case X86::BI__builtin_ia32_vec_set_v4di:
3517  case X86::BI__builtin_ia32_shuf_f32x4_256:
3518  case X86::BI__builtin_ia32_shuf_f64x2_256:
3519  case X86::BI__builtin_ia32_shuf_i32x4_256:
3520  case X86::BI__builtin_ia32_shuf_i64x2_256:
3521  case X86::BI__builtin_ia32_insertf64x2_512:
3522  case X86::BI__builtin_ia32_inserti64x2_512:
3523  case X86::BI__builtin_ia32_insertf32x4:
3524  case X86::BI__builtin_ia32_inserti32x4:
3525  i = 2; l = 0; u = 3;
3526  break;
3527  case X86::BI__builtin_ia32_vpermil2pd:
3528  case X86::BI__builtin_ia32_vpermil2pd256:
3529  case X86::BI__builtin_ia32_vpermil2ps:
3530  case X86::BI__builtin_ia32_vpermil2ps256:
3531  i = 3; l = 0; u = 3;
3532  break;
3533  case X86::BI__builtin_ia32_cmpb128_mask:
3534  case X86::BI__builtin_ia32_cmpw128_mask:
3535  case X86::BI__builtin_ia32_cmpd128_mask:
3536  case X86::BI__builtin_ia32_cmpq128_mask:
3537  case X86::BI__builtin_ia32_cmpb256_mask:
3538  case X86::BI__builtin_ia32_cmpw256_mask:
3539  case X86::BI__builtin_ia32_cmpd256_mask:
3540  case X86::BI__builtin_ia32_cmpq256_mask:
3541  case X86::BI__builtin_ia32_cmpb512_mask:
3542  case X86::BI__builtin_ia32_cmpw512_mask:
3543  case X86::BI__builtin_ia32_cmpd512_mask:
3544  case X86::BI__builtin_ia32_cmpq512_mask:
3545  case X86::BI__builtin_ia32_ucmpb128_mask:
3546  case X86::BI__builtin_ia32_ucmpw128_mask:
3547  case X86::BI__builtin_ia32_ucmpd128_mask:
3548  case X86::BI__builtin_ia32_ucmpq128_mask:
3549  case X86::BI__builtin_ia32_ucmpb256_mask:
3550  case X86::BI__builtin_ia32_ucmpw256_mask:
3551  case X86::BI__builtin_ia32_ucmpd256_mask:
3552  case X86::BI__builtin_ia32_ucmpq256_mask:
3553  case X86::BI__builtin_ia32_ucmpb512_mask:
3554  case X86::BI__builtin_ia32_ucmpw512_mask:
3555  case X86::BI__builtin_ia32_ucmpd512_mask:
3556  case X86::BI__builtin_ia32_ucmpq512_mask:
3557  case X86::BI__builtin_ia32_vpcomub:
3558  case X86::BI__builtin_ia32_vpcomuw:
3559  case X86::BI__builtin_ia32_vpcomud:
3560  case X86::BI__builtin_ia32_vpcomuq:
3561  case X86::BI__builtin_ia32_vpcomb:
3562  case X86::BI__builtin_ia32_vpcomw:
3563  case X86::BI__builtin_ia32_vpcomd:
3564  case X86::BI__builtin_ia32_vpcomq:
3565  case X86::BI__builtin_ia32_vec_set_v8hi:
3566  case X86::BI__builtin_ia32_vec_set_v8si:
3567  i = 2; l = 0; u = 7;
3568  break;
3569  case X86::BI__builtin_ia32_vpermilpd256:
3570  case X86::BI__builtin_ia32_roundps:
3571  case X86::BI__builtin_ia32_roundpd:
3572  case X86::BI__builtin_ia32_roundps256:
3573  case X86::BI__builtin_ia32_roundpd256:
3574  case X86::BI__builtin_ia32_getmantpd128_mask:
3575  case X86::BI__builtin_ia32_getmantpd256_mask:
3576  case X86::BI__builtin_ia32_getmantps128_mask:
3577  case X86::BI__builtin_ia32_getmantps256_mask:
3578  case X86::BI__builtin_ia32_getmantpd512_mask:
3579  case X86::BI__builtin_ia32_getmantps512_mask:
3580  case X86::BI__builtin_ia32_vec_ext_v16qi:
3581  case X86::BI__builtin_ia32_vec_ext_v16hi:
3582  i = 1; l = 0; u = 15;
3583  break;
3584  case X86::BI__builtin_ia32_pblendd128:
3585  case X86::BI__builtin_ia32_blendps:
3586  case X86::BI__builtin_ia32_blendpd256:
3587  case X86::BI__builtin_ia32_shufpd256:
3588  case X86::BI__builtin_ia32_roundss:
3589  case X86::BI__builtin_ia32_roundsd:
3590  case X86::BI__builtin_ia32_rangepd128_mask:
3591  case X86::BI__builtin_ia32_rangepd256_mask:
3592  case X86::BI__builtin_ia32_rangepd512_mask:
3593  case X86::BI__builtin_ia32_rangeps128_mask:
3594  case X86::BI__builtin_ia32_rangeps256_mask:
3595  case X86::BI__builtin_ia32_rangeps512_mask:
3596  case X86::BI__builtin_ia32_getmantsd_round_mask:
3597  case X86::BI__builtin_ia32_getmantss_round_mask:
3598  case X86::BI__builtin_ia32_vec_set_v16qi:
3599  case X86::BI__builtin_ia32_vec_set_v16hi:
3600  i = 2; l = 0; u = 15;
3601  break;
3602  case X86::BI__builtin_ia32_vec_ext_v32qi:
3603  i = 1; l = 0; u = 31;
3604  break;
3605  case X86::BI__builtin_ia32_cmpps:
3606  case X86::BI__builtin_ia32_cmpss:
3607  case X86::BI__builtin_ia32_cmppd:
3608  case X86::BI__builtin_ia32_cmpsd:
3609  case X86::BI__builtin_ia32_cmpps256:
3610  case X86::BI__builtin_ia32_cmppd256:
3611  case X86::BI__builtin_ia32_cmpps128_mask:
3612  case X86::BI__builtin_ia32_cmppd128_mask:
3613  case X86::BI__builtin_ia32_cmpps256_mask:
3614  case X86::BI__builtin_ia32_cmppd256_mask:
3615  case X86::BI__builtin_ia32_cmpps512_mask:
3616  case X86::BI__builtin_ia32_cmppd512_mask:
3617  case X86::BI__builtin_ia32_cmpsd_mask:
3618  case X86::BI__builtin_ia32_cmpss_mask:
3619  case X86::BI__builtin_ia32_vec_set_v32qi:
3620  i = 2; l = 0; u = 31;
3621  break;
3622  case X86::BI__builtin_ia32_permdf256:
3623  case X86::BI__builtin_ia32_permdi256:
3624  case X86::BI__builtin_ia32_permdf512:
3625  case X86::BI__builtin_ia32_permdi512:
3626  case X86::BI__builtin_ia32_vpermilps:
3627  case X86::BI__builtin_ia32_vpermilps256:
3628  case X86::BI__builtin_ia32_vpermilpd512:
3629  case X86::BI__builtin_ia32_vpermilps512:
3630  case X86::BI__builtin_ia32_pshufd:
3631  case X86::BI__builtin_ia32_pshufd256:
3632  case X86::BI__builtin_ia32_pshufd512:
3633  case X86::BI__builtin_ia32_pshufhw:
3634  case X86::BI__builtin_ia32_pshufhw256:
3635  case X86::BI__builtin_ia32_pshufhw512:
3636  case X86::BI__builtin_ia32_pshuflw:
3637  case X86::BI__builtin_ia32_pshuflw256:
3638  case X86::BI__builtin_ia32_pshuflw512:
3639  case X86::BI__builtin_ia32_vcvtps2ph:
3640  case X86::BI__builtin_ia32_vcvtps2ph_mask:
3641  case X86::BI__builtin_ia32_vcvtps2ph256:
3642  case X86::BI__builtin_ia32_vcvtps2ph256_mask:
3643  case X86::BI__builtin_ia32_vcvtps2ph512_mask:
3644  case X86::BI__builtin_ia32_rndscaleps_128_mask:
3645  case X86::BI__builtin_ia32_rndscalepd_128_mask:
3646  case X86::BI__builtin_ia32_rndscaleps_256_mask:
3647  case X86::BI__builtin_ia32_rndscalepd_256_mask:
3648  case X86::BI__builtin_ia32_rndscaleps_mask:
3649  case X86::BI__builtin_ia32_rndscalepd_mask:
3650  case X86::BI__builtin_ia32_reducepd128_mask:
3651  case X86::BI__builtin_ia32_reducepd256_mask:
3652  case X86::BI__builtin_ia32_reducepd512_mask:
3653  case X86::BI__builtin_ia32_reduceps128_mask:
3654  case X86::BI__builtin_ia32_reduceps256_mask:
3655  case X86::BI__builtin_ia32_reduceps512_mask:
3656  case X86::BI__builtin_ia32_prold512:
3657  case X86::BI__builtin_ia32_prolq512:
3658  case X86::BI__builtin_ia32_prold128:
3659  case X86::BI__builtin_ia32_prold256:
3660  case X86::BI__builtin_ia32_prolq128:
3661  case X86::BI__builtin_ia32_prolq256:
3662  case X86::BI__builtin_ia32_prord512:
3663  case X86::BI__builtin_ia32_prorq512:
3664  case X86::BI__builtin_ia32_prord128:
3665  case X86::BI__builtin_ia32_prord256:
3666  case X86::BI__builtin_ia32_prorq128:
3667  case X86::BI__builtin_ia32_prorq256:
3668  case X86::BI__builtin_ia32_fpclasspd128_mask:
3669  case X86::BI__builtin_ia32_fpclasspd256_mask:
3670  case X86::BI__builtin_ia32_fpclassps128_mask:
3671  case X86::BI__builtin_ia32_fpclassps256_mask:
3672  case X86::BI__builtin_ia32_fpclassps512_mask:
3673  case X86::BI__builtin_ia32_fpclasspd512_mask:
3674  case X86::BI__builtin_ia32_fpclasssd_mask:
3675  case X86::BI__builtin_ia32_fpclassss_mask:
3676  case X86::BI__builtin_ia32_pslldqi128_byteshift:
3677  case X86::BI__builtin_ia32_pslldqi256_byteshift:
3678  case X86::BI__builtin_ia32_pslldqi512_byteshift:
3679  case X86::BI__builtin_ia32_psrldqi128_byteshift:
3680  case X86::BI__builtin_ia32_psrldqi256_byteshift:
3681  case X86::BI__builtin_ia32_psrldqi512_byteshift:
3682  case X86::BI__builtin_ia32_kshiftliqi:
3683  case X86::BI__builtin_ia32_kshiftlihi:
3684  case X86::BI__builtin_ia32_kshiftlisi:
3685  case X86::BI__builtin_ia32_kshiftlidi:
3686  case X86::BI__builtin_ia32_kshiftriqi:
3687  case X86::BI__builtin_ia32_kshiftrihi:
3688  case X86::BI__builtin_ia32_kshiftrisi:
3689  case X86::BI__builtin_ia32_kshiftridi:
3690  i = 1; l = 0; u = 255;
3691  break;
3692  case X86::BI__builtin_ia32_vperm2f128_pd256:
3693  case X86::BI__builtin_ia32_vperm2f128_ps256:
3694  case X86::BI__builtin_ia32_vperm2f128_si256:
3695  case X86::BI__builtin_ia32_permti256:
3696  case X86::BI__builtin_ia32_pblendw128:
3697  case X86::BI__builtin_ia32_pblendw256:
3698  case X86::BI__builtin_ia32_blendps256:
3699  case X86::BI__builtin_ia32_pblendd256:
3700  case X86::BI__builtin_ia32_palignr128:
3701  case X86::BI__builtin_ia32_palignr256:
3702  case X86::BI__builtin_ia32_palignr512:
3703  case X86::BI__builtin_ia32_alignq512:
3704  case X86::BI__builtin_ia32_alignd512:
3705  case X86::BI__builtin_ia32_alignd128:
3706  case X86::BI__builtin_ia32_alignd256:
3707  case X86::BI__builtin_ia32_alignq128:
3708  case X86::BI__builtin_ia32_alignq256:
3709  case X86::BI__builtin_ia32_vcomisd:
3710  case X86::BI__builtin_ia32_vcomiss:
3711  case X86::BI__builtin_ia32_shuf_f32x4:
3712  case X86::BI__builtin_ia32_shuf_f64x2:
3713  case X86::BI__builtin_ia32_shuf_i32x4:
3714  case X86::BI__builtin_ia32_shuf_i64x2:
3715  case X86::BI__builtin_ia32_shufpd512:
3716  case X86::BI__builtin_ia32_shufps:
3717  case X86::BI__builtin_ia32_shufps256:
3718  case X86::BI__builtin_ia32_shufps512:
3719  case X86::BI__builtin_ia32_dbpsadbw128:
3720  case X86::BI__builtin_ia32_dbpsadbw256:
3721  case X86::BI__builtin_ia32_dbpsadbw512:
3722  case X86::BI__builtin_ia32_vpshldd128:
3723  case X86::BI__builtin_ia32_vpshldd256:
3724  case X86::BI__builtin_ia32_vpshldd512:
3725  case X86::BI__builtin_ia32_vpshldq128:
3726  case X86::BI__builtin_ia32_vpshldq256:
3727  case X86::BI__builtin_ia32_vpshldq512:
3728  case X86::BI__builtin_ia32_vpshldw128:
3729  case X86::BI__builtin_ia32_vpshldw256:
3730  case X86::BI__builtin_ia32_vpshldw512:
3731  case X86::BI__builtin_ia32_vpshrdd128:
3732  case X86::BI__builtin_ia32_vpshrdd256:
3733  case X86::BI__builtin_ia32_vpshrdd512:
3734  case X86::BI__builtin_ia32_vpshrdq128:
3735  case X86::BI__builtin_ia32_vpshrdq256:
3736  case X86::BI__builtin_ia32_vpshrdq512:
3737  case X86::BI__builtin_ia32_vpshrdw128:
3738  case X86::BI__builtin_ia32_vpshrdw256:
3739  case X86::BI__builtin_ia32_vpshrdw512:
3740  i = 2; l = 0; u = 255;
3741  break;
3742  case X86::BI__builtin_ia32_fixupimmpd512_mask:
3743  case X86::BI__builtin_ia32_fixupimmpd512_maskz:
3744  case X86::BI__builtin_ia32_fixupimmps512_mask:
3745  case X86::BI__builtin_ia32_fixupimmps512_maskz:
3746  case X86::BI__builtin_ia32_fixupimmsd_mask:
3747  case X86::BI__builtin_ia32_fixupimmsd_maskz:
3748  case X86::BI__builtin_ia32_fixupimmss_mask:
3749  case X86::BI__builtin_ia32_fixupimmss_maskz:
3750  case X86::BI__builtin_ia32_fixupimmpd128_mask:
3751  case X86::BI__builtin_ia32_fixupimmpd128_maskz:
3752  case X86::BI__builtin_ia32_fixupimmpd256_mask:
3753  case X86::BI__builtin_ia32_fixupimmpd256_maskz:
3754  case X86::BI__builtin_ia32_fixupimmps128_mask:
3755  case X86::BI__builtin_ia32_fixupimmps128_maskz:
3756  case X86::BI__builtin_ia32_fixupimmps256_mask:
3757  case X86::BI__builtin_ia32_fixupimmps256_maskz:
3758  case X86::BI__builtin_ia32_pternlogd512_mask:
3759  case X86::BI__builtin_ia32_pternlogd512_maskz:
3760  case X86::BI__builtin_ia32_pternlogq512_mask:
3761  case X86::BI__builtin_ia32_pternlogq512_maskz:
3762  case X86::BI__builtin_ia32_pternlogd128_mask:
3763  case X86::BI__builtin_ia32_pternlogd128_maskz:
3764  case X86::BI__builtin_ia32_pternlogd256_mask:
3765  case X86::BI__builtin_ia32_pternlogd256_maskz:
3766  case X86::BI__builtin_ia32_pternlogq128_mask:
3767  case X86::BI__builtin_ia32_pternlogq128_maskz:
3768  case X86::BI__builtin_ia32_pternlogq256_mask:
3769  case X86::BI__builtin_ia32_pternlogq256_maskz:
3770  i = 3; l = 0; u = 255;
3771  break;
3772  case X86::BI__builtin_ia32_gatherpfdpd:
3773  case X86::BI__builtin_ia32_gatherpfdps:
3774  case X86::BI__builtin_ia32_gatherpfqpd:
3775  case X86::BI__builtin_ia32_gatherpfqps:
3776  case X86::BI__builtin_ia32_scatterpfdpd:
3777  case X86::BI__builtin_ia32_scatterpfdps:
3778  case X86::BI__builtin_ia32_scatterpfqpd:
3779  case X86::BI__builtin_ia32_scatterpfqps:
3780  i = 4; l = 2; u = 3;
3781  break;
3782  case X86::BI__builtin_ia32_rndscalesd_round_mask:
3783  case X86::BI__builtin_ia32_rndscaless_round_mask:
3784  i = 4; l = 0; u = 255;
3785  break;
3786  }
3787 
3788  // Note that we don't force a hard error on the range check here, allowing
3789  // template-generated or macro-generated dead code to potentially have out-of-
3790  // range values. These need to code generate, but don't need to necessarily
3791  // make any sense. We use a warning that defaults to an error.
3792  return SemaBuiltinConstantArgRange(TheCall, i, l, u, /*RangeIsError*/ false);
3793 }
3794 
3795 /// Given a FunctionDecl's FormatAttr, attempts to populate the FomatStringInfo
3796 /// parameter with the FormatAttr's correct format_idx and firstDataArg.
3797 /// Returns true when the format fits the function and the FormatStringInfo has
3798 /// been populated.
3799 bool Sema::getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember,
3800  FormatStringInfo *FSI) {
3801  FSI->HasVAListArg = Format->getFirstArg() == 0;
3802  FSI->FormatIdx = Format->getFormatIdx() - 1;
3803  FSI->FirstDataArg = FSI->HasVAListArg ? 0 : Format->getFirstArg() - 1;
3804 
3805  // The way the format attribute works in GCC, the implicit this argument
3806  // of member functions is counted. However, it doesn't appear in our own
3807  // lists, so decrement format_idx in that case.
3808  if (IsCXXMember) {
3809  if(FSI->FormatIdx == 0)
3810  return false;
3811  --FSI->FormatIdx;
3812  if (FSI->FirstDataArg != 0)
3813  --FSI->FirstDataArg;
3814  }
3815  return true;
3816 }
3817 
3818 /// Checks if a the given expression evaluates to null.
3819 ///
3820 /// Returns true if the value evaluates to null.
3821 static bool CheckNonNullExpr(Sema &S, const Expr *Expr) {
3822  // If the expression has non-null type, it doesn't evaluate to null.
3823  if (auto nullability
3824  = Expr->IgnoreImplicit()->getType()->getNullability(S.Context)) {
3825  if (*nullability == NullabilityKind::NonNull)
3826  return false;
3827  }
3828 
3829  // As a special case, transparent unions initialized with zero are
3830  // considered null for the purposes of the nonnull attribute.
3831  if (const RecordType *UT = Expr->getType()->getAsUnionType()) {
3832  if (UT->getDecl()->hasAttr<TransparentUnionAttr>())
3833  if (const CompoundLiteralExpr *CLE =
3834  dyn_cast<CompoundLiteralExpr>(Expr))
3835  if (const InitListExpr *ILE =
3836  dyn_cast<InitListExpr>(CLE->getInitializer()))
3837  Expr = ILE->getInit(0);
3838  }
3839 
3840  bool Result;
3841  return (!Expr->isValueDependent() &&
3842  Expr->EvaluateAsBooleanCondition(Result, S.Context) &&
3843  !Result);
3844 }
3845 
3847  const Expr *ArgExpr,
3848  SourceLocation CallSiteLoc) {
3849  if (CheckNonNullExpr(S, ArgExpr))
3850  S.DiagRuntimeBehavior(CallSiteLoc, ArgExpr,
3851  S.PDiag(diag::warn_null_arg) << ArgExpr->getSourceRange());
3852 }
3853 
3854 bool Sema::GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx) {
3855  FormatStringInfo FSI;
3856  if ((GetFormatStringType(Format) == FST_NSString) &&
3857  getFormatStringInfo(Format, false, &FSI)) {
3858  Idx = FSI.FormatIdx;
3859  return true;
3860  }
3861  return false;
3862 }
3863 
3864 /// Diagnose use of %s directive in an NSString which is being passed
3865 /// as formatting string to formatting method.
3866 static void
3868  const NamedDecl *FDecl,
3869  Expr **Args,
3870  unsigned NumArgs) {
3871  unsigned Idx = 0;
3872  bool Format = false;
3874  if (SFFamily == ObjCStringFormatFamily::SFF_CFString) {
3875  Idx = 2;
3876  Format = true;
3877  }
3878  else
3879  for (const auto *I : FDecl->specific_attrs<FormatAttr>()) {
3880  if (S.GetFormatNSStringIdx(I, Idx)) {
3881  Format = true;
3882  break;
3883  }
3884  }
3885  if (!Format || NumArgs <= Idx)
3886  return;
3887  const Expr *FormatExpr = Args[Idx];
3888  if (const CStyleCastExpr *CSCE = dyn_cast<CStyleCastExpr>(FormatExpr))
3889  FormatExpr = CSCE->getSubExpr();
3890  const StringLiteral *FormatString;
3891  if (const ObjCStringLiteral *OSL =
3892  dyn_cast<ObjCStringLiteral>(FormatExpr->IgnoreParenImpCasts()))
3893  FormatString = OSL->getString();
3894  else
3895  FormatString = dyn_cast<StringLiteral>(FormatExpr->IgnoreParenImpCasts());
3896  if (!FormatString)
3897  return;
3898  if (S.FormatStringHasSArg(FormatString)) {
3899  S.Diag(FormatExpr->getExprLoc(), diag::warn_objc_cdirective_format_string)
3900  << "%s" << 1 << 1;
3901  S.Diag(FDecl->getLocation(), diag::note_entity_declared_at)
3902  << FDecl->getDeclName();
3903  }
3904 }
3905 
3906 /// Determine whether the given type has a non-null nullability annotation.
3908  if (auto nullability = type->getNullability(ctx))
3909  return *nullability == NullabilityKind::NonNull;
3910 
3911  return false;
3912 }
3913 
3915  const NamedDecl *FDecl,
3916  const FunctionProtoType *Proto,
3917  ArrayRef<const Expr *> Args,
3918  SourceLocation CallSiteLoc) {
3919  assert((FDecl || Proto) && "Need a function declaration or prototype");
3920 
3921  // Check the attributes attached to the method/function itself.
3922  llvm::SmallBitVector NonNullArgs;
3923  if (FDecl) {
3924  // Handle the nonnull attribute on the function/method declaration itself.
3925  for (const auto *NonNull : FDecl->specific_attrs<NonNullAttr>()) {
3926  if (!NonNull->args_size()) {
3927  // Easy case: all pointer arguments are nonnull.
3928  for (const auto *Arg : Args)
3929  if (S.isValidPointerAttrType(Arg->getType()))
3930  CheckNonNullArgument(S, Arg, CallSiteLoc);
3931  return;
3932  }
3933 
3934  for (const ParamIdx &Idx : NonNull->args()) {
3935  unsigned IdxAST = Idx.getASTIndex();
3936  if (IdxAST >= Args.size())
3937  continue;
3938  if (NonNullArgs.empty())
3939  NonNullArgs.resize(Args.size());
3940  NonNullArgs.set(IdxAST);
3941  }
3942  }
3943  }
3944 
3945  if (FDecl && (isa<FunctionDecl>(FDecl) || isa<ObjCMethodDecl>(FDecl))) {
3946  // Handle the nonnull attribute on the parameters of the
3947  // function/method.
3948  ArrayRef<ParmVarDecl*> parms;
3949  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(FDecl))
3950  parms = FD->parameters();
3951  else
3952  parms = cast<ObjCMethodDecl>(FDecl)->parameters();
3953 
3954  unsigned ParamIndex = 0;
3955  for (ArrayRef<ParmVarDecl*>::iterator I = parms.begin(), E = parms.end();
3956  I != E; ++I, ++ParamIndex) {
3957  const ParmVarDecl *PVD = *I;
3958  if (PVD->hasAttr<NonNullAttr>() ||
3959  isNonNullType(S.Context, PVD->getType())) {
3960  if (NonNullArgs.empty())
3961  NonNullArgs.resize(Args.size());
3962 
3963  NonNullArgs.set(ParamIndex);
3964  }
3965  }
3966  } else {
3967  // If we have a non-function, non-method declaration but no
3968  // function prototype, try to dig out the function prototype.
3969  if (!Proto) {
3970  if (const ValueDecl *VD = dyn_cast<ValueDecl>(FDecl)) {
3971  QualType type = VD->getType().getNonReferenceType();
3972  if (auto pointerType = type->getAs<PointerType>())
3973  type = pointerType->getPointeeType();
3974  else if (auto blockType = type->getAs<BlockPointerType>())
3975  type = blockType->getPointeeType();
3976  // FIXME: data member pointers?
3977 
3978  // Dig out the function prototype, if there is one.
3979  Proto = type->getAs<FunctionProtoType>();
3980  }
3981  }
3982 
3983  // Fill in non-null argument information from the nullability
3984  // information on the parameter types (if we have them).
3985  if (Proto) {
3986  unsigned Index = 0;
3987  for (auto paramType : Proto->getParamTypes()) {
3988  if (isNonNullType(S.Context, paramType)) {
3989  if (NonNullArgs.empty())
3990  NonNullArgs.resize(Args.size());
3991 
3992  NonNullArgs.set(Index);
3993  }
3994 
3995  ++Index;
3996  }
3997  }
3998  }
3999 
4000  // Check for non-null arguments.
4001  for (unsigned ArgIndex = 0, ArgIndexEnd = NonNullArgs.size();
4002  ArgIndex != ArgIndexEnd; ++ArgIndex) {
4003  if (NonNullArgs[ArgIndex])
4004  CheckNonNullArgument(S, Args[ArgIndex], CallSiteLoc);
4005  }
4006 }
4007 
4008 /// Handles the checks for format strings, non-POD arguments to vararg
4009 /// functions, NULL arguments passed to non-NULL parameters, and diagnose_if
4010 /// attributes.
4011 void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
4012  const Expr *ThisArg, ArrayRef<const Expr *> Args,
4013  bool IsMemberFunction, SourceLocation Loc,
4014  SourceRange Range, VariadicCallType CallType) {
4015  // FIXME: We should check as much as we can in the template definition.
4016  if (CurContext->isDependentContext())
4017  return;
4018 
4019  // Printf and scanf checking.
4020  llvm::SmallBitVector CheckedVarArgs;
4021  if (FDecl) {
4022  for (const auto *I : FDecl->specific_attrs<FormatAttr>()) {
4023  // Only create vector if there are format attributes.
4024  CheckedVarArgs.resize(Args.size());
4025 
4026  CheckFormatArguments(I, Args, IsMemberFunction, CallType, Loc, Range,
4027  CheckedVarArgs);
4028  }
4029  }
4030 
4031  // Refuse POD arguments that weren't caught by the format string
4032  // checks above.
4033  auto *FD = dyn_cast_or_null<FunctionDecl>(FDecl);
4034  if (CallType != VariadicDoesNotApply &&
4035  (!FD || FD->getBuiltinID() != Builtin::BI__noop)) {
4036  unsigned NumParams = Proto ? Proto->getNumParams()
4037  : FDecl && isa<FunctionDecl>(FDecl)
4038  ? cast<FunctionDecl>(FDecl)->getNumParams()
4039  : FDecl && isa<ObjCMethodDecl>(FDecl)
4040  ? cast<ObjCMethodDecl>(FDecl)->param_size()
4041  : 0;
4042 
4043  for (unsigned ArgIdx = NumParams; ArgIdx < Args.size(); ++ArgIdx) {
4044  // Args[ArgIdx] can be null in malformed code.
4045  if (const Expr *Arg = Args[ArgIdx]) {
4046  if (CheckedVarArgs.empty() || !CheckedVarArgs[ArgIdx])
4047  checkVariadicArgument(Arg, CallType);
4048  }
4049  }
4050  }
4051 
4052  if (FDecl || Proto) {
4053  CheckNonNullArguments(*this, FDecl, Proto, Args, Loc);
4054 
4055  // Type safety checking.
4056  if (FDecl) {
4057  for (const auto *I : FDecl->specific_attrs<ArgumentWithTypeTagAttr>())
4058  CheckArgumentWithTypeTag(I, Args, Loc);
4059  }
4060  }
4061 
4062  if (FD)
4063  diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
4064 }
4065 
4066 /// CheckConstructorCall - Check a constructor call for correctness and safety
4067 /// properties not enforced by the C type system.
4068 void Sema::CheckConstructorCall(FunctionDecl *FDecl,
4069  ArrayRef<const Expr *> Args,
4070  const FunctionProtoType *Proto,
4071  SourceLocation Loc) {
4072  VariadicCallType CallType =
4073  Proto->isVariadic() ? VariadicConstructor : VariadicDoesNotApply;
4074  checkCall(FDecl, Proto, /*ThisArg=*/nullptr, Args, /*IsMemberFunction=*/true,
4075  Loc, SourceRange(), CallType);
4076 }
4077 
4078 /// CheckFunctionCall - Check a direct function call for various correctness
4079 /// and safety properties not strictly enforced by the C type system.
4080 bool Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
4081  const FunctionProtoType *Proto) {
4082  bool IsMemberOperatorCall = isa<CXXOperatorCallExpr>(TheCall) &&
4083  isa<CXXMethodDecl>(FDecl);
4084  bool IsMemberFunction = isa<CXXMemberCallExpr>(TheCall) ||
4085  IsMemberOperatorCall;
4086  VariadicCallType CallType = getVariadicCallType(FDecl, Proto,
4087  TheCall->getCallee());
4088  Expr** Args = TheCall->getArgs();
4089  unsigned NumArgs = TheCall->getNumArgs();
4090 
4091  Expr *ImplicitThis = nullptr;
4092  if (IsMemberOperatorCall) {
4093  // If this is a call to a member operator, hide the first argument
4094  // from checkCall.
4095  // FIXME: Our choice of AST representation here is less than ideal.
4096  ImplicitThis = Args[0];
4097  ++Args;
4098  --NumArgs;
4099  } else if (IsMemberFunction)
4100  ImplicitThis =
4101  cast<CXXMemberCallExpr>(TheCall)->getImplicitObjectArgument();
4102 
4103  checkCall(FDecl, Proto, ImplicitThis, llvm::makeArrayRef(Args, NumArgs),
4104  IsMemberFunction, TheCall->getRParenLoc(),
4105  TheCall->getCallee()->getSourceRange(), CallType);
4106 
4107  IdentifierInfo *FnInfo = FDecl->getIdentifier();
4108  // None of the checks below are needed for functions that don't have
4109  // simple names (e.g., C++ conversion functions).
4110  if (!FnInfo)
4111  return false;
4112 
4113  CheckAbsoluteValueFunction(TheCall, FDecl);
4114  CheckMaxUnsignedZero(TheCall, FDecl);
4115 
4116  if (getLangOpts().ObjC1)
4117  DiagnoseCStringFormatDirectiveInCFAPI(*this, FDecl, Args, NumArgs);
4118 
4119  unsigned CMId = FDecl->getMemoryFunctionKind();
4120  if (CMId == 0)
4121  return false;
4122 
4123  // Handle memory setting and copying functions.
4124  if (CMId == Builtin::BIstrlcpy || CMId == Builtin::BIstrlcat)
4125  CheckStrlcpycatArguments(TheCall, FnInfo);
4126  else if (CMId == Builtin::BIstrncat)
4127  CheckStrncatArguments(TheCall, FnInfo);
4128  else
4129  CheckMemaccessArguments(TheCall, CMId, FnInfo);
4130 
4131  return false;
4132 }
4133 
4134 bool Sema::CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation lbrac,
4135  ArrayRef<const Expr *> Args) {
4136  VariadicCallType CallType =
4137  Method->isVariadic() ? VariadicMethod : VariadicDoesNotApply;
4138 
4139  checkCall(Method, nullptr, /*ThisArg=*/nullptr, Args,
4140  /*IsMemberFunction=*/false, lbrac, Method->getSourceRange(),
4141  CallType);
4142 
4143  return false;
4144 }
4145 
4146 bool Sema::CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall,
4147  const FunctionProtoType *Proto) {
4148  QualType Ty;
4149  if (const auto *V = dyn_cast<VarDecl>(NDecl))
4150  Ty = V->getType().getNonReferenceType();
4151  else if (const auto *F = dyn_cast<FieldDecl>(NDecl))
4152  Ty = F->getType().getNonReferenceType();
4153  else
4154  return false;
4155 
4156  if (!Ty->isBlockPointerType() && !Ty->isFunctionPointerType() &&
4157  !Ty->isFunctionProtoType())
4158  return false;
4159 
4160  VariadicCallType CallType;
4161  if (!Proto || !Proto->isVariadic()) {
4162  CallType = VariadicDoesNotApply;
4163  } else if (Ty->isBlockPointerType()) {
4164  CallType = VariadicBlock;
4165  } else { // Ty->isFunctionPointerType()
4166  CallType = VariadicFunction;
4167  }
4168 
4169  checkCall(NDecl, Proto, /*ThisArg=*/nullptr,
4170  llvm::makeArrayRef(TheCall->getArgs(), TheCall->getNumArgs()),
4171  /*IsMemberFunction=*/false, TheCall->getRParenLoc(),
4172  TheCall->getCallee()->getSourceRange(), CallType);
4173 
4174  return false;
4175 }
4176 
4177 /// Checks function calls when a FunctionDecl or a NamedDecl is not available,
4178 /// such as function pointers returned from functions.
4179 bool Sema::CheckOtherCall(CallExpr *TheCall, const FunctionProtoType *Proto) {
4180  VariadicCallType CallType = getVariadicCallType(/*FDecl=*/nullptr, Proto,
4181  TheCall->getCallee());
4182  checkCall(/*FDecl=*/nullptr, Proto, /*ThisArg=*/nullptr,
4183  llvm::makeArrayRef(TheCall->getArgs(), TheCall->getNumArgs()),
4184  /*IsMemberFunction=*/false, TheCall->getRParenLoc(),
4185  TheCall->getCallee()->getSourceRange(), CallType);
4186 
4187  return false;
4188 }
4189 
4190 static bool isValidOrderingForOp(int64_t Ordering, AtomicExpr::AtomicOp Op) {
4191  if (!llvm::isValidAtomicOrderingCABI(Ordering))
4192  return false;
4193 
4194  auto OrderingCABI = (llvm::AtomicOrderingCABI)Ordering;
4195  switch (Op) {
4196  case AtomicExpr::AO__c11_atomic_init:
4197  case AtomicExpr::AO__opencl_atomic_init:
4198  llvm_unreachable("There is no ordering argument for an init");
4199 
4200  case AtomicExpr::AO__c11_atomic_load:
4201  case AtomicExpr::AO__opencl_atomic_load:
4202  case AtomicExpr::AO__atomic_load_n:
4203  case AtomicExpr::AO__atomic_load:
4204  return OrderingCABI != llvm::AtomicOrderingCABI::release &&
4205  OrderingCABI != llvm::AtomicOrderingCABI::acq_rel;
4206 
4207  case AtomicExpr::AO__c11_atomic_store:
4208  case AtomicExpr::AO__opencl_atomic_store:
4209  case AtomicExpr::AO__atomic_store:
4210  case AtomicExpr::AO__atomic_store_n:
4211  return OrderingCABI != llvm::AtomicOrderingCABI::consume &&
4212  OrderingCABI != llvm::AtomicOrderingCABI::acquire &&
4213  OrderingCABI != llvm::AtomicOrderingCABI::acq_rel;
4214 
4215  default:
4216  return true;
4217  }
4218 }
4219 
4220 ExprResult Sema::SemaAtomicOpsOverloaded(ExprResult TheCallResult,
4221  AtomicExpr::AtomicOp Op) {
4222  CallExpr *TheCall = cast<CallExpr>(TheCallResult.get());
4223  DeclRefExpr *DRE =cast<DeclRefExpr>(TheCall->getCallee()->IgnoreParenCasts());
4224 
4225  // All the non-OpenCL operations take one of the following forms.
4226  // The OpenCL operations take the __c11 forms with one extra argument for
4227  // synchronization scope.
4228  enum {
4229  // C __c11_atomic_init(A *, C)
4230  Init,
4231 
4232  // C __c11_atomic_load(A *, int)
4233  Load,
4234 
4235  // void __atomic_load(A *, CP, int)
4236  LoadCopy,
4237 
4238  // void __atomic_store(A *, CP, int)
4239  Copy,
4240 
4241  // C __c11_atomic_add(A *, M, int)
4242  Arithmetic,
4243 
4244  // C __atomic_exchange_n(A *, CP, int)
4245  Xchg,
4246 
4247  // void __atomic_exchange(A *, C *, CP, int)
4248  GNUXchg,
4249 
4250  // bool __c11_atomic_compare_exchange_strong(A *, C *, CP, int, int)
4251  C11CmpXchg,
4252 
4253  // bool __atomic_compare_exchange(A *, C *, CP, bool, int, int)
4254  GNUCmpXchg
4255  } Form = Init;
4256 
4257  const unsigned NumForm = GNUCmpXchg + 1;
4258  const unsigned NumArgs[] = { 2, 2, 3, 3, 3, 3, 4, 5, 6 };
4259  const unsigned NumVals[] = { 1, 0, 1, 1, 1, 1, 2, 2, 3 };
4260  // where:
4261  // C is an appropriate type,
4262  // A is volatile _Atomic(C) for __c11 builtins and is C for GNU builtins,
4263  // CP is C for __c11 builtins and GNU _n builtins and is C * otherwise,
4264  // M is C if C is an integer, and ptrdiff_t if C is a pointer, and
4265  // the int parameters are for orderings.
4266 
4267  static_assert(sizeof(NumArgs)/sizeof(NumArgs[0]) == NumForm
4268  && sizeof(NumVals)/sizeof(NumVals[0]) == NumForm,
4269  "need to update code for modified forms");
4270  static_assert(AtomicExpr::AO__c11_atomic_init == 0 &&
4271  AtomicExpr::AO__c11_atomic_fetch_xor + 1 ==
4272  AtomicExpr::AO__atomic_load,
4273  "need to update code for modified C11 atomics");
4274  bool IsOpenCL = Op >= AtomicExpr::AO__opencl_atomic_init &&
4275  Op <= AtomicExpr::AO__opencl_atomic_fetch_max;
4276  bool IsC11 = (Op >= AtomicExpr::AO__c11_atomic_init &&
4277  Op <= AtomicExpr::AO__c11_atomic_fetch_xor) ||
4278  IsOpenCL;
4279  bool IsN = Op == AtomicExpr::AO__atomic_load_n ||
4280  Op == AtomicExpr::AO__atomic_store_n ||
4281  Op == AtomicExpr::AO__atomic_exchange_n ||
4282  Op == AtomicExpr::AO__atomic_compare_exchange_n;
4283  bool IsAddSub = false;
4284  bool IsMinMax = false;
4285 
4286  switch (Op) {
4287  case AtomicExpr::AO__c11_atomic_init:
4288  case AtomicExpr::AO__opencl_atomic_init:
4289  Form = Init;
4290  break;
4291 
4292  case AtomicExpr::AO__c11_atomic_load:
4293  case AtomicExpr::AO__opencl_atomic_load:
4294  case AtomicExpr::AO__atomic_load_n:
4295  Form = Load;
4296  break;
4297 
4298  case AtomicExpr::AO__atomic_load:
4299  Form = LoadCopy;
4300  break;
4301 
4302  case AtomicExpr::AO__c11_atomic_store:
4303  case AtomicExpr::AO__opencl_atomic_store:
4304  case AtomicExpr::AO__atomic_store:
4305  case AtomicExpr::AO__atomic_store_n:
4306  Form = Copy;
4307  break;
4308 
4309  case AtomicExpr::AO__c11_atomic_fetch_add:
4310  case AtomicExpr::AO__c11_atomic_fetch_sub:
4311  case AtomicExpr::AO__opencl_atomic_fetch_add:
4312  case AtomicExpr::AO__opencl_atomic_fetch_sub:
4313  case AtomicExpr::AO__opencl_atomic_fetch_min:
4314  case AtomicExpr::AO__opencl_atomic_fetch_max:
4315  case AtomicExpr::AO__atomic_fetch_add:
4316  case AtomicExpr::AO__atomic_fetch_sub:
4317  case AtomicExpr::AO__atomic_add_fetch:
4318  case AtomicExpr::AO__atomic_sub_fetch:
4319  IsAddSub = true;
4320  LLVM_FALLTHROUGH;
4321  case AtomicExpr::AO__c11_atomic_fetch_and:
4322  case AtomicExpr::AO__c11_atomic_fetch_or:
4323  case AtomicExpr::AO__c11_atomic_fetch_xor:
4324  case AtomicExpr::AO__opencl_atomic_fetch_and:
4325  case AtomicExpr::AO__opencl_atomic_fetch_or:
4326  case AtomicExpr::AO__opencl_atomic_fetch_xor:
4327  case AtomicExpr::AO__atomic_fetch_and:
4328  case AtomicExpr::AO__atomic_fetch_or:
4329  case AtomicExpr::AO__atomic_fetch_xor:
4330  case AtomicExpr::AO__atomic_fetch_nand:
4331  case AtomicExpr::AO__atomic_and_fetch:
4332  case AtomicExpr::AO__atomic_or_fetch:
4333  case AtomicExpr::AO__atomic_xor_fetch:
4334  case AtomicExpr::AO__atomic_nand_fetch:
4335  Form = Arithmetic;
4336  break;
4337 
4338  case AtomicExpr::AO__atomic_fetch_min:
4339  case AtomicExpr::AO__atomic_fetch_max:
4340  IsMinMax = true;
4341  Form = Arithmetic;
4342  break;
4343 
4344  case AtomicExpr::AO__c11_atomic_exchange:
4345  case AtomicExpr::AO__opencl_atomic_exchange:
4346  case AtomicExpr::AO__atomic_exchange_n:
4347  Form = Xchg;
4348  break;
4349 
4350  case AtomicExpr::AO__atomic_exchange:
4351  Form = GNUXchg;
4352  break;
4353 
4354  case AtomicExpr::AO__c11_atomic_compare_exchange_strong:
4355  case AtomicExpr::AO__c11_atomic_compare_exchange_weak:
4356  case AtomicExpr::AO__opencl_atomic_compare_exchange_strong:
4357  case AtomicExpr::AO__opencl_atomic_compare_exchange_weak:
4358  Form = C11CmpXchg;
4359  break;
4360 
4361  case AtomicExpr::AO__atomic_compare_exchange:
4362  case AtomicExpr::AO__atomic_compare_exchange_n:
4363  Form = GNUCmpXchg;
4364  break;
4365  }
4366 
4367  unsigned AdjustedNumArgs = NumArgs[Form];
4368  if (IsOpenCL && Op != AtomicExpr::AO__opencl_atomic_init)
4369  ++AdjustedNumArgs;
4370  // Check we have the right number of arguments.
4371  if (TheCall->getNumArgs() < AdjustedNumArgs) {
4372  Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args)
4373  << 0 << AdjustedNumArgs << TheCall->getNumArgs()
4374  << TheCall->getCallee()->getSourceRange();
4375  return ExprError();
4376  } else if (TheCall->getNumArgs() > AdjustedNumArgs) {
4377  Diag(TheCall->getArg(AdjustedNumArgs)->getBeginLoc(),
4378  diag::err_typecheck_call_too_many_args)
4379  << 0 << AdjustedNumArgs << TheCall->getNumArgs()
4380  << TheCall->getCallee()->getSourceRange();
4381  return ExprError();
4382  }
4383 
4384  // Inspect the first argument of the atomic operation.
4385  Expr *Ptr = TheCall->getArg(0);
4386  ExprResult ConvertedPtr = DefaultFunctionArrayLvalueConversion(Ptr);
4387  if (ConvertedPtr.isInvalid())
4388  return ExprError();
4389 
4390  Ptr = ConvertedPtr.get();
4391  const PointerType *pointerType = Ptr->getType()->getAs<PointerType>();
4392  if (!pointerType) {
4393  Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_must_be_pointer)
4394  << Ptr->getType() << Ptr->getSourceRange();
4395  return ExprError();
4396  }
4397 
4398  // For a __c11 builtin, this should be a pointer to an _Atomic type.
4399  QualType AtomTy = pointerType->getPointeeType(); // 'A'
4400  QualType ValType = AtomTy; // 'C'
4401  if (IsC11) {
4402  if (!AtomTy->isAtomicType()) {
4403  Diag(DRE->getBeginLoc(), diag::err_atomic_op_needs_atomic)
4404  << Ptr->getType() << Ptr->getSourceRange();
4405  return ExprError();
4406  }
4407  if ((Form != Load && Form != LoadCopy && AtomTy.isConstQualified()) ||
4409  Diag(DRE->getBeginLoc(), diag::err_atomic_op_needs_non_const_atomic)
4410  << (AtomTy.isConstQualified() ? 0 : 1) << Ptr->getType()
4411  << Ptr->getSourceRange();
4412  return ExprError();
4413  }
4414  ValType = AtomTy->getAs<AtomicType>()->getValueType();
4415  } else if (Form != Load && Form != LoadCopy) {
4416  if (ValType.isConstQualified()) {
4417  Diag(DRE->getBeginLoc(), diag::err_atomic_op_needs_non_const_pointer)
4418  << Ptr->getType() << Ptr->getSourceRange();
4419  return ExprError();
4420  }
4421  }
4422 
4423  // For an arithmetic operation, the implied arithmetic must be well-formed.
4424  if (Form == Arithmetic) {
4425  // gcc does not enforce these rules for GNU atomics, but we do so for sanity.
4426  if (IsAddSub && !ValType->isIntegerType()
4427  && !ValType->isPointerType()) {
4428  Diag(DRE->getBeginLoc(), diag::err_atomic_op_needs_atomic_int_or_ptr)
4429  << IsC11 << Ptr->getType() << Ptr->getSourceRange();
4430  return ExprError();
4431  }
4432  if (IsMinMax) {
4433  const BuiltinType *BT = ValType->getAs<BuiltinType>();
4434  if (!BT || (BT->getKind() != BuiltinType::Int &&
4435  BT->getKind() != BuiltinType::UInt)) {
4436  Diag(DRE->getBeginLoc(), diag::err_atomic_op_needs_int32_or_ptr);
4437  return ExprError();
4438  }
4439  }
4440  if (!IsAddSub && !IsMinMax && !ValType->isIntegerType()) {
4441  Diag(DRE->getBeginLoc(), diag::err_atomic_op_bitwise_needs_atomic_int)
4442  << IsC11 << Ptr->getType() << Ptr->getSourceRange();
4443  return ExprError();
4444  }
4445  if (IsC11 && ValType->isPointerType() &&
4446  RequireCompleteType(Ptr->getBeginLoc(), ValType->getPointeeType(),
4447  diag::err_incomplete_type)) {
4448  return ExprError();
4449  }
4450  } else if (IsN && !ValType->isIntegerType() && !ValType->isPointerType()) {
4451  // For __atomic_*_n operations, the value type must be a scalar integral or
4452  // pointer type which is 1, 2, 4, 8 or 16 bytes in length.
4453  Diag(DRE->getBeginLoc(), diag::err_atomic_op_needs_atomic_int_or_ptr)
4454  << IsC11 << Ptr->getType() << Ptr->getSourceRange();
4455  return ExprError();
4456  }
4457 
4458  if (!IsC11 && !AtomTy.isTriviallyCopyableType(Context) &&
4459  !AtomTy->isScalarType()) {
4460  // For GNU atomics, require a trivially-copyable type. This is not part of
4461  // the GNU atomics specification, but we enforce it for sanity.
4462  Diag(DRE->getBeginLoc(), diag::err_atomic_op_needs_trivial_copy)
4463  << Ptr->getType() << Ptr->getSourceRange();
4464  return ExprError();
4465  }
4466 
4467  switch (ValType.getObjCLifetime()) {
4468  case Qualifiers::OCL_None:
4470  // okay
4471  break;
4472 
4473  case Qualifiers::OCL_Weak:
4476  // FIXME: Can this happen? By this point, ValType should be known
4477  // to be trivially copyable.
4478  Diag(DRE->getBeginLoc(), diag::err_arc_atomic_ownership)
4479  << ValType << Ptr->getSourceRange();
4480  return ExprError();
4481  }
4482 
4483  // All atomic operations have an overload which takes a pointer to a volatile
4484  // 'A'. We shouldn't let the volatile-ness of the pointee-type inject itself
4485  // into the result or the other operands. Similarly atomic_load takes a
4486  // pointer to a const 'A'.
4487  ValType.removeLocalVolatile();
4488  ValType.removeLocalConst();
4489  QualType ResultType = ValType;
4490  if (Form == Copy || Form == LoadCopy || Form == GNUXchg ||
4491  Form == Init)
4492  ResultType = Context.VoidTy;
4493  else if (Form == C11CmpXchg || Form == GNUCmpXchg)
4494  ResultType = Context.BoolTy;
4495 
4496  // The type of a parameter passed 'by value'. In the GNU atomics, such
4497  // arguments are actually passed as pointers.
4498  QualType ByValType = ValType; // 'CP'
4499  bool IsPassedByAddress = false;
4500  if (!IsC11 && !IsN) {
4501  ByValType = Ptr->getType();
4502  IsPassedByAddress = true;
4503  }
4504 
4505  // The first argument's non-CV pointer type is used to deduce the type of
4506  // subsequent arguments, except for:
4507  // - weak flag (always converted to bool)
4508  // - memory order (always converted to int)
4509  // - scope (always converted to int)
4510  for (unsigned i = 0; i != TheCall->getNumArgs(); ++i) {
4511  QualType Ty;
4512  if (i < NumVals[Form] + 1) {
4513  switch (i) {
4514  case 0:
4515  // The first argument is always a pointer. It has a fixed type.
4516  // It is always dereferenced, a nullptr is undefined.
4517  CheckNonNullArgument(*this, TheCall->getArg(i), DRE->getBeginLoc());
4518  // Nothing else to do: we already know all we want about this pointer.
4519  continue;
4520  case 1:
4521  // The second argument is the non-atomic operand. For arithmetic, this
4522  // is always passed by value, and for a compare_exchange it is always
4523  // passed by address. For the rest, GNU uses by-address and C11 uses
4524  // by-value.
4525  assert(Form != Load);
4526  if (Form == Init || (Form == Arithmetic && ValType->isIntegerType()))
4527  Ty = ValType;
4528  else if (Form == Copy || Form == Xchg) {
4529  if (IsPassedByAddress)
4530  // The value pointer is always dereferenced, a nullptr is undefined.
4531  CheckNonNullArgument(*this, TheCall->getArg(i), DRE->getBeginLoc());
4532  Ty = ByValType;
4533  } else if (Form == Arithmetic)
4534  Ty = Context.getPointerDiffType();
4535  else {
4536  Expr *ValArg = TheCall->getArg(i);
4537  // The value pointer is always dereferenced, a nullptr is undefined.
4538  CheckNonNullArgument(*this, ValArg, DRE->getBeginLoc());
4539  LangAS AS = LangAS::Default;
4540  // Keep address space of non-atomic pointer type.
4541  if (const PointerType *PtrTy =
4542  ValArg->getType()->getAs<PointerType>()) {
4543  AS = PtrTy->getPointeeType().getAddressSpace();
4544  }
4545  Ty = Context.getPointerType(
4546  Context.getAddrSpaceQualType(ValType.getUnqualifiedType(), AS));
4547  }
4548  break;
4549  case 2:
4550  // The third argument to compare_exchange / GNU exchange is the desired
4551  // value, either by-value (for the C11 and *_n variant) or as a pointer.
4552  if (IsPassedByAddress)
4553  CheckNonNullArgument(*this, TheCall->getArg(i), DRE->getBeginLoc());
4554  Ty = ByValType;
4555  break;
4556  case 3:
4557  // The fourth argument to GNU compare_exchange is a 'weak' flag.
4558  Ty = Context.BoolTy;
4559  break;
4560  }
4561  } else {
4562  // The order(s) and scope are always converted to int.
4563  Ty = Context.IntTy;
4564  }
4565 
4566  InitializedEntity Entity =
4567  InitializedEntity::InitializeParameter(Context, Ty, false);
4568  ExprResult Arg = TheCall->getArg(i);
4569  Arg = PerformCopyInitialization(Entity, SourceLocation(), Arg);
4570  if (Arg.isInvalid())
4571  return true;
4572  TheCall->setArg(i, Arg.get());
4573  }
4574 
4575  // Permute the arguments into a 'consistent' order.
4576  SmallVector<Expr*, 5> SubExprs;
4577  SubExprs.push_back(Ptr);
4578  switch (Form) {
4579  case Init:
4580  // Note, AtomicExpr::getVal1() has a special case for this atomic.
4581  SubExprs.push_back(TheCall->getArg(1)); // Val1
4582  break;
4583  case Load:
4584  SubExprs.push_back(TheCall->getArg(1)); // Order
4585  break;
4586  case LoadCopy:
4587  case Copy:
4588  case Arithmetic:
4589  case Xchg:
4590  SubExprs.push_back(TheCall->getArg(2)); // Order
4591  SubExprs.push_back(TheCall->getArg(1)); // Val1
4592  break;
4593  case GNUXchg:
4594  // Note, AtomicExpr::getVal2() has a special case for this atomic.
4595  SubExprs.push_back(TheCall->getArg(3)); // Order
4596  SubExprs.push_back(TheCall->getArg(1)); // Val1
4597  SubExprs.push_back(TheCall->getArg(2)); // Val2
4598  break;
4599  case C11CmpXchg:
4600  SubExprs.push_back(TheCall->getArg(3)); // Order
4601  SubExprs.push_back(TheCall->getArg(1)); // Val1
4602  SubExprs.push_back(TheCall->getArg(4)); // OrderFail
4603  SubExprs.push_back(TheCall->getArg(2)); // Val2
4604  break;
4605  case GNUCmpXchg:
4606  SubExprs.push_back(TheCall->getArg(4)); // Order
4607  SubExprs.push_back(TheCall->getArg(1)); // Val1
4608  SubExprs.push_back(TheCall->getArg(5)); // OrderFail
4609  SubExprs.push_back(TheCall->getArg(2)); // Val2
4610  SubExprs.push_back(TheCall->getArg(3)); // Weak
4611  break;
4612  }
4613 
4614  if (SubExprs.size() >= 2 && Form != Init) {
4615  llvm::APSInt Result(32);
4616  if (SubExprs[1]->isIntegerConstantExpr(Result, Context) &&
4617  !isValidOrderingForOp(Result.getSExtValue(), Op))
4618  Diag(SubExprs[1]->getBeginLoc(),
4619  diag::warn_atomic_op_has_invalid_memory_order)
4620  << SubExprs[1]->getSourceRange();
4621  }
4622 
4623  if (auto ScopeModel = AtomicExpr::getScopeModel(Op)) {
4624  auto *Scope = TheCall->getArg(TheCall->getNumArgs() - 1);
4625  llvm::APSInt Result(32);
4626  if (Scope->isIntegerConstantExpr(Result, Context) &&
4627  !ScopeModel->isValid(Result.getZExtValue())) {
4628  Diag(Scope->getBeginLoc(), diag::err_atomic_op_has_invalid_synch_scope)
4629  << Scope->getSourceRange();
4630  }
4631  SubExprs.push_back(Scope);
4632  }
4633 
4634  AtomicExpr *AE =
4635  new (Context) AtomicExpr(TheCall->getCallee()->getBeginLoc(), SubExprs,
4636  ResultType, Op, TheCall->getRParenLoc());
4637 
4638  if ((Op == AtomicExpr::AO__c11_atomic_load ||
4639  Op == AtomicExpr::AO__c11_atomic_store ||
4640  Op == AtomicExpr::AO__opencl_atomic_load ||
4641  Op == AtomicExpr::AO__opencl_atomic_store ) &&
4642  Context.AtomicUsesUnsupportedLibcall(AE))
4643  Diag(AE->getBeginLoc(), diag::err_atomic_load_store_uses_lib)
4644  << ((Op == AtomicExpr::AO__c11_atomic_load ||
4645  Op == AtomicExpr::AO__opencl_atomic_load)
4646  ? 0
4647  : 1);
4648 
4649  return AE;
4650 }
4651 
4652 /// checkBuiltinArgument - Given a call to a builtin function, perform
4653 /// normal type-checking on the given argument, updating the call in
4654 /// place. This is useful when a builtin function requires custom
4655 /// type-checking for some of its arguments but not necessarily all of
4656 /// them.
4657 ///
4658 /// Returns true on error.
4659 static bool checkBuiltinArgument(Sema &S, CallExpr *E, unsigned ArgIndex) {
4660  FunctionDecl *Fn = E->getDirectCallee();
4661  assert(Fn && "builtin call without direct callee!");
4662 
4663  ParmVarDecl *Param = Fn->getParamDecl(ArgIndex);
4664  InitializedEntity Entity =
4666 
4667  ExprResult Arg = E->getArg(0);
4668  Arg = S.PerformCopyInitialization(Entity, SourceLocation(), Arg);
4669  if (Arg.isInvalid())
4670  return true;
4671 
4672  E->setArg(ArgIndex, Arg.get());
4673  return false;
4674 }
4675 
4676 /// We have a call to a function like __sync_fetch_and_add, which is an
4677 /// overloaded function based on the pointer type of its first argument.
4678 /// The main ActOnCallExpr routines have already promoted the types of
4679 /// arguments because all of these calls are prototyped as void(...).
4680 ///
4681 /// This function goes through and does final semantic checking for these
4682 /// builtins, as well as generating any warnings.
4683 ExprResult
4684 Sema::SemaBuiltinAtomicOverloaded(ExprResult TheCallResult) {
4685  CallExpr *TheCall = static_cast<CallExpr *>(TheCallResult.get());
4686  Expr *Callee = TheCall->getCallee();
4687  DeclRefExpr *DRE = cast<DeclRefExpr>(Callee->IgnoreParenCasts());
4688  FunctionDecl *FDecl = cast<FunctionDecl>(DRE->getDecl());
4689 
4690  // Ensure that we have at least one argument to do type inference from.
4691  if (TheCall->getNumArgs() < 1) {
4692  Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args_at_least)
4693  << 0 << 1 << TheCall->getNumArgs() << Callee->getSourceRange();
4694  return ExprError();
4695  }
4696 
4697  // Inspect the first argument of the atomic builtin. This should always be
4698  // a pointer type, whose element is an integral scalar or pointer type.
4699  // Because it is a pointer type, we don't have to worry about any implicit
4700  // casts here.
4701  // FIXME: We don't allow floating point scalars as input.
4702  Expr *FirstArg = TheCall->getArg(0);
4703  ExprResult FirstArgResult = DefaultFunctionArrayLvalueConversion(FirstArg);
4704  if (FirstArgResult.isInvalid())
4705  return ExprError();
4706  FirstArg = FirstArgResult.get();
4707  TheCall->setArg(0, FirstArg);
4708 
4709  const PointerType *pointerType = FirstArg->getType()->getAs<PointerType>();
4710  if (!pointerType) {
4711  Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_must_be_pointer)
4712  << FirstArg->getType() << FirstArg->getSourceRange();
4713  return ExprError();
4714  }
4715 
4716  QualType ValType = pointerType->getPointeeType();
4717  if (!ValType->isIntegerType() && !ValType->isAnyPointerType() &&
4718  !ValType->isBlockPointerType()) {
4719  Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_must_be_pointer_intptr)
4720  << FirstArg->getType() << FirstArg->getSourceRange();
4721  return ExprError();
4722  }
4723 
4724  if (ValType.isConstQualified()) {
4725  Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_cannot_be_const)
4726  << FirstArg->getType() << FirstArg->getSourceRange();
4727  return ExprError();
4728  }
4729 
4730  switch (ValType.getObjCLifetime()) {
4731  case Qualifiers::OCL_None:
4733  // okay
4734  break;
4735 
4736  case Qualifiers::OCL_Weak:
4739  Diag(DRE->getBeginLoc(), diag::err_arc_atomic_ownership)
4740  << ValType << FirstArg->getSourceRange();
4741  return ExprError();
4742  }
4743 
4744  // Strip any qualifiers off ValType.
4745  ValType = ValType.getUnqualifiedType();
4746 
4747  // The majority of builtins return a value, but a few have special return
4748  // types, so allow them to override appropriately below.
4749  QualType ResultType = ValType;
4750 
4751  // We need to figure out which concrete builtin this maps onto. For example,
4752  // __sync_fetch_and_add with a 2 byte object turns into
4753  // __sync_fetch_and_add_2.
4754 #define BUILTIN_ROW(x) \
4755  { Builtin::BI##x##_1, Builtin::BI##x##_2, Builtin::BI##x##_4, \
4756  Builtin::BI##x##_8, Builtin::BI##x##_16 }
4757 
4758  static const unsigned BuiltinIndices[][5] = {
4759  BUILTIN_ROW(__sync_fetch_and_add),
4760  BUILTIN_ROW(__sync_fetch_and_sub),
4761  BUILTIN_ROW(__sync_fetch_and_or),
4762  BUILTIN_ROW(__sync_fetch_and_and),
4763  BUILTIN_ROW(__sync_fetch_and_xor),
4764  BUILTIN_ROW(__sync_fetch_and_nand),
4765 
4766  BUILTIN_ROW(__sync_add_and_fetch),
4767  BUILTIN_ROW(__sync_sub_and_fetch),
4768  BUILTIN_ROW(__sync_and_and_fetch),
4769  BUILTIN_ROW(__sync_or_and_fetch),
4770  BUILTIN_ROW(__sync_xor_and_fetch),
4771  BUILTIN_ROW(__sync_nand_and_fetch),
4772 
4773  BUILTIN_ROW(__sync_val_compare_and_swap),
4774  BUILTIN_ROW(__sync_bool_compare_and_swap),
4775  BUILTIN_ROW(__sync_lock_test_and_set),
4776  BUILTIN_ROW(__sync_lock_release),
4777  BUILTIN_ROW(__sync_swap)
4778  };
4779 #undef BUILTIN_ROW
4780 
4781  // Determine the index of the size.
4782  unsigned SizeIndex;
4783  switch (Context.getTypeSizeInChars(ValType).getQuantity()) {
4784  case 1: SizeIndex = 0; break;
4785  case 2: SizeIndex = 1; break;
4786  case 4: SizeIndex = 2; break;
4787  case 8: SizeIndex = 3; break;
4788  case 16: SizeIndex = 4; break;
4789  default:
4790  Diag(DRE->getBeginLoc(), diag::err_atomic_builtin_pointer_size)
4791  << FirstArg->getType() << FirstArg->getSourceRange();
4792  return ExprError();
4793  }
4794 
4795  // Each of these builtins has one pointer argument, followed by some number of
4796  // values (0, 1 or 2) followed by a potentially empty varags list of stuff
4797  // that we ignore. Find out which row of BuiltinIndices to read from as well
4798  // as the number of fixed args.
4799  unsigned BuiltinID = FDecl->getBuiltinID();
4800  unsigned BuiltinIndex, NumFixed = 1;
4801  bool WarnAboutSemanticsChange = false;
4802  switch (BuiltinID) {
4803  default: llvm_unreachable("Unknown overloaded atomic builtin!");
4804  case Builtin::BI__sync_fetch_and_add:
4805  case Builtin::BI__sync_fetch_and_add_1:
4806  case Builtin::BI__sync_fetch_and_add_2:
4807  case Builtin::BI__sync_fetch_and_add_4:
4808  case Builtin::BI__sync_fetch_and_add_8:
4809  case Builtin::BI__sync_fetch_and_add_16:
4810  BuiltinIndex = 0;
4811  break;
4812 
4813  case Builtin::BI__sync_fetch_and_sub:
4814  case Builtin::BI__sync_fetch_and_sub_1:
4815  case Builtin::BI__sync_fetch_and_sub_2:
4816  case Builtin::BI__sync_fetch_and_sub_4:
4817  case Builtin::BI__sync_fetch_and_sub_8:
4818  case Builtin::BI__sync_fetch_and_sub_16:
4819  BuiltinIndex = 1;
4820  break;
4821 
4822  case Builtin::BI__sync_fetch_and_or:
4823  case Builtin::BI__sync_fetch_and_or_1:
4824  case Builtin::BI__sync_fetch_and_or_2:
4825  case Builtin::BI__sync_fetch_and_or_4:
4826  case Builtin::BI__sync_fetch_and_or_8:
4827  case Builtin::BI__sync_fetch_and_or_16:
4828  BuiltinIndex = 2;
4829  break;
4830 
4831  case Builtin::BI__sync_fetch_and_and:
4832  case Builtin::BI__sync_fetch_and_and_1:
4833  case Builtin::BI__sync_fetch_and_and_2:
4834  case Builtin::BI__sync_fetch_and_and_4:
4835  case Builtin::BI__sync_fetch_and_and_8:
4836  case Builtin::BI__sync_fetch_and_and_16:
4837  BuiltinIndex = 3;
4838  break;
4839 
4840  case Builtin::BI__sync_fetch_and_xor:
4841  case Builtin::BI__sync_fetch_and_xor_1:
4842  case Builtin::BI__sync_fetch_and_xor_2:
4843  case Builtin::BI__sync_fetch_and_xor_4:
4844  case Builtin::BI__sync_fetch_and_xor_8:
4845  case Builtin::BI__sync_fetch_and_xor_16:
4846  BuiltinIndex = 4;
4847  break;
4848 
4849  case Builtin::BI__sync_fetch_and_nand:
4850  case Builtin::BI__sync_fetch_and_nand_1:
4851  case Builtin::BI__sync_fetch_and_nand_2:
4852  case Builtin::BI__sync_fetch_and_nand_4:
4853  case Builtin::BI__sync_fetch_and_nand_8:
4854  case Builtin::BI__sync_fetch_and_nand_16:
4855  BuiltinIndex = 5;
4856  WarnAboutSemanticsChange = true;
4857  break;
4858 
4859  case Builtin::BI__sync_add_and_fetch:
4860  case Builtin::BI__sync_add_and_fetch_1:
4861  case Builtin::BI__sync_add_and_fetch_2:
4862  case Builtin::BI__sync_add_and_fetch_4:
4863  case Builtin::BI__sync_add_and_fetch_8:
4864  case Builtin::BI__sync_add_and_fetch_16:
4865  BuiltinIndex = 6;
4866  break;
4867 
4868  case Builtin::BI__sync_sub_and_fetch:
4869  case Builtin::BI__sync_sub_and_fetch_1:
4870  case Builtin::BI__sync_sub_and_fetch_2:
4871  case Builtin::BI__sync_sub_and_fetch_4:
4872  case Builtin::BI__sync_sub_and_fetch_8:
4873  case Builtin::BI__sync_sub_and_fetch_16:
4874  BuiltinIndex = 7;
4875  break;
4876 
4877  case Builtin::BI__sync_and_and_fetch:
4878  case Builtin::BI__sync_and_and_fetch_1:
4879  case Builtin::BI__sync_and_and_fetch_2:
4880  case Builtin::BI__sync_and_and_fetch_4:
4881  case Builtin::BI__sync_and_and_fetch_8:
4882  case Builtin::BI__sync_and_and_fetch_16:
4883  BuiltinIndex = 8;
4884  break;
4885 
4886  case Builtin::BI__sync_or_and_fetch:
4887  case Builtin::BI__sync_or_and_fetch_1:
4888  case Builtin::BI__sync_or_and_fetch_2:
4889  case Builtin::BI__sync_or_and_fetch_4:
4890  case Builtin::BI__sync_or_and_fetch_8:
4891  case Builtin::BI__sync_or_and_fetch_16:
4892  BuiltinIndex = 9;
4893  break;
4894 
4895  case Builtin::BI__sync_xor_and_fetch:
4896  case Builtin::BI__sync_xor_and_fetch_1:
4897  case Builtin::BI__sync_xor_and_fetch_2:
4898  case Builtin::BI__sync_xor_and_fetch_4:
4899  case Builtin::BI__sync_xor_and_fetch_8:
4900  case Builtin::BI__sync_xor_and_fetch_16:
4901  BuiltinIndex = 10;
4902  break;
4903 
4904  case Builtin::BI__sync_nand_and_fetch:
4905  case Builtin::BI__sync_nand_and_fetch_1:
4906  case Builtin::BI__sync_nand_and_fetch_2:
4907  case Builtin::BI__sync_nand_and_fetch_4:
4908  case Builtin::BI__sync_nand_and_fetch_8:
4909  case Builtin::BI__sync_nand_and_fetch_16:
4910  BuiltinIndex = 11;
4911  WarnAboutSemanticsChange = true;
4912  break;
4913 
4914  case Builtin::BI__sync_val_compare_and_swap:
4915  case Builtin::BI__sync_val_compare_and_swap_1:
4916  case Builtin::BI__sync_val_compare_and_swap_2:
4917  case Builtin::BI__sync_val_compare_and_swap_4:
4918  case Builtin::BI__sync_val_compare_and_swap_8:
4919  case Builtin::BI__sync_val_compare_and_swap_16:
4920  BuiltinIndex = 12;
4921  NumFixed = 2;
4922  break;
4923 
4924  case Builtin::BI__sync_bool_compare_and_swap:
4925  case Builtin::BI__sync_bool_compare_and_swap_1:
4926  case Builtin::BI__sync_bool_compare_and_swap_2:
4927  case Builtin::BI__sync_bool_compare_and_swap_4:
4928  case Builtin::BI__sync_bool_compare_and_swap_8:
4929  case Builtin::BI__sync_bool_compare_and_swap_16:
4930  BuiltinIndex = 13;
4931  NumFixed = 2;
4932  ResultType = Context.BoolTy;
4933  break;
4934 
4935  case Builtin::BI__sync_lock_test_and_set:
4936  case Builtin::BI__sync_lock_test_and_set_1:
4937  case Builtin::BI__sync_lock_test_and_set_2:
4938  case Builtin::BI__sync_lock_test_and_set_4:
4939  case Builtin::BI__sync_lock_test_and_set_8:
4940  case Builtin::BI__sync_lock_test_and_set_16:
4941  BuiltinIndex = 14;
4942  break;
4943 
4944  case Builtin::BI__sync_lock_release:
4945  case Builtin::BI__sync_lock_release_1:
4946  case Builtin::BI__sync_lock_release_2:
4947  case Builtin::BI__sync_lock_release_4:
4948  case Builtin::BI__sync_lock_release_8:
4949  case Builtin::BI__sync_lock_release_16:
4950  BuiltinIndex = 15;
4951  NumFixed = 0;
4952  ResultType = Context.VoidTy;
4953  break;
4954 
4955  case Builtin::BI__sync_swap:
4956  case Builtin::BI__sync_swap_1:
4957  case Builtin::BI__sync_swap_2:
4958  case Builtin::BI__sync_swap_4:
4959  case Builtin::BI__sync_swap_8:
4960  case Builtin::BI__sync_swap_16:
4961  BuiltinIndex = 16;
4962  break;
4963  }
4964 
4965  // Now that we know how many fixed arguments we expect, first check that we
4966  // have at least that many.
4967  if (TheCall->getNumArgs() < 1+NumFixed) {
4968  Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args_at_least)
4969  << 0 << 1 + NumFixed << TheCall->getNumArgs()
4970  << Callee->getSourceRange();
4971  return ExprError();
4972  }
4973 
4974  Diag(TheCall->getEndLoc(), diag::warn_atomic_implicit_seq_cst)
4975  << Callee->getSourceRange();
4976 
4977  if (WarnAboutSemanticsChange) {
4978  Diag(TheCall->getEndLoc(), diag::warn_sync_fetch_and_nand_semantics_change)
4979  << Callee->getSourceRange();
4980  }
4981 
4982  // Get the decl for the concrete builtin from this, we can tell what the
4983  // concrete integer type we should convert to is.
4984  unsigned NewBuiltinID = BuiltinIndices[BuiltinIndex][SizeIndex];
4985  const char *NewBuiltinName = Context.BuiltinInfo.getName(NewBuiltinID);
4986  FunctionDecl *NewBuiltinDecl;
4987  if (NewBuiltinID == BuiltinID)
4988  NewBuiltinDecl = FDecl;
4989  else {
4990  // Perform builtin lookup to avoid redeclaring it.
4991  DeclarationName DN(&Context.Idents.get(NewBuiltinName));
4992  LookupResult Res(*this, DN, DRE->getBeginLoc(), LookupOrdinaryName);
4993  LookupName(Res, TUScope, /*AllowBuiltinCreation=*/true);
4994  assert(Res.getFoundDecl());
4995  NewBuiltinDecl = dyn_cast<FunctionDecl>(Res.getFoundDecl());
4996  if (!NewBuiltinDecl)
4997  return ExprError();
4998  }
4999 
5000  // The first argument --- the pointer --- has a fixed type; we
5001  // deduce the types of the rest of the arguments accordingly. Walk
5002  // the remaining arguments, converting them to the deduced value type.
5003  for (unsigned i = 0; i != NumFixed; ++i) {
5004  ExprResult Arg = TheCall->getArg(i+1);
5005 
5006  // GCC does an implicit conversion to the pointer or integer ValType. This
5007  // can fail in some cases (1i -> int**), check for this error case now.
5008  // Initialize the argument.
5010  ValType, /*consume*/ false);
5011  Arg = PerformCopyInitialization(Entity, SourceLocation(), Arg);
5012  if (Arg.isInvalid())
5013  return ExprError();
5014 
5015  // Okay, we have something that *can* be converted to the right type. Check
5016  // to see if there is a potentially weird extension going on here. This can
5017  // happen when you do an atomic operation on something like an char* and
5018  // pass in 42. The 42 gets converted to char. This is even more strange
5019  // for things like 45.123 -> char, etc.
5020  // FIXME: Do this check.
5021  TheCall->setArg(i+1, Arg.get());
5022  }
5023 
5024  ASTContext& Context = this->getASTContext();
5025 
5026  // Create a new DeclRefExpr to refer to the new decl.
5027  DeclRefExpr* NewDRE = DeclRefExpr::Create(
5028  Context,
5029  DRE->getQualifierLoc(),
5030  SourceLocation(),
5031  NewBuiltinDecl,
5032  /*enclosing*/ false,
5033  DRE->getLocation(),
5034  Context.BuiltinFnTy,
5035  DRE->getValueKind());
5036 
5037  // Set the callee in the CallExpr.
5038  // FIXME: This loses syntactic information.
5039  QualType CalleePtrTy = Context.getPointerType(NewBuiltinDecl->getType());
5040  ExprResult PromotedCall = ImpCastExprToType(NewDRE, CalleePtrTy,
5041  CK_BuiltinFnToFnPtr);
5042  TheCall->setCallee(PromotedCall.get());
5043 
5044  // Change the result type of the call to match the original value type. This
5045  // is arbitrary, but the codegen for these builtins ins design to handle it
5046  // gracefully.
5047  TheCall->setType(ResultType);
5048 
5049  return TheCallResult;
5050 }
5051 
5052 /// SemaBuiltinNontemporalOverloaded - We have a call to
5053 /// __builtin_nontemporal_store or __builtin_nontemporal_load, which is an
5054 /// overloaded function based on the pointer type of its last argument.
5055 ///
5056 /// This function goes through and does final semantic checking for these
5057 /// builtins.
5058 ExprResult Sema::SemaBuiltinNontemporalOverloaded(ExprResult TheCallResult) {
5059  CallExpr *TheCall = (CallExpr *)TheCallResult.get();
5060  DeclRefExpr *DRE =
5061  cast<DeclRefExpr>(TheCall->getCallee()->IgnoreParenCasts());
5062  FunctionDecl *FDecl = cast<FunctionDecl>(DRE->getDecl());
5063  unsigned BuiltinID = FDecl->getBuiltinID();
5064  assert((BuiltinID == Builtin::BI__builtin_nontemporal_store ||
5065  BuiltinID == Builtin::BI__builtin_nontemporal_load) &&
5066  "Unexpected nontemporal load/store builtin!");
5067  bool isStore = BuiltinID == Builtin::BI__builtin_nontemporal_store;
5068  unsigned numArgs = isStore ? 2 : 1;
5069 
5070  // Ensure that we have the proper number of arguments.
5071  if (checkArgCount(*this, TheCall, numArgs))
5072  return ExprError();
5073 
5074  // Inspect the last argument of the nontemporal builtin. This should always
5075  // be a pointer type, from which we imply the type of the memory access.
5076  // Because it is a pointer type, we don't have to worry about any implicit
5077  // casts here.
5078  Expr *PointerArg = TheCall->getArg(numArgs - 1);
5079  ExprResult PointerArgResult =
5080  DefaultFunctionArrayLvalueConversion(PointerArg);
5081 
5082  if (PointerArgResult.isInvalid())
5083  return ExprError();
5084  PointerArg = PointerArgResult.get();
5085  TheCall->setArg(numArgs - 1, PointerArg);
5086 
5087  const PointerType *pointerType = PointerArg->getType()->getAs<PointerType>();
5088  if (!pointerType) {
5089  Diag(DRE->getBeginLoc(), diag::err_nontemporal_builtin_must_be_pointer)
5090  << PointerArg->getType() << PointerArg->getSourceRange();
5091  return ExprError();
5092  }
5093 
5094  QualType ValType = pointerType->getPointeeType();
5095 
5096  // Strip any qualifiers off ValType.
5097  ValType = ValType.getUnqualifiedType();
5098  if (!ValType->isIntegerType() && !ValType->isAnyPointerType() &&
5099  !ValType->isBlockPointerType() && !ValType->isFloatingType() &&
5100  !ValType->isVectorType()) {
5101  Diag(DRE->getBeginLoc(),
5102  diag::err_nontemporal_builtin_must_be_pointer_intfltptr_or_vector)
5103  << PointerArg->getType() << PointerArg->getSourceRange();
5104  return ExprError();
5105  }
5106 
5107  if (!isStore) {
5108  TheCall->setType(ValType);
5109  return TheCallResult;
5110  }
5111 
5112  ExprResult ValArg = TheCall->getArg(0);
5114  Context, ValType, /*consume*/ false);
5115  ValArg = PerformCopyInitialization(Entity, SourceLocation(), ValArg);
5116  if (ValArg.isInvalid())
5117  return ExprError();
5118 
5119  TheCall->setArg(0, ValArg.get());
5120  TheCall->setType(Context.VoidTy);
5121  return TheCallResult;
5122 }
5123 
5124 /// CheckObjCString - Checks that the argument to the builtin
5125 /// CFString constructor is correct
5126 /// Note: It might also make sense to do the UTF-16 conversion here (would
5127 /// simplify the backend).
5128 bool Sema::CheckObjCString(Expr *Arg) {
5129  Arg = Arg->IgnoreParenCasts();
5130  StringLiteral *Literal = dyn_cast<StringLiteral>(Arg);
5131 
5132  if (!Literal || !Literal->isAscii()) {
5133  Diag(Arg->getBeginLoc(), diag::err_cfstring_literal_not_string_constant)
5134  << Arg->getSourceRange();
5135  return true;
5136  }
5137 
5138  if (Literal->containsNonAsciiOrNull()) {
5139  StringRef String = Literal->getString();
5140  unsigned NumBytes = String.size();
5141  SmallVector<llvm::UTF16, 128> ToBuf(NumBytes);
5142  const llvm::UTF8 *FromPtr = (const llvm::UTF8 *)String.data();
5143  llvm::UTF16 *ToPtr = &ToBuf[0];
5144 
5145  llvm::ConversionResult Result =
5146  llvm::ConvertUTF8toUTF16(&FromPtr, FromPtr + NumBytes, &ToPtr,
5147  ToPtr + NumBytes, llvm::strictConversion);
5148  // Check for conversion failure.
5149  if (Result != llvm::conversionOK)
5150  Diag(Arg->getBeginLoc(), diag::warn_cfstring_truncated)
5151  << Arg->getSourceRange();
5152  }
5153  return false;
5154 }
5155 
5156 /// CheckObjCString - Checks that the format string argument to the os_log()
5157 /// and os_trace() functions is correct, and converts it to const char *.
5158 ExprResult Sema::CheckOSLogFormatStringArg(Expr *Arg) {
5159  Arg = Arg->IgnoreParenCasts();
5160  auto *Literal = dyn_cast<StringLiteral>(Arg);
5161  if (!Literal) {
5162  if (auto *ObjcLiteral = dyn_cast<ObjCStringLiteral>(Arg)) {
5163  Literal = ObjcLiteral->getString();
5164  }
5165  }
5166 
5167  if (!Literal || (!Literal->isAscii() && !Literal->isUTF8())) {
5168  return ExprError(
5169  Diag(Arg->getBeginLoc(), diag::err_os_log_format_not_string_constant)
5170  << Arg->getSourceRange());
5171  }
5172 
5173  ExprResult Result(Literal);
5174  QualType ResultTy = Context.getPointerType(Context.CharTy.withConst());
5175  InitializedEntity Entity =
5176  InitializedEntity::InitializeParameter(Context, ResultTy, false);
5177  Result = PerformCopyInitialization(Entity, SourceLocation(), Result);
5178  return Result;
5179 }
5180 
5181 /// Check that the user is calling the appropriate va_start builtin for the
5182 /// target and calling convention.
5183 static bool checkVAStartABI(Sema &S, unsigned BuiltinID, Expr *Fn) {
5184  const llvm::Triple &TT = S.Context.getTargetInfo().getTriple();
5185  bool IsX64 = TT.getArch() == llvm::Triple::x86_64;
5186  bool IsAArch64 = TT.getArch() == llvm::Triple::aarch64;
5187  bool IsWindows = TT.isOSWindows();
5188  bool IsMSVAStart = BuiltinID == Builtin::BI__builtin_ms_va_start;
5189  if (IsX64 || IsAArch64) {
5190  CallingConv CC = CC_C;
5191  if (const FunctionDecl *FD = S.getCurFunctionDecl())
5192  CC = FD->getType()->getAs<FunctionType>()->getCallConv();
5193  if (IsMSVAStart) {
5194  // Don't allow this in System V ABI functions.
5195  if (CC == CC_X86_64SysV || (!IsWindows && CC != CC_Win64))
5196  return S.Diag(Fn->getBeginLoc(),
5197  diag::err_ms_va_start_used_in_sysv_function);
5198  } else {
5199  // On x86-64/AArch64 Unix, don't allow this in Win64 ABI functions.
5200  // On x64 Windows, don't allow this in System V ABI functions.
5201  // (Yes, that means there's no corresponding way to support variadic
5202  // System V ABI functions on Windows.)
5203  if ((IsWindows && CC == CC_X86_64SysV) ||
5204  (!IsWindows && CC == CC_Win64))
5205  return S.Diag(Fn->getBeginLoc(),
5206  diag::err_va_start_used_in_wrong_abi_function)
5207  << !IsWindows;
5208  }
5209  return false;
5210  }
5211 
5212  if (IsMSVAStart)
5213  return S.Diag(Fn->getBeginLoc(), diag::err_builtin_x64_aarch64_only);
5214  return false;
5215 }
5216 
5218  ParmVarDecl **LastParam = nullptr) {
5219  // Determine whether the current function, block, or obj-c method is variadic
5220  // and get its parameter list.
5221  bool IsVariadic = false;
5222  ArrayRef<ParmVarDecl *> Params;
5223  DeclContext *Caller = S.CurContext;
5224  if (auto *Block = dyn_cast<BlockDecl>(Caller)) {
5225  IsVariadic = Block->isVariadic();
5226  Params = Block->parameters();
5227  } else if (auto *FD = dyn_cast<FunctionDecl>(Caller)) {
5228  IsVariadic = FD->isVariadic();
5229  Params = FD->parameters();
5230  } else if (auto *MD = dyn_cast<ObjCMethodDecl>(Caller)) {
5231  IsVariadic = MD->isVariadic();
5232  // FIXME: This isn't correct for methods (results in bogus warning).
5233  Params = MD->parameters();
5234  } else if (isa<CapturedDecl>(Caller)) {
5235  // We don't support va_start in a CapturedDecl.
5236  S.Diag(Fn->getBeginLoc(), diag::err_va_start_captured_stmt);
5237  return true;
5238  } else {
5239  // This must be some other declcontext that parses exprs.
5240  S.Diag(Fn->getBeginLoc(), diag::err_va_start_outside_function);
5241  return true;
5242  }
5243 
5244  if (!IsVariadic) {
5245  S.Diag(Fn->getBeginLoc(), diag::err_va_start_fixed_function);
5246  return true;
5247  }
5248 
5249  if (LastParam)
5250  *LastParam = Params.empty() ? nullptr : Params.back();
5251 
5252  return false;
5253 }
5254 
5255 /// Check the arguments to '__builtin_va_start' or '__builtin_ms_va_start'
5256 /// for validity. Emit an error and return true on failure; return false
5257 /// on success.
5258 bool Sema::SemaBuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) {
5259  Expr *Fn = TheCall->getCallee();
5260 
5261  if (checkVAStartABI(*this, BuiltinID, Fn))
5262  return true;
5263 
5264  if (TheCall->getNumArgs() > 2) {
5265  Diag(TheCall->getArg(2)->getBeginLoc(),
5266  diag::err_typecheck_call_too_many_args)
5267  << 0 /*function call*/ << 2 << TheCall->getNumArgs()
5268  << Fn->getSourceRange()
5269  << SourceRange(TheCall->getArg(2)->getBeginLoc(),
5270  (*(TheCall->arg_end() - 1))->getEndLoc());
5271  return true;
5272  }
5273 
5274  if (TheCall->getNumArgs() < 2) {
5275  return Diag(TheCall->getEndLoc(),
5276  diag::err_typecheck_call_too_few_args_at_least)
5277  << 0 /*function call*/ << 2 << TheCall->getNumArgs();
5278  }
5279 
5280  // Type-check the first argument normally.
5281  if (checkBuiltinArgument(*this, TheCall, 0))
5282  return true;
5283 
5284  // Check that the current function is variadic, and get its last parameter.
5285  ParmVarDecl *LastParam;
5286  if (checkVAStartIsInVariadicFunction(*this, Fn, &LastParam))
5287  return true;
5288 
5289  // Verify that the second argument to the builtin is the last argument of the
5290  // current function or method.
5291  bool SecondArgIsLastNamedArgument = false;
5292  const Expr *Arg = TheCall->getArg(1)->IgnoreParenCasts();
5293 
5294  // These are valid if SecondArgIsLastNamedArgument is false after the next
5295  // block.
5296  QualType Type;
5297  SourceLocation ParamLoc;
5298  bool IsCRegister = false;
5299 
5300  if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(Arg)) {
5301  if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(DR->getDecl())) {
5302  SecondArgIsLastNamedArgument = PV == LastParam;
5303 
5304  Type = PV->getType();
5305  ParamLoc = PV->getLocation();
5306  IsCRegister =
5307  PV->getStorageClass() == SC_Register && !getLangOpts().CPlusPlus;
5308  }
5309  }
5310 
5311  if (!SecondArgIsLastNamedArgument)
5312  Diag(TheCall->getArg(1)->getBeginLoc(),
5313  diag::warn_second_arg_of_va_start_not_last_named_param);
5314  else if (IsCRegister || Type->isReferenceType() ||
5315  Type->isSpecificBuiltinType(BuiltinType::Float) || [=] {
5316  // Promotable integers are UB, but enumerations need a bit of
5317  // extra checking to see what their promotable type actually is.
5318  if (!Type->isPromotableIntegerType())
5319  return false;
5320  if (!Type->isEnumeralType())
5321  return true;
5322  const EnumDecl *ED = Type->getAs<EnumType>()->getDecl();
5323  return !(ED &&
5324  Context.typesAreCompatible(ED->getPromotionType(), Type));
5325  }()) {
5326  unsigned Reason = 0;
5327  if (Type->isReferenceType()) Reason = 1;
5328  else if (IsCRegister) Reason = 2;
5329  Diag(Arg->getBeginLoc(), diag::warn_va_start_type_is_undefined) << Reason;
5330  Diag(ParamLoc, diag::note_parameter_type) << Type;
5331  }
5332 
5333  TheCall->setType(Context.VoidTy);
5334  return false;
5335 }
5336 
5337 bool Sema::SemaBuiltinVAStartARMMicrosoft(CallExpr *Call) {
5338  // void __va_start(va_list *ap, const char *named_addr, size_t slot_size,
5339  // const char *named_addr);
5340 
5341  Expr *Func = Call->getCallee();
5342 
5343  if (Call->getNumArgs() < 3)
5344  return Diag(Call->getEndLoc(),
5345  diag::err_typecheck_call_too_few_args_at_least)
5346  << 0 /*function call*/ << 3 << Call->getNumArgs();
5347 
5348  // Type-check the first argument normally.
5349  if (checkBuiltinArgument(*this, Call, 0))
5350  return true;
5351 
5352  // Check that the current function is variadic.
5353  if (checkVAStartIsInVariadicFunction(*this, Func))
5354  return true;
5355 
5356  // __va_start on Windows does not validate the parameter qualifiers
5357 
5358  const Expr *Arg1 = Call->getArg(1)->IgnoreParens();
5359  const Type *Arg1Ty = Arg1->getType().getCanonicalType().getTypePtr();
5360 
5361  const Expr *Arg2 = Call->getArg(2)->IgnoreParens();
5362  const Type *Arg2Ty = Arg2->getType().getCanonicalType().getTypePtr();
5363 
5364  const QualType &ConstCharPtrTy =
5365  Context.getPointerType(Context.CharTy.withConst());
5366  if (!Arg1Ty->isPointerType() ||
5367  Arg1Ty->getPointeeType().withoutLocalFastQualifiers() != Context.CharTy)
5368  Diag(Arg1->getBeginLoc(), diag::err_typecheck_convert_incompatible)
5369  << Arg1->getType() << ConstCharPtrTy << 1 /* different class */
5370  << 0 /* qualifier difference */
5371  << 3 /* parameter mismatch */
5372  << 2 << Arg1->getType() << ConstCharPtrTy;
5373 
5374  const QualType SizeTy = Context.getSizeType();
5375  if (Arg2Ty->getCanonicalTypeInternal().withoutLocalFastQualifiers() != SizeTy)
5376  Diag(Arg2->getBeginLoc(), diag::err_typecheck_convert_incompatible)
5377  << Arg2->getType() << SizeTy << 1 /* different class */
5378  << 0 /* qualifier difference */
5379  << 3 /* parameter mismatch */
5380  << 3 << Arg2->getType() << SizeTy;
5381 
5382  return false;
5383 }
5384 
5385 /// SemaBuiltinUnorderedCompare - Handle functions like __builtin_isgreater and
5386 /// friends. This is declared to take (...), so we have to check everything.
5387 bool Sema::SemaBuiltinUnorderedCompare(CallExpr *TheCall) {
5388  if (TheCall->getNumArgs() < 2)
5389  return Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args)
5390  << 0 << 2 << TheCall->getNumArgs() /*function call*/;
5391  if (TheCall->getNumArgs() > 2)
5392  return Diag(TheCall->getArg(2)->getBeginLoc(),
5393  diag::err_typecheck_call_too_many_args)
5394  << 0 /*function call*/ << 2 << TheCall->getNumArgs()
5395  << SourceRange(TheCall->getArg(2)->getBeginLoc(),
5396  (*(TheCall->arg_end() - 1))->getEndLoc());
5397 
5398  ExprResult OrigArg0 = TheCall->getArg(0);
5399  ExprResult OrigArg1 = TheCall->getArg(1);
5400 
5401  // Do standard promotions between the two arguments, returning their common
5402  // type.
5403  QualType Res = UsualArithmeticConversions(OrigArg0, OrigArg1, false);
5404  if (OrigArg0.isInvalid() || OrigArg1.isInvalid())
5405  return