33 const auto *ATy = dyn_cast<ArrayType>(ArgExpr->
getType());
34 if (!ATy || !ATy->getElementType().isWebAssemblyReferenceType()) {
36 diag::err_wasm_builtin_arg_must_be_table_type)
39 ElTy = ATy->getElementType();
44 unsigned TableIndex,
unsigned ArgIndex) {
50 diag::err_wasm_builtin_arg_must_match_table_element_type)
51 << (ArgIndex + 1) << (TableIndex + 1)
63 diag::err_wasm_builtin_arg_must_be_integer_type)
70 if (
SemaRef.checkArgCount(TheCall, 0))
78 if (
SemaRef.checkArgCount(TheCall, 1)) {
85 diag::err_wasm_builtin_arg_must_be_externref_type)
95 if (
SemaRef.checkArgCount(TheCall, 0))
100 QualType Pointee = Context.getFunctionType(Context.VoidTy, {}, {});
103 Type = Context.getAttributedType(attr::WebAssemblyFuncref,
Type,
104 Context.getPointerType(Pointee));
113 if (
SemaRef.checkArgCount(TheCall, 2))
136 if (
SemaRef.checkArgCount(TheCall, 3))
154 if (
SemaRef.checkArgCount(TheCall, 1))
168 if (
SemaRef.checkArgCount(TheCall, 3))
188 if (
SemaRef.checkArgCount(TheCall, 4))
211 if (
SemaRef.checkArgCount(TheCall, 5))
225 diag::err_wasm_builtin_arg_must_match_table_element_type)
229 for (
int I = 2; I <= 4; I++) {
239 if (
SemaRef.checkArgCount(TheCall, 1))
249 diag::err_typecheck_expect_function_pointer)
257 diag::err_typecheck_expect_function_pointer)
261 if (TI.
getABI() ==
"experimental-mv") {
263 return T->isUnionType() ||
T->isStructureType();
269 err_wasm_builtin_test_fp_sig_cannot_include_struct_or_union)
273 for (
unsigned I = 0; I < NParams; I++) {
278 err_wasm_builtin_test_fp_sig_cannot_include_struct_or_union)
293 case WebAssembly::BI__builtin_wasm_ref_null_extern:
295 case WebAssembly::BI__builtin_wasm_ref_null_func:
297 case WebAssembly::BI__builtin_wasm_ref_is_null_extern:
299 case WebAssembly::BI__builtin_wasm_table_get:
301 case WebAssembly::BI__builtin_wasm_table_set:
303 case WebAssembly::BI__builtin_wasm_table_size:
305 case WebAssembly::BI__builtin_wasm_table_grow:
307 case WebAssembly::BI__builtin_wasm_table_fill:
309 case WebAssembly::BI__builtin_wasm_table_copy:
311 case WebAssembly::BI__builtin_wasm_test_function_pointer_signature:
318WebAssemblyImportModuleAttr *
320 const WebAssemblyImportModuleAttr &AL) {
321 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
322 if (
const auto *ExistingAttr = FD->getAttr<WebAssemblyImportModuleAttr>()) {
323 if (ExistingAttr->getImportModule() == AL.getImportModule())
325 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_import)
326 << 0 << ExistingAttr->getImportModule() << AL.getImportModule();
327 Diag(AL.getLoc(), diag::note_previous_attribute);
331 Diag(AL.getLoc(), diag::warn_import_on_definition) << 0 << 0;
334 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
335 if (
const auto *ExistingAttr = VD->getAttr<WebAssemblyImportModuleAttr>()) {
336 if (ExistingAttr->getImportModule() == AL.getImportModule())
338 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_import)
339 << 0 << ExistingAttr->getImportModule() << AL.getImportModule();
340 Diag(AL.getLoc(), diag::note_previous_attribute);
344 Diag(AL.getLoc(), diag::warn_import_on_definition) << 0 << 1;
349 WebAssemblyImportModuleAttr(
getASTContext(), AL, AL.getImportModule());
352WebAssemblyImportNameAttr *
354 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
355 if (
const auto *ExistingAttr = FD->getAttr<WebAssemblyImportNameAttr>()) {
356 if (ExistingAttr->getImportName() == AL.getImportName())
358 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_import)
359 << 1 << ExistingAttr->getImportName() << AL.getImportName();
360 Diag(AL.getLoc(), diag::note_previous_attribute);
364 Diag(AL.getLoc(), diag::warn_import_on_definition) << 1 << 0;
367 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
368 if (
const auto *ExistingAttr = VD->getAttr<WebAssemblyImportNameAttr>()) {
369 if (ExistingAttr->getImportName() == AL.getImportName())
371 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_import)
372 << 1 << ExistingAttr->getImportName() << AL.getImportName();
373 Diag(AL.getLoc(), diag::note_previous_attribute);
377 Diag(AL.getLoc(), diag::warn_import_on_definition) << 1 << 1;
382 WebAssemblyImportNameAttr(
getASTContext(), AL, AL.getImportName());
385WebAssemblyExportNameAttr *
387 if (
const auto *ExistingAttr = D->
getAttr<WebAssemblyExportNameAttr>()) {
388 if (ExistingAttr->getExportName() == AL.getExportName())
390 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_import)
391 << 2 << ExistingAttr->getExportName() << AL.getExportName();
392 Diag(AL.getLoc(), diag::note_previous_attribute);
396 WebAssemblyExportNameAttr(
getASTContext(), AL, AL.getExportName());
403 if (!
SemaRef.checkStringLiteralArgumentAttr(AL, 0, Str, &ArgLoc))
406 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
408 Diag(AL.
getLoc(), diag::warn_import_on_definition) << 0 << 0;
416 Diag(AL.
getLoc(), diag::warn_import_on_definition) << 0 << 1;
427 if (!
SemaRef.checkStringLiteralArgumentAttr(AL, 0, Str, &ArgLoc))
430 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
432 Diag(AL.
getLoc(), diag::warn_import_on_definition) << 1 << 0;
440 Diag(AL.
getLoc(), diag::warn_import_on_definition) << 1 << 1;
453 if (!
SemaRef.checkStringLiteralArgumentAttr(AL, 0, Str, &ArgLoc))
456 D->
addAttr(::new (Context) WebAssemblyExportNameAttr(Context, AL, Str));
457 D->
addAttr(UsedAttr::CreateImplicit(Context));
Defines the clang::ASTContext interface.
Provides definitions for the various language-specific address spaces.
This file declares semantic analysis functions specific to Wasm.
Enumerates target-specific builtins in their own namespaces within namespace clang.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
static bool hasSameType(QualType T1, QualType T2)
Determine whether the given types T1 and T2 are equivalent.
SourceLocation getLoc() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Decl - This represents one declaration (or definition), e.g.
This represents one expression.
Represents a prototype with parameter type info, e.g.
unsigned getNumParams() const
QualType getParamType(unsigned i) const
QualType getReturnType() const
ParsedAttr - Represents a syntactic attribute.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isWebAssemblyExternrefType() const
Returns true if it is a WebAssembly Externref Type.
ASTContext & getASTContext() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
void handleWebAssemblyImportNameAttr(Decl *D, const ParsedAttr &AL)
bool BuiltinWasmRefNullExtern(CallExpr *TheCall)
bool CheckWebAssemblyBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, CallExpr *TheCall)
bool BuiltinWasmTableGet(CallExpr *TheCall)
Check that the first argument is a WebAssembly table, and the second is an index to use as index into...
bool BuiltinWasmTableFill(CallExpr *TheCall)
Check that the first argument is a WebAssembly table, the second is an integer, the third is the valu...
bool BuiltinWasmTableSize(CallExpr *TheCall)
Check that the argument is a WebAssembly table.
void handleWebAssemblyImportModuleAttr(Decl *D, const ParsedAttr &AL)
bool BuiltinWasmRefNullFunc(CallExpr *TheCall)
bool BuiltinWasmTestFunctionPointerSignature(const TargetInfo &TI, CallExpr *TheCall)
WebAssemblyExportNameAttr * mergeExportNameAttr(Decl *D, const WebAssemblyExportNameAttr &AL)
bool BuiltinWasmTableSet(CallExpr *TheCall)
Check that the first argument is a WebAssembly table, the second is an index to use as index into the...
bool BuiltinWasmRefIsNullExtern(CallExpr *TheCall)
void handleWebAssemblyExportNameAttr(Decl *D, const ParsedAttr &AL)
WebAssemblyImportNameAttr * mergeImportNameAttr(Decl *D, const WebAssemblyImportNameAttr &AL)
WebAssemblyImportModuleAttr * mergeImportModuleAttr(Decl *D, const WebAssemblyImportModuleAttr &AL)
bool BuiltinWasmTableGrow(CallExpr *TheCall)
Check that the first argument is a WebAssembly table, the second is the value to use for new elements...
bool BuiltinWasmTableCopy(CallExpr *TheCall)
Check that the first argument is a WebAssembly table, the second is also a WebAssembly table (of the ...
Sema - This implements semantic analysis and AST building for C.
ASTContext & getASTContext() const
Encodes a location in the source.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
Exposes information about the current target.
virtual StringRef getABI() const
Get the ABI currently in use.
The base class of the type hierarchy.
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
const T * getAs() const
Member-template getAs<specific type>'.
@ DeclarationOnly
This declaration is only a declaration.
Defines the clang::TargetInfo interface.
Top level wrappers for InstallAPI frontend operations.
static bool CheckWasmTableElement(Sema &S, QualType &ElTy, CallExpr *E, unsigned TableIndex, unsigned ArgIndex)
static bool CheckWasmBuiltinArgIsTable(Sema &S, CallExpr *E, unsigned ArgIndex, QualType &ElTy)
Checks the argument at the given index is a WebAssembly table and if it is, sets ElTy to the element ...
static bool CheckWasmBuiltinArgIsInteger(Sema &S, CallExpr *E, unsigned ArgIndex)
Checks the argument at the given index is an integer.
const FunctionProtoType * T
U cast(CodeGen::Address addr)