Skip to content

Commit 5264f0e

Browse files
committed
Add first lot of compatibility changes with llvm 21
1 parent c88d0c1 commit 5264f0e

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

.github/workflows/emscripten.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ jobs:
227227
else
228228
# Apply patches
229229
llvm_vers=$(echo "${{ matrix.clang-runtime }}" | tr '[:lower:]' '[:upper:]')
230-
if [[ "${llvm_vers}" == "19" || "${llvm_vers}" == "20" ]]; then
230+
if [[ "${llvm_vers}" == "19" || "${llvm_vers}" == "20" || "${llvm_vers}" == "21" ]]; then
231231
git apply -v ../patches/llvm/emscripten-clang${{ matrix.clang-runtime }}-*.patch
232232
echo "Apply emscripten-clang${{ matrix.clang-runtime }}-*.patch patches:"
233233
fi
@@ -342,6 +342,11 @@ jobs:
342342
git apply -v Windows-emscripten-clang20-1-CrossCompile.patch
343343
git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch
344344
}
345+
elseif ( "${{ matrix.clang-runtime }}" -imatch "21" )
346+
{
347+
git apply -v Windows-emscripten-clang21-1-CrossCompile.patch
348+
git apply -v emscripten-clang21-2-shift-temporary-files-to-tmp-dir.patch
349+
}
345350
cd build
346351
echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:"
347352
emcmake cmake -DCMAKE_BUILD_TYPE=Release `

lib/CppInterOp/Compatibility.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ static inline char* GetEnv(const char* Var_Name) {
2727
#endif
2828
}
2929

30+
#if CLANG_VERSION_MAJOR < 21
31+
#define clang_LookupResult_Found clang::LookupResult::Found
32+
#define clang_LookupResult_Not_Found clang::LookupResult::NotFound
33+
#define clang_LookupResult_Found_Overloaded clang::LookupResult::FoundOverloaded ^~~~~~~~~~~~~~~
34+
#else
35+
#define clang_LookupResult_Found clang::LookupResultKind::Found
36+
#define clang_LookupResult_Not_Found clang::LookupResultKind::NotFound
37+
#define clang_LookupResult_Found_Overloaded clang::LookupResultKind::FoundOverloaded
38+
#endif
39+
3040
#if CLANG_VERSION_MAJOR < 19
3141
#define Template_Deduction_Result Sema::TemplateDeductionResult
3242
#define Template_Deduction_Result_Success \

lib/CppInterOp/CppInterOp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,16 +1107,16 @@ bool GetClassTemplatedMethods(const std::string& name, TCppScope_t parent,
11071107
auto* DC = clang::Decl::castToDeclContext(D);
11081108
Cpp_utils::Lookup::Named(&S, R, DC);
11091109

1110-
if (R.getResultKind() == clang::LookupResult::NotFound && funcs.empty())
1110+
if (R.getResultKind() == clang_LookupResult_Not_Found && funcs.empty())
11111111
return false;
11121112

11131113
// Distinct match, single Decl
1114-
else if (R.getResultKind() == clang::LookupResult::Found) {
1114+
else if (R.getResultKind() == clang_LookupResult_Found {
11151115
if (IsTemplatedFunction(R.getFoundDecl()))
11161116
funcs.push_back(R.getFoundDecl());
11171117
}
11181118
// Loop over overload set
1119-
else if (R.getResultKind() == clang::LookupResult::FoundOverloaded) {
1119+
else if (R.getResultKind() == clang_LookupResult_Found_Overloaded) {
11201120
for (auto* Found : R)
11211121
if (IsTemplatedFunction(Found))
11221122
funcs.push_back(Found);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
diff --git a/llvm/cmake/modules/CrossCompile.cmake b/llvm/cmake/modules/CrossCompile.cmake
2+
index 39b4abaa0..474ceddbb 100644
3+
--- a/llvm/cmake/modules/CrossCompile.cmake
4+
+++ b/llvm/cmake/modules/CrossCompile.cmake
5+
@@ -74,10 +74,12 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype)
6+
endif()
7+
8+
add_custom_command(OUTPUT ${${project_name}_${target_name}_BUILD}/CMakeCache.txt
9+
- COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
10+
+ COMMAND ${CMAKE_COMMAND} -G Ninja
11+
-DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}"
12+
- -DCMAKE_C_COMPILER_LAUNCHER="${CMAKE_C_COMPILER_LAUNCHER}"
13+
- -DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER}"
14+
+ -DCMAKE_C_COMPILER="clang-cl"
15+
+ -DCMAKE_CXX_COMPILER="clang-cl"
16+
+ -DCMAKE_ASM_MASM_COMPILER=llvm-ml
17+
+ -DCMAKE_ASM_MASM_FLAGS="-m64"
18+
${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_CURRENT_SOURCE_DIR}
19+
${CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name}}
20+
-DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp
2+
index aa10b160ccf8..184867e2b55f 100644
3+
--- a/clang/lib/Interpreter/Wasm.cpp
4+
+++ b/clang/lib/Interpreter/Wasm.cpp
5+
@@ -76,8 +76,8 @@ llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
6+
llvm::TargetMachine *TargetMachine = Target->createTargetMachine(
7+
PTU.TheModule->getTargetTriple(), "", "", TO, llvm::Reloc::Model::PIC_);
8+
PTU.TheModule->setDataLayout(TargetMachine->createDataLayout());
9+
- std::string ObjectFileName = PTU.TheModule->getName().str() + ".o";
10+
- std::string BinaryFileName = PTU.TheModule->getName().str() + ".wasm";
11+
+ std::string ObjectFileName = "/tmp/" + PTU.TheModule->getName().str() + ".o";
12+
+ std::string BinaryFileName = "/tmp/" + PTU.TheModule->getName().str() + ".wasm";
13+
14+
std::error_code Error;
15+
llvm::raw_fd_ostream ObjectFileOutput(llvm::StringRef(ObjectFileName), Error);

0 commit comments

Comments
 (0)