[clang] [cir-translate] Fix crash issue where the data layout string is missing (PR #147209)

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 9 07:08:05 PDT 2025


================
@@ -82,12 +85,17 @@ llvm::LogicalResult prepareCIRModuleDataLayout(mlir::ModuleOp mod,
 
   // Data layout is fully determined by the target triple. Here we only pass the
   // triple to get the data layout.
+  llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagID(
+      new clang::DiagnosticIDs);
+  clang::DiagnosticOptions diagOpts;
+  clang::DiagnosticsEngine diagnostics(diagID, diagOpts,
+                                       new clang::IgnoringDiagConsumer());
   llvm::Triple triple(rawTriple);
   clang::TargetOptions targetOptions;
   targetOptions.Triple = rawTriple;
   // FIXME: AllocateTarget is a big deal. Better make it a global state.
-  std::unique_ptr<clang::TargetInfo> targetInfo =
-      clang::targets::AllocateTarget(llvm::Triple(rawTriple), targetOptions);
+  llvm::IntrusiveRefCntPtr<clang::TargetInfo> targetInfo =
+      clang::TargetInfo::CreateTargetInfo(diagnostics, targetOptions);
----------------
bcardosolopes wrote:

re `IntrusiveRefCntPtr`: yea, I see other examples around now.

https://github.com/llvm/llvm-project/pull/147209


More information about the cfe-commits mailing list