================
@@ -8926,12 +8922,45 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD)
{
NewVD->setType(T);
}
+ // WebAssembly tables must be static with a zero length and can't be
+ // declared within functions.
+ if (T->isWebAssemblyTableType()) {
+ if (getCurScope()->getParent()) { // Parent is null at top-level
+ Diag(NewVD->getLocation(), diag::err_wasm_table_in_function);
+ NewVD->setInvalidDecl();
+ return;
+ }
+ if (NewVD->getStorageClass() != SC_Static) {
+ Diag(NewVD->getLocation(), diag::err_wasm_table_must_be_static);
+ NewVD->setInvalidDecl();
+ return;
+ }
+ const auto *ATy = dyn_cast<ConstantArrayType>(T.getTypePtr());
+ if (!ATy || ATy->getZExtSize() != 0) {
+ Diag(NewVD->getLocation(),
+ diag::err_typecheck_wasm_table_must_have_zero_length);
+ NewVD->setInvalidDecl();
+ return;
+ }
+ }
+
// Emit an error if an address space was applied to decl with local storage.
// This includes arrays of objects with address space qualifiers, but not
// automatic variables that point to other address spaces.
// ISO/IEC TR 18037 S5.1.2
- if (!getLangOpts().OpenCL && NewVD->hasLocalStorage() &&
- T.getAddressSpace() != LangAS::Default) {
+ if (T.isWebAssemblyReferenceType() &&
+ Context.getTargetInfo().getTriple().isWasm() && !T->isArrayType()) {
----------------
arsenm wrote:
Shouldn't need the triple check?
https://github.com/llvm/llvm-project/pull/197540
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits