Skip to content

Commit a2c2149

Browse files
authored
exporter: tag all SVE types w/ TagSve (unhandled) (#1417)
* Fixes #1252. This often crops up when compiling on aarch64. I'm not sure why it works fine in CI. There are a lot of SVE types and we were only handling a couple of them. Inside clang, this is done by `#include "clang/include/clang/Basic/AArch64ACLETypes.def"` and defining a macro beforehand, but we can't do that in an extern clang tool, so I just copied all of the variants from that file. Alternatively, we could vendor that file.
2 parents d00940c + fcb7ec9 commit a2c2149

File tree

4 files changed

+83
-29
lines changed

4 files changed

+83
-29
lines changed

c2rust-ast-exporter/build.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use c2rust_build_paths::find_llvm_config;
22
use cmake::Config;
33
use std::env;
4-
use std::ffi::OsStr;
4+
use std::ffi::{OsStr, OsString};
55
use std::path::{Path, PathBuf};
66
use std::process::{self, Command};
77

@@ -129,13 +129,13 @@ fn build_native(llvm_info: &LLVMInfo) {
129129
// Where to find LLVM/Clang CMake files
130130
.define(
131131
"LLVM_DIR",
132-
env::var("CMAKE_LLVM_DIR")
133-
.unwrap_or_else(|_| format!("{}/cmake/llvm", llvm_lib_dir)),
132+
env::var_os("CMAKE_LLVM_DIR")
133+
.unwrap_or_else(|| llvm_lib_dir.join("cmake/llvm").into()),
134134
)
135135
.define(
136136
"Clang_DIR",
137-
env::var("CMAKE_CLANG_DIR")
138-
.unwrap_or_else(|_| format!("{}/cmake/clang", llvm_lib_dir)),
137+
env::var_os("CMAKE_CLANG_DIR")
138+
.unwrap_or_else(|| llvm_lib_dir.join("cmake/clang").into()),
139139
)
140140
// What to build
141141
.build_target("clangAstExporter")
@@ -153,7 +153,7 @@ fn build_native(llvm_info: &LLVMInfo) {
153153
println!("cargo:rustc-link-lib=static=tinycbor");
154154
println!("cargo:rustc-link-lib=static=clangAstExporter");
155155

156-
println!("cargo:rustc-link-search=native={}", llvm_lib_dir);
156+
println!("cargo:rustc-link-search=native={}", llvm_lib_dir.display());
157157

158158
// Some distro's, including arch and Fedora, no longer build with
159159
// BUILD_SHARED_LIBS=ON; programs linking to clang are required to
@@ -231,7 +231,7 @@ fn build_native(llvm_info: &LLVMInfo) {
231231
/// Holds information about LLVM paths we have found
232232
struct LLVMInfo {
233233
/// LLVM lib dir containing libclang* and libLLVM* libraries
234-
pub lib_dir: String,
234+
pub lib_dir: PathBuf,
235235

236236
/// List of libs we need to link against
237237
pub libs: Vec<String>,
@@ -267,16 +267,12 @@ impl LLVMInfo {
267267
$ export LLVM_LIB_DIR=/usr/local/opt/llvm/lib
268268
";
269269
let lib_dir = {
270-
let path_str = env::var("LLVM_LIB_DIR")
271-
.ok()
272-
.or_else(|| invoke_command(llvm_config.as_deref(), ["--libdir"]))
270+
let path_str = env::var_os("LLVM_LIB_DIR")
271+
.or_else(|| {
272+
invoke_command(llvm_config.as_deref(), ["--libdir"]).map(OsString::from)
273+
})
273274
.expect(llvm_config_missing);
274-
String::from(
275-
Path::new(&path_str)
276-
.canonicalize()
277-
.unwrap()
278-
.to_string_lossy(),
279-
)
275+
Path::new(&path_str).canonicalize().unwrap()
280276
};
281277

282278
let llvm_shared_libs = invoke_command(llvm_config.as_deref(), ["--libs", "--link-shared"]);

c2rust-ast-exporter/src/AstExporter.cpp

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,11 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
448448
// built-in to normal vector types.
449449
case BuiltinType::Float16: return TagHalf;
450450
case BuiltinType::Half: return TagHalf;
451+
451452
#if CLANG_VERSION_MAJOR >= 11
452453
case BuiltinType::BFloat16: return TagBFloat16;
453454
#endif
455+
454456
case BuiltinType::Float: return TagFloat;
455457
case BuiltinType::Double: return TagDouble;
456458
case BuiltinType::LongDouble: return TagLongDouble;
@@ -462,13 +464,75 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
462464
case BuiltinType::Bool: return TagBool;
463465
case BuiltinType::WChar_S: return TagSWChar;
464466
case BuiltinType::WChar_U: return TagUWChar;
467+
465468
#if CLANG_VERSION_MAJOR >= 17
466-
case BuiltinType::SveCount: return TagSveCount;
467-
case BuiltinType::SveBool: return TagSveBool;
468-
case BuiltinType::SveBoolx2: return TagSveBoolx2;
469-
case BuiltinType::SveBoolx4: return TagSveBoolx4;
470469
case BuiltinType::Float128: return TagFloat128;
471-
#endif
470+
471+
// From `clang/include/clang/Basic/AArch64ACLETypes.def`,
472+
// but we can't `#include` it in an external clang tool.
473+
case BuiltinType::SveInt8:
474+
case BuiltinType::SveInt16:
475+
case BuiltinType::SveInt32:
476+
case BuiltinType::SveInt64:
477+
case BuiltinType::SveUint8:
478+
case BuiltinType::SveUint16:
479+
case BuiltinType::SveUint32:
480+
case BuiltinType::SveUint64:
481+
case BuiltinType::SveFloat16:
482+
case BuiltinType::SveFloat32:
483+
case BuiltinType::SveFloat64:
484+
case BuiltinType::SveBFloat16:
485+
case BuiltinType::SveInt8x2:
486+
case BuiltinType::SveInt16x2:
487+
case BuiltinType::SveInt32x2:
488+
case BuiltinType::SveInt64x2:
489+
case BuiltinType::SveUint8x2:
490+
case BuiltinType::SveUint16x2:
491+
case BuiltinType::SveUint32x2:
492+
case BuiltinType::SveUint64x2:
493+
case BuiltinType::SveFloat16x2:
494+
case BuiltinType::SveFloat32x2:
495+
case BuiltinType::SveFloat64x2:
496+
case BuiltinType::SveBFloat16x2:
497+
case BuiltinType::SveInt8x3:
498+
case BuiltinType::SveInt16x3:
499+
case BuiltinType::SveInt32x3:
500+
case BuiltinType::SveInt64x3:
501+
case BuiltinType::SveUint8x3:
502+
case BuiltinType::SveUint16x3:
503+
case BuiltinType::SveUint32x3:
504+
case BuiltinType::SveUint64x3:
505+
case BuiltinType::SveFloat16x3:
506+
case BuiltinType::SveFloat32x3:
507+
case BuiltinType::SveFloat64x3:
508+
case BuiltinType::SveBFloat16x3:
509+
case BuiltinType::SveInt8x4:
510+
case BuiltinType::SveInt16x4:
511+
case BuiltinType::SveInt32x4:
512+
case BuiltinType::SveInt64x4:
513+
case BuiltinType::SveUint8x4:
514+
case BuiltinType::SveUint16x4:
515+
case BuiltinType::SveUint32x4:
516+
case BuiltinType::SveUint64x4:
517+
case BuiltinType::SveFloat16x4:
518+
case BuiltinType::SveFloat32x4:
519+
case BuiltinType::SveFloat64x4:
520+
case BuiltinType::SveBFloat16x4:
521+
case BuiltinType::SveBool:
522+
case BuiltinType::SveBoolx2:
523+
case BuiltinType::SveBoolx4:
524+
case BuiltinType::SveCount:
525+
#endif // CLANG_VERSION_MAJOR >= 17
526+
527+
#if CLANG_VERSION_MAJOR >= 20
528+
case BuiltinType::MFloat8:
529+
case BuiltinType::SveMFloat8:
530+
case BuiltinType::SveMFloat8x2:
531+
case BuiltinType::SveMFloat8x3:
532+
case BuiltinType::SveMFloat8x4:
533+
#endif // CLANG_VERSION_MAJOR >= 20
534+
return TagSve;
535+
472536
default:
473537
auto pol = clang::PrintingPolicy(Context->getLangOpts());
474538
auto warning = std::string("Encountered unsupported BuiltinType kind ") +

c2rust-ast-exporter/src/ast_tags.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ enum TypeTag {
147147
TagHalf,
148148
TagBFloat16,
149149

150-
TagSveCount,
151-
TagSveBool,
152-
TagSveBoolx2,
153-
TagSveBoolx4,
150+
TagSve,
154151

155152
TagFloat128,
156153
TagAtomicType,

c2rust-transpile/src/c_ast/conversion.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -916,10 +916,7 @@ impl ConversionContext {
916916
self.processed_nodes.insert(new_id, OTHER_TYPE);
917917
}
918918

919-
TypeTag::TagSveCount
920-
| TypeTag::TagSveBool
921-
| TypeTag::TagSveBoolx2
922-
| TypeTag::TagSveBoolx4 => {
919+
TypeTag::TagSve => {
923920
let ty = CTypeKind::UnhandledSveType;
924921
self.add_type(new_id, not_located(ty));
925922
self.processed_nodes.insert(new_id, OTHER_TYPE);

0 commit comments

Comments
 (0)