Bug Summary

File:tools/clang/lib/Sema/SemaChecking.cpp
Warning:line 586, column 7
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

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