Repository: immunant/c2rust (language: rust)

Issue:
Darwin build is broken with LLVM 17
I have observed this locally after updating MacOS to Sonoma, and it is also happening on CI: https://dev.azure.com/immunant/c2rust/_build/results?buildId=3921&view=logs&j=02bad918-85c8-5a4b-30eb-93cb7f58f78e&t=4e141b9f-cf66-5021-c262-96c31d2de06c

Locally, this can be worked around by installing LLVM 16 via Homebrew:
```
brew install llvm@16
```
and building c2rust with:
```
export LLVM_CONFIG_PATH=/opt/homebrew/opt/llvm@16/bin/llvm-config
```

Darwin build is broken with LLVM 17
I have observed this locally after updating MacOS to Sonoma, and it is also happening on CI: https://dev.azure.com/immunant/c2rust/_build/results?buildId=3921&view=logs&j=02bad918-85c8-5a4b-30eb-93cb7f58f78e&t=4e141b9f-cf66-5021-c262-96c31d2de06c

Locally, this can be worked around by installing LLVM 16 via Homebrew:
```
brew install llvm@16
```
and building c2rust with:
```
export LLVM_CONFIG_PATH=/opt/homebrew/opt/llvm@16/bin/llvm-config
```



Discussion / hints:

Fix patch:
diff --git a/c2rust-ast-exporter/src/AstExporter.cpp b/c2rust-ast-exporter/src/AstExporter.cpp
index b58308e51f..548e6e8fef 100644
--- a/c2rust-ast-exporter/src/AstExporter.cpp
+++ b/c2rust-ast-exporter/src/AstExporter.cpp
@@ -85,6 +85,7 @@ std::string make_realpath(std::string const &path) {
 }
 
 // Helper to smooth out differences between versions of clang
+#if CLANG_VERSION_MAJOR < 17
 Optional<APSInt> getIntegerConstantExpr(const Expr &E, const ASTContext &Ctx) {
 #if CLANG_VERSION_MAJOR < 12
     APSInt value;
@@ -96,6 +97,13 @@ Optional<APSInt> getIntegerConstantExpr(const Expr &E, const ASTContext &Ctx) {
     return E.getIntegerConstantExpr(Ctx);
 #endif // CLANG_VERSION_MAJOR
 }
+#else
+#include <optional>
+std::optional<APSInt> getIntegerConstantExpr(const Expr &E,
+                                             const ASTContext &Ctx) {
+    return E.getIntegerConstantExpr(Ctx);
+}
+#endif // CLANG_VERSION_MAJOR
 } // namespace
 
 class TranslateASTVisitor;
@@ -363,7 +371,7 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
                 }
             }();
             // All the SVE types present in Clang 10 are 128-bit vectors
-            // (see `AArch64SVEACLETypes.def`), so we can divide 128 
+            // (see `AArch64SVEACLETypes.def`), so we can divide 128
             // by their element size to get element count.
             auto ElemCount = 128 / Context->getTypeSize(ElemType);
 #endif // CLANG_VERSION_MAJOR >= 11
@@ -381,14 +389,6 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
 
         const TypeTag tag = [&] {
             switch (kind) {
-            default: {
-                auto pol = clang::PrintingPolicy(Context->getLangOpts());
-                auto warning = std::string("Encountered unsupported BuiltinType kind ") +
-                               std::to_string((int)kind) + " for type " +
-                               T->getName(pol).str();
-                printWarning(warning, clang::FullSourceLoc());
-                return TagTypeUnknown;
-            }
             case BuiltinType::BuiltinFn: return TagBuiltinFn;
             case BuiltinType::UInt128: return TagUInt128;
             case BuiltinType::Int128: return TagInt128;
@@ -403,10 +403,10 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
             // Constructed as a consequence of the conversion of
             // built-in to normal vector types.
             case BuiltinType::Float16: return TagHalf;
-            case BuiltinType::Half: return TagHalf;     
-            #if CLANG_VERSION_MAJOR >= 11
+            case BuiltinType::Half: return TagHalf;
+#if CLANG_VERSION_MAJOR >= 11
             case BuiltinType::BFloat16: return TagBFloat16;
-            #endif
+#endif
             case BuiltinType::Float: return TagFloat;
             case BuiltinType::Double: return TagDouble;
             case BuiltinType::LongDouble: return TagLongDouble;
@@ -418,6 +418,19 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
             case BuiltinType::Bool: return TagBool;
             case BuiltinType::WChar_S: return TagSWChar;
             case BuiltinType::WChar_U: return TagUWChar;
+#if CLANG_VERSION_MAJOR >= 16
+            case BuiltinType::SveCount: return TagSveCount;
+            case BuiltinType::SveBool: return TagSveBool;
+            case BuiltinType::SveBoolx2: return TagSveBoolx2;
+            case BuiltinType::SveBoolx4: return TagSveBoolx4;
+#endif
+            default:
+                auto pol = clang::PrintingPolicy(Context->getLangOpts());
+                auto warning = std::string("Encountered unsupported BuiltinType kind ") +
+                               std::to_string((int)kind) + " for type " +
+                               T->getName(pol).str();
+                printWarning(warning, clang::FullSourceLoc());
+                return TagTypeUnknown;
             }
         }();
 
@@ -1499,7 +1512,11 @@ class TranslateASTVisitor final
                         cbor_encoder_create_array(&array, &entry, 2);
                         cbor_encode_int(&entry, 2);
                         cbor_encode_uint(&entry,
+#if CLANG_VERSION_MAJOR < 17
                                          uintptr_t(designator.getField()));
+#else
+                                         uintptr_t(designator.getFieldDecl()));
+#endif // CLANG_VERSION_MAJOR
                     } else if (designator.isArrayRangeDesignator()) {
                         cbor_encoder_create_array(&array, &entry, 3);
                         cbor_encode_int(&entry, 3);
@@ -2300,6 +2317,11 @@ class TranslateASTVisitor final
             case clang::StringLiteral::StringKind::UTF32:
                 cbor_encode_uint(array, StringTypeTag::TagUTF32);
                 break;
+#if CLANG_VERSION_MAJOR >= 17
+            case clang::StringLiteral::StringKind::Unevaluated:
+                cbor_encode_uint(array, StringTypeTag::TagUnevaluated);
+                break;
+#endif // CLANG_VERSION_MAJOR
             }
             // The size of the wchar_t type in C is implementation defined
             cbor_encode_uint(array, SL->getCharByteWidth());
diff --git a/c2rust-ast-exporter/src/ast_tags.hpp b/c2rust-ast-exporter/src/ast_tags.hpp
index ab6e87344b..2027957d5f 100644
--- a/c2rust-ast-exporter/src/ast_tags.hpp
+++ b/c2rust-ast-exporter/src/ast_tags.hpp
@@ -142,6 +142,11 @@ enum TypeTag {
     TagComplexType,
     TagHalf,
     TagBFloat16,
+
+    TagSveCount,
+    TagSveBool,
+    TagSveBoolx2,
+    TagSveBoolx4,
 };
 
 enum StringTypeTag {
@@ -150,6 +155,7 @@ enum StringTypeTag {
     TagUTF8,
     TagUTF16,
     TagUTF32,
+    TagUnevaluated,
 };
 
 // From `clang/Basic/TargetInfo.h`
diff --git a/c2rust-transpile/src/c_ast/conversion.rs b/c2rust-transpile/src/c_ast/conversion.rs
index 26033bf0ae..440fa1a8a3 100644
--- a/c2rust-transpile/src/c_ast/conversion.rs
+++ b/c2rust-transpile/src/c_ast/conversion.rs
@@ -799,7 +799,16 @@ impl ConversionContext {
                 }
 
                 TypeTag::TagBFloat16 => {
-                    let ty = CTypeKind::BuiltinFn;
+                    let ty = CTypeKind::BFloat16;
+                    self.add_type(new_id, not_located(ty));
+                    self.processed_nodes.insert(new_id, OTHER_TYPE);
+                }
+
+                TypeTag::TagSveCount
+                | TypeTag::TagSveBool
+                | TypeTag::TagSveBoolx2
+                | TypeTag::TagSveBoolx4 => {
+                    let ty = CTypeKind::UnhandledSveType;
                     self.add_type(new_id, not_located(ty));
                     self.processed_nodes.insert(new_id, OTHER_TYPE);
                 }
diff --git a/c2rust-transpile/src/c_ast/iterators.rs b/c2rust-transpile/src/c_ast/iterators.rs
index 6817cf1e1a..22ba07e71c 100644
--- a/c2rust-transpile/src/c_ast/iterators.rs
+++ b/c2rust-transpile/src/c_ast/iterators.rs
@@ -285,7 +285,7 @@ fn immediate_type_children(kind: &CTypeKind) -> Vec<SomeId> {
         TypeOfExpr(e) => intos![e],
         Void | Bool | Short | Int | Long | LongLong | UShort | UInt | ULong | ULongLong | SChar
         | UChar | Char | Double | LongDouble | Float | Int128 | UInt128 | BuiltinFn | Half
-        | BFloat16 => {
+        | BFloat16 | UnhandledSveType => {
             vec![]
         }
 
diff --git a/c2rust-transpile/src/c_ast/mod.rs b/c2rust-transpile/src/c_ast/mod.rs
index 56b067f3e8..182b795812 100644
--- a/c2rust-transpile/src/c_ast/mod.rs
+++ b/c2rust-transpile/src/c_ast/mod.rs
@@ -1672,6 +1672,10 @@ pub enum CTypeKind {
 
     Half,
     BFloat16,
+
+    // ARM Scalable Vector Extention types
+    // TODO: represent all the individual types in AArch64SVEACLETypes.def
+    UnhandledSveType,
 }
 
 impl CTypeKind {
diff --git a/c2rust-transpile/src/translator/mod.rs b/c2rust-transpile/src/translator/mod.rs
index 91144d0f29..99dca9734e 100644
--- a/c2rust-transpile/src/translator/mod.rs
+++ b/c2rust-transpile/src/translator/mod.rs
@@ -4921,6 +4921,9 @@ impl<'c> Translation<'c> {
                 // Handled in `import_simd_typedef`
             }
             TypeOfExpr(_) | BuiltinFn => {}
+            UnhandledSveType => {
+                // TODO: handle SVE types
+            }
         }
     }
 


Test patch: