Skip to content

Commit

Permalink
Add support for LLVM18
Browse files Browse the repository at this point in the history
Notes:
- Main breakage due to addition of clang::StringLiteralKind enum
  and addition of a new clang module: clangAPINotes.
- There doesn't seem to be a 18.0.0 release at this time
- scripts/build_transpiler.py doesn't build 18.1.1 cleanly
- scripts/test_transpiler.py encountered some failures.
- There is an unresolved linker error from libzstd on macOS.

Closes #1066.
  • Loading branch information
thedataking committed Mar 13, 2024
1 parent 31ec4e7 commit fcd8e17
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions c2rust-ast-exporter/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ fn build_native(llvm_info: &LLVMInfo) {
let sema_pos = clang_libs.iter().position(|&r| r == "clangSema").unwrap();
clang_libs.insert(sema_pos + 1, "clangSupport");
}
if llvm_info.llvm_major_version >= 18 {
// insert after clangSupport
let sema_pos = clang_libs.iter().position(|&r| r == "clangSupport").unwrap();
clang_libs.insert(sema_pos + 1, "clangAPINotes");
}

for lib in &clang_libs {
println!("cargo:rustc-link-lib={}", lib);
Expand Down
24 changes: 23 additions & 1 deletion c2rust-ast-exporter/src/AstExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2298,27 +2298,49 @@ class TranslateASTVisitor final
// C and C++ supports different string types, so
// we need to identify the string literal type
switch (SL->getKind()) {
#if CLANG_VERSION_MAJOR >= 15
#if CLANG_VERSION_MAJOR >= 18
case clang::StringLiteralKind::Ordinary:
#elif CLANG_VERSION_MAJOR >= 15
case clang::StringLiteral::StringKind::Ordinary:
#else
case clang::StringLiteral::StringKind::Ascii:
#endif // CLANG_VERSION_MAJOR
cbor_encode_uint(array, StringTypeTag::TagAscii);
break;
#if CLANG_VERSION_MAJOR >= 18
case clang::StringLiteralKind::Wide:
#else
case clang::StringLiteral::StringKind::Wide:
#endif // CLANG_VERSION_MAJOR
cbor_encode_uint(array, StringTypeTag::TagWide);
break;
#if CLANG_VERSION_MAJOR >= 18
case clang::StringLiteralKind::UTF8:
#else
case clang::StringLiteral::StringKind::UTF8:
#endif // CLANG_VERSION_MAJOR
cbor_encode_uint(array, StringTypeTag::TagUTF8);
break;
#if CLANG_VERSION_MAJOR >= 18
case clang::StringLiteralKind::UTF16:
#else
case clang::StringLiteral::StringKind::UTF16:
#endif // CLANG_VERSION_MAJOR
cbor_encode_uint(array, StringTypeTag::TagUTF16);
break;
#if CLANG_VERSION_MAJOR >= 18
case clang::StringLiteralKind::UTF32:
#else
case clang::StringLiteral::StringKind::UTF32:
#endif // CLANG_VERSION_MAJOR
cbor_encode_uint(array, StringTypeTag::TagUTF32);
break;
#if CLANG_VERSION_MAJOR >= 17
#if CLANG_VERSION_MAJOR >= 18
case clang::StringLiteralKind::Unevaluated:
#else // CLANG_VERSION_MAJOR >= 17
case clang::StringLiteral::StringKind::Unevaluated:
#endif
cbor_encode_uint(array, StringTypeTag::TagUnevaluated);
break;
#endif // CLANG_VERSION_MAJOR
Expand Down

0 comments on commit fcd8e17

Please sign in to comment.