Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/generate-names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ void NameGenerator::MaybeUseAndBindName(BindingHash* bindings,
Index index,
std::string* str) {
if (!HasName(*str)) {
if (!HasName(name)) {
// An empty import or export name would produce a bare "$", which is not
// a valid identifier. Leave the name unset; the index-based pass that
// runs afterwards will give it a usable one.
return;
}
unsigned disambiguator = 0;
while (true) {
GenerateName(name, kInvalidIndex, disambiguator, str);
Expand Down
22 changes: 22 additions & 0 deletions test/roundtrip/generate-empty-export-name.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
;;; TOOL: run-roundtrip
;;; ARGS: --stdout --generate-names

(module
;; With no name section the generated names come from the exports. An empty
;; export name cannot be used as an identifier, since it would produce a bare
;; "$", so it has to be skipped: this func has no other export to take a name
;; from and falls back to an index-based name.
(func $f)
(export "" (func $f))

(func $g)
(export "named" (func $g))
)
(;; STDOUT ;;;
(module
(type $t0 (func))
(func $f0 (type $t0))
(func $named (type $t0))
(export "" (func $f0))
(export "named" (func $named)))
;;; STDOUT ;;)
14 changes: 7 additions & 7 deletions test/wasm2c/export-names.txt
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ DEFINE_TABLE_FILL(externref)
wasm_rt_tailcallee_t* next)
#endif

static void w2c_test__0(w2c_test*);
static void w2c_test_0x2A0x2F_0(w2c_test*);

FUNC_TYPE_T(w2c_test_t0) = "\x36\xa9\xe7\xf1\xc9\x5b\x82\xff\xb9\x97\x43\xe0\xc5\xc4\xce\x95\xd8\x3c\x9a\x43\x0a\xac\x59\xf8\x4e\xf3\xcb\xfa\xb6\x14\x50\x68";

Expand All @@ -941,7 +941,7 @@ void w2c_test_(w2c_test* instance) {
#endif
wasm_rt_segue_write_base((*instance->w2c_0x5Cmodule_import0x200x2A0x2F).data);
#endif
w2c_test__0(instance);
w2c_test_0x2A0x2F_0(instance);
#if WASM_RT_USE_SEGUE_FOR_THIS_MODULE && !WASM_RT_SEGUE_FREE_SEGMENT
wasm_rt_segue_write_base(segue_saved_base);
#endif
Expand All @@ -955,7 +955,7 @@ void w2c_test_0x2A0x2F(w2c_test* instance) {
#endif
wasm_rt_segue_write_base((*instance->w2c_0x5Cmodule_import0x200x2A0x2F).data);
#endif
w2c_test__0(instance);
w2c_test_0x2A0x2F_0(instance);
#if WASM_RT_USE_SEGUE_FOR_THIS_MODULE && !WASM_RT_SEGUE_FREE_SEGMENT
wasm_rt_segue_write_base(segue_saved_base);
#endif
Expand All @@ -969,7 +969,7 @@ void w2c_test_0x3F0x3F0x2F(w2c_test* instance) {
#endif
wasm_rt_segue_write_base((*instance->w2c_0x5Cmodule_import0x200x2A0x2F).data);
#endif
w2c_test__0(instance);
w2c_test_0x2A0x2F_0(instance);
#if WASM_RT_USE_SEGUE_FOR_THIS_MODULE && !WASM_RT_SEGUE_FREE_SEGMENT
wasm_rt_segue_write_base(segue_saved_base);
#endif
Expand All @@ -983,7 +983,7 @@ void w2c_test_0x0A(w2c_test* instance) {
#endif
wasm_rt_segue_write_base((*instance->w2c_0x5Cmodule_import0x200x2A0x2F).data);
#endif
w2c_test__0(instance);
w2c_test_0x2A0x2F_0(instance);
#if WASM_RT_USE_SEGUE_FOR_THIS_MODULE && !WASM_RT_SEGUE_FREE_SEGMENT
wasm_rt_segue_write_base(segue_saved_base);
#endif
Expand All @@ -997,7 +997,7 @@ void w2c_test_0xE20x9D0xA40xEF0xB80x8F(w2c_test* instance) {
#endif
wasm_rt_segue_write_base((*instance->w2c_0x5Cmodule_import0x200x2A0x2F).data);
#endif
w2c_test__0(instance);
w2c_test_0x2A0x2F_0(instance);
#if WASM_RT_USE_SEGUE_FOR_THIS_MODULE && !WASM_RT_SEGUE_FREE_SEGMENT
wasm_rt_segue_write_base(segue_saved_base);
#endif
Expand Down Expand Up @@ -1045,7 +1045,7 @@ wasm_rt_func_type_t wasm2c_test_get_func_type(uint32_t param_count, uint32_t res
return NULL;
}

void w2c_test__0(w2c_test* instance) {
void w2c_test_0x2A0x2F_0(w2c_test* instance) {
FUNC_PROLOGUE;
uint8_t* const wasm_rt_local_memory_base = (instance->w2c_0x5Cmodule_import0x200x2A0x2F)->data;
uint64_t wasm_rt_local_memory_size = (instance->w2c_0x5Cmodule_import0x200x2A0x2F)->size;
Expand Down
Loading