[clang] Fix InstantiateTemplate & Value test while building against emscripten (PR #154513)
Anutosh Bhat via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 20 03:59:40 PDT 2025
https://github.com/anutosh491 created https://github.com/llvm/llvm-project/pull/154513
Building with assertions flag (-sAssertions=2) gives me these
```
[ RUN ] InterpreterTest.InstantiateTemplate Aborted(Assertion failed: undefined symbol '__clang_Interpreter_SetValueWithAlloc'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Error in loading dynamic library incr_module_3.wasm: RuntimeError: Aborted(Assertion failed: undefined symbol '__clang_Interpreter_SetValueWithAlloc'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Could not load dynamic lib: incr_module_3.wasm RuntimeError: Aborted(Assertion failed: undefined symbol '__clang_Interpreter_SetValueWithAlloc'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment)
[ RUN ] InterpreterTest.InstantiateTemplate Aborted(Assertion failed: undefined symbol '__clang_Interpreter_SetValueNoAlloc'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Error in loading dynamic library incr_module_3.wasm: RuntimeError: Aborted(Assertion failed: undefined symbol '__clang_Interpreter_SetValueNoAlloc'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Could not load dynamic lib: incr_module_3.wasm RuntimeError: Aborted(Assertion failed: undefined symbol '__clang_Interpreter_SetValueNoAlloc'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment)
[ RUN ] InterpreterTest.InstantiateTemplate Aborted(Assertion failed: undefined symbol '_ZnwmPv26__clang_Interpreter_NewTag'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Error in loading dynamic library incr_module_23.wasm: RuntimeError: Aborted(Assertion failed: undefined symbol '_ZnwmPv26__clang_Interpreter_NewTag'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Could not load dynamic lib: incr_module_23.wasm RuntimeError: Aborted(Assertion failed: undefined symbol '_ZnwmPv26__clang_Interpreter_NewTag'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment)
[ RUN ] InterpreterTest.Value Aborted(Assertion failed: undefined symbol '_Z9getGlobalv'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Error in loading dynamic library incr_module_36.wasm: RuntimeError: Aborted(Assertion failed: undefined symbol '_Z9getGlobalv'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Could not load dynamic lib: incr_module_36.wasm
[ RUN ] InterpreterTest.Value Aborted(Assertion failed: undefined symbol '_Z9getGlobalv'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Error in loading dynamic library incr_module_36.wasm: RuntimeError: Aborted(Assertion failed: undefined symbol '_Z9setGlobali'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Could not load dynamic lib: incr_module_36.wasm
```
**So we have some symbols missing here that are needed by the side modules being created here.**
First 2 are needed by both tests
Last 3 are needed for these lines accordingly in the Value test.
https://github.com/llvm/llvm-project/blob/dc23869f98452ca2c4086f12bb431a8d6fdb8169/clang/unittests/Interpreter/InterpreterTest.cpp#L355
https://github.com/llvm/llvm-project/blob/dc23869f98452ca2c4086f12bb431a8d6fdb8169/clang/unittests/Interpreter/InterpreterTest.cpp#L364
https://github.com/llvm/llvm-project/blob/dc23869f98452ca2c4086f12bb431a8d6fdb8169/clang/unittests/Interpreter/InterpreterTest.cpp#L365
Everything should work as expected after this
```
[----------] 9 tests from InterpreterTest
[ RUN ] InterpreterTest.Sanity
[ OK ] InterpreterTest.Sanity (18 ms)
[ RUN ] InterpreterTest.IncrementalInputTopLevelDecls
[ OK ] InterpreterTest.IncrementalInputTopLevelDecls (45 ms)
[ RUN ] InterpreterTest.Errors
[ OK ] InterpreterTest.Errors (29 ms)
[ RUN ] InterpreterTest.DeclsAndStatements
[ OK ] InterpreterTest.DeclsAndStatements (34 ms)
[ RUN ] InterpreterTest.UndoCommand
/Users/anutosh491/work/llvm-project/clang/unittests/Interpreter/InterpreterTest.cpp:156: Skipped
Test fails for Emscipten builds
[ SKIPPED ] InterpreterTest.UndoCommand (0 ms)
[ RUN ] InterpreterTest.FindMangledNameSymbol
[ OK ] InterpreterTest.FindMangledNameSymbol (85 ms)
[ RUN ] InterpreterTest.InstantiateTemplate
[ OK ] InterpreterTest.InstantiateTemplate (127 ms)
[ RUN ] InterpreterTest.Value
[ OK ] InterpreterTest.Value (608 ms)
[ RUN ] InterpreterTest.TranslationUnit_CanonicalDecl
[ OK ] InterpreterTest.TranslationUnit_CanonicalDecl (64 ms)
[----------] 9 tests from InterpreterTest (1014 ms total)
```
>From e5b449adbd6b4fad167ac700287591a4a8772c7b Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Wed, 20 Aug 2025 16:18:43 +0530
Subject: [PATCH] Fix InstantiateTemplate & Value test while building against
emscripten
---
clang/unittests/Interpreter/CMakeLists.txt | 5 +++++
clang/unittests/Interpreter/InterpreterTest.cpp | 16 ----------------
2 files changed, 5 insertions(+), 16 deletions(-)
diff --git a/clang/unittests/Interpreter/CMakeLists.txt b/clang/unittests/Interpreter/CMakeLists.txt
index b6825f9461ad7..db9f80d9f53fe 100644
--- a/clang/unittests/Interpreter/CMakeLists.txt
+++ b/clang/unittests/Interpreter/CMakeLists.txt
@@ -60,6 +60,11 @@ target_link_options(ClangReplInterpreterTests
PUBLIC "SHELL: -s STACK_SIZE=32mb"
PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
PUBLIC "SHELL: --emrun"
+ PUBLIC "SHELL: -Wl,--export=__clang_Interpreter_SetValueWithAlloc"
+ PUBLIC "SHELL: -Wl,--export=__clang_Interpreter_SetValueNoAlloc"
+ PUBLIC "SHELL: -Wl,--export=_ZnwmPv26__clang_Interpreter_NewTag"
+ PUBLIC "SHELL: -Wl,--export=_Z9getGlobalv"
+ PUBLIC "SHELL: -Wl,--export=_Z9setGlobali"
)
set_target_properties(ClangReplInterpreterTests PROPERTIES
SUFFIX ".html"
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index 8639fb668f1fe..9ff9092524d21 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -264,14 +264,6 @@ static NamedDecl *LookupSingleName(Interpreter &Interp, const char *Name) {
}
TEST_F(InterpreterTest, InstantiateTemplate) {
-// FIXME : This test doesn't current work for Emscripten builds.
-// It should be possible to make it work.For details on how it fails and
-// the current progress to enable this test see
-// the following Github issue https: //
-// github.com/llvm/llvm-project/issues/153461
-#ifdef __EMSCRIPTEN__
- GTEST_SKIP() << "Test fails for Emscipten builds";
-#endif
// FIXME: We cannot yet handle delayed template parsing. If we run with
// -fdelayed-template-parsing we try adding the newly created decl to the
// active PTU which causes an assert.
@@ -311,14 +303,6 @@ TEST_F(InterpreterTest, InstantiateTemplate) {
}
TEST_F(InterpreterTest, Value) {
-// FIXME : This test doesn't current work for Emscripten builds.
-// It should be possible to make it work.For details on how it fails and
-// the current progress to enable this test see
-// the following Github issue https: //
-// github.com/llvm/llvm-project/issues/153461
-#ifdef __EMSCRIPTEN__
- GTEST_SKIP() << "Test fails for Emscipten builds";
-#endif
std::vector<const char *> Args = {"-fno-sized-deallocation"};
std::unique_ptr<Interpreter> Interp = createInterpreter(Args);
More information about the cfe-commits
mailing list