clang: lib/Sema/SemaWasm.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
22
24
26
27
28
31 Expr *ArgExpr = E->getArg(ArgIndex);
32 const auto *ATy = dyn_cast(ArgExpr->getType());
33 if (!ATy || !ATy->getElementType().isWebAssemblyReferenceType()) {
35 diag::err_wasm_builtin_arg_must_be_table_type)
37 }
38 ElTy = ATy->getElementType();
39 return false;
40}
41
42
44 unsigned ArgIndex) {
45 Expr *ArgExpr = E->getArg(ArgIndex);
48 diag::err_wasm_builtin_arg_must_be_integer_type)
50 }
51 return false;
52}
53
56 return true;
57
59
60 return false;
61}
62
66 Diag(TheCall->getBeginLoc(), diag::err_typecheck_call_too_many_args)
67 << 0 << 0 << TheCall->getNumArgs()
68 << 0;
69 return true;
70 }
71
72
73
74 QualType Pointee = Context.getFunctionType(Context.VoidTy, {}, {});
75 QualType Type = Context.getPointerType(Pointee);
77 Type = Context.getAttributedType(attr::WebAssemblyFuncref, Type,
78 Context.getPointerType(Pointee));
80
81 return false;
82}
83
84
85
88 return true;
89
92 return true;
93
95 return true;
96
97
98
99
100
102
103 return false;
104}
105
106
107
108
111 return true;
112
115 return true;
116
118 return true;
119
121 return true;
122
123 return false;
124}
125
126
129 return true;
130
133 return true;
134
135 return false;
136}
137
138
139
140
143 return true;
144
147 return true;
148
149 Expr *NewElemArg = TheCall->getArg(1);
152 diag::err_wasm_builtin_arg_must_match_table_element_type)
154 }
155
157 return true;
158
159 return false;
160}
161
162
163
164
167 return true;
168
171 return true;
172
174 return true;
175
176 Expr *NewElemArg = TheCall->getArg(2);
179 diag::err_wasm_builtin_arg_must_match_table_element_type)
181 }
182
184 return true;
185
186 return false;
187}
188
189
190
191
194 return true;
195
198 return true;
199
202 return true;
203
204 Expr *TableYArg = TheCall->getArg(1);
205 if (().hasSameType(XElTy, YElTy)) {
207 diag::err_wasm_builtin_arg_must_match_table_element_type)
209 }
210
211 for (int I = 2; I <= 4; I++) {
213 return true;
214 }
215
216 return false;
217}
218
220 unsigned BuiltinID,
222 switch (BuiltinID) {
223 case WebAssembly::BI__builtin_wasm_ref_null_extern:
225 case WebAssembly::BI__builtin_wasm_ref_null_func:
227 case WebAssembly::BI__builtin_wasm_table_get:
229 case WebAssembly::BI__builtin_wasm_table_set:
231 case WebAssembly::BI__builtin_wasm_table_size:
233 case WebAssembly::BI__builtin_wasm_table_grow:
235 case WebAssembly::BI__builtin_wasm_table_fill:
237 case WebAssembly::BI__builtin_wasm_table_copy:
239 }
240
241 return false;
242}
243
244WebAssemblyImportModuleAttr *
246 const WebAssemblyImportModuleAttr &AL) {
247 auto *FD = cast(D);
248
249 if (const auto *ExistingAttr = FD->getAttr()) {
250 if (ExistingAttr->getImportModule() == AL.getImportModule())
251 return nullptr;
252 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_import)
253 << 0 << ExistingAttr->getImportModule() << AL.getImportModule();
254 Diag(AL.getLoc(), diag::note_previous_attribute);
255 return nullptr;
256 }
257 if (FD->hasBody()) {
258 Diag(AL.getLoc(), diag::warn_import_on_definition) << 0;
259 return nullptr;
260 }
262 WebAssemblyImportModuleAttr(getASTContext(), AL, AL.getImportModule());
263}
264
265WebAssemblyImportNameAttr *
267 auto *FD = cast(D);
268
269 if (const auto *ExistingAttr = FD->getAttr()) {
270 if (ExistingAttr->getImportName() == AL.getImportName())
271 return nullptr;
272 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_import)
273 << 1 << ExistingAttr->getImportName() << AL.getImportName();
274 Diag(AL.getLoc(), diag::note_previous_attribute);
275 return nullptr;
276 }
277 if (FD->hasBody()) {
278 Diag(AL.getLoc(), diag::warn_import_on_definition) << 1;
279 return nullptr;
280 }
282 WebAssemblyImportNameAttr(getASTContext(), AL, AL.getImportName());
283}
284
287 auto *FD = cast(D);
288
289 StringRef Str;
292 return;
293 if (FD->hasBody()) {
294 Diag(AL.getLoc(), diag::warn_import_on_definition) << 0;
295 return;
296 }
297
299 WebAssemblyImportModuleAttr(getASTContext(), AL, Str));
300}
301
303 auto *FD = cast(D);
304
305 StringRef Str;
308 return;
309 if (FD->hasBody()) {
310 Diag(AL.getLoc(), diag::warn_import_on_definition) << 1;
311 return;
312 }
313
315 WebAssemblyImportNameAttr(getASTContext(), AL, Str));
316}
317
321 Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type)
323 return;
324 }
325
326 auto *FD = cast(D);
327 if (FD->isThisDeclarationADefinition()) {
328 Diag(D->getLocation(), diag::err_alias_is_definition) << FD << 0;
329 return;
330 }
331
332 StringRef Str;
335 return;
336
337 D->addAttr(::new (Context) WebAssemblyExportNameAttr(Context, AL, Str));
338 D->addAttr(UsedAttr::CreateImplicit(Context));
339}
340
341}
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 ...
bool isRegularKeywordAttribute() const
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.
SourceLocation getBeginLoc() const LLVM_READONLY
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Decl - This represents one declaration (or definition), e.g.
This represents one expression.
ParsedAttr - Represents a syntactic attribute.
A (possibly-)qualified type.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
ASTContext & getASTContext() const
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 BuiltinWasmTableSet(CallExpr *TheCall)
Check that the first argumnet is a WebAssembly table, the second is an index to use as index into the...
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.
bool checkArgCount(CallExpr *Call, unsigned DesiredArgCount)
Checks that a call expression's argument count is the desired number.
bool checkStringLiteralArgumentAttr(const AttributeCommonInfo &CI, const Expr *E, StringRef &Str, SourceLocation *ArgLocation=nullptr)
Check if the argument E is a ASCII string literal.
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.
The base class of the type hierarchy.
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
The JSON file list parser is used to communicate input to InstallAPI.
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.
bool isFuncOrMethodForAttrSubject(const Decl *D)
isFuncOrMethodForAttrSubject - Return true if the given decl has function type (function or function-...