From 720b7b5fbdcd8d39249e430997f3fdf17e7b11ea Mon Sep 17 00:00:00 2001 From: Shiroki Satsuki Date: Sun, 18 May 2025 08:51:49 +0800 Subject: [PATCH 1/2] Fix getBitWidthValue compilation error on LLVM 20+ Introduced by upstream in https://github.com/llvm/llvm-project/pull/122289 Ref: https://github.com/iovisor/bcc/pull/5194 --- c2rust-ast-exporter/src/AstExporter.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/c2rust-ast-exporter/src/AstExporter.cpp b/c2rust-ast-exporter/src/AstExporter.cpp index 63b8a2ceb4..cd01c5701f 100644 --- a/c2rust-ast-exporter/src/AstExporter.cpp +++ b/c2rust-ast-exporter/src/AstExporter.cpp @@ -2213,8 +2213,12 @@ class TranslateASTVisitor final // 2. Encode bitfield width if any if (D->isBitField()) { +#if LLVM_VERSION_MAJOR >= 20 + cbor_encode_uint(array, D->getBitWidthValue()); +#else cbor_encode_uint( array, D->getBitWidthValue(*this->Context)); +#endif } else { cbor_encode_null(array); }; From bc656a7be2d838f42d9d9fa8ec2b8061ae926c72 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Mon, 19 May 2025 02:00:32 -0700 Subject: [PATCH 2/2] c2rust-ast-exporter: refactor `cbor_encode_uint` call out of `#if` with `bitWidthValue` var --- c2rust-ast-exporter/src/AstExporter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/c2rust-ast-exporter/src/AstExporter.cpp b/c2rust-ast-exporter/src/AstExporter.cpp index cd01c5701f..bd02943d33 100644 --- a/c2rust-ast-exporter/src/AstExporter.cpp +++ b/c2rust-ast-exporter/src/AstExporter.cpp @@ -2214,11 +2214,11 @@ class TranslateASTVisitor final // 2. Encode bitfield width if any if (D->isBitField()) { #if LLVM_VERSION_MAJOR >= 20 - cbor_encode_uint(array, D->getBitWidthValue()); + const auto bitWidthValue = D->getBitWidthValue(); #else - cbor_encode_uint( - array, D->getBitWidthValue(*this->Context)); + const auto bitWidthValue = D->getBitWidthValue(*this->Context); #endif + cbor_encode_uint(array, bitWidthValue); } else { cbor_encode_null(array); };