diff --git a/mlir/lib/Target/LLVMIR/TypeFromLLVM.cpp b/mlir/lib/Target/LLVMIR/TypeFromLLVM.cpp --- a/mlir/lib/Target/LLVMIR/TypeFromLLVM.cpp +++ b/mlir/lib/Target/LLVMIR/TypeFromLLVM.cpp @@ -112,14 +112,13 @@ if (type->isOpaque()) return LLVM::LLVMStructType::getOpaque(type->getName(), &context); - LLVM::LLVMStructType translated = - LLVM::LLVMStructType::getIdentified(&context, type->getName()); - knownTranslations.try_emplace(type, translated); + // With opaque pointers, types in LLVM can't be recursive anymore. Note that + // using getIdentified is not possible, as type names in LLVM are not + // guaranteed to be unique. translateTypes(type->subtypes(), subtypes); - LogicalResult bodySet = translated.setBody(subtypes, type->isPacked()); - assert(succeeded(bodySet) && - "could not set the body of an identified struct"); - (void)bodySet; + LLVM::LLVMStructType translated = LLVM::LLVMStructType::getNewIdentified( + &context, type->getName(), subtypes, type->isPacked()); + knownTranslations.try_emplace(type, translated); return translated; } diff --git a/mlir/test/Target/LLVMIR/Import/global-struct.ll b/mlir/test/Target/LLVMIR/Import/global-struct.ll new file mode 100644 --- /dev/null +++ b/mlir/test/Target/LLVMIR/Import/global-struct.ll @@ -0,0 +1,8 @@ +; RUN: mlir-translate --import-llvm %s | FileCheck %s + +; Ensure both structs have different names. +; CHECK: llvm.func @fn(!llvm.struct<"[[NAME:[^"]*]]", +; CHECK-NOT: struct<"[[NAME]]", +%0 = type { %1 } +%1 = type { i8 } +declare void @fn(%0)