Author: Anutosh Bhat
Date: 2025-08-20T14:14:19Z
New Revision: ea634fef562ce8c4403966dcb3e63a234c3b266f

URL: 
https://github.com/llvm/llvm-project/commit/ea634fef562ce8c4403966dcb3e63a234c3b266f
DIFF: 
https://github.com/llvm/llvm-project/commit/ea634fef562ce8c4403966dcb3e63a234c3b266f.diff

LOG: [clang-repl] Fix InstantiateTemplate & Value test while building against 
emscripten (#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)
```

This is similar to how we need to take care of some symbols while
building side modules during running cppinterop's test suite !

Added: 
    

Modified: 
    clang/unittests/Interpreter/CMakeLists.txt
    clang/unittests/Interpreter/InterpreterTest.cpp

Removed: 
    


################################################################################
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);
 


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to