[Mlir-commits] [mlir] f4ad12c - [mlir][LLVMIR] Validate profile format metadata (#220582)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Sep 3 00:42:22 PDT 2026
Author: Mehdi Amini
Date: 2026-09-03T09:42:17+02:00
New Revision: f4ad12c3e4371874aaf40078785fb3d00a664aa0
URL: https://github.com/llvm/llvm-project/commit/f4ad12c3e4371874aaf40078785fb3d00a664aa0
DIFF: https://github.com/llvm/llvm-project/commit/f4ad12c3e4371874aaf40078785fb3d00a664aa0.diff
LOG: [mlir][LLVMIR] Validate profile format metadata (#220582)
Added:
Modified:
mlir/lib/Target/LLVMIR/ModuleImport.cpp
mlir/test/Target/LLVMIR/Import/import-failure.ll
Removed:
################################################################################
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index bb85fe8c77b32..b6ef1503acc22 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -754,7 +754,20 @@ convertProfileSummaryFormat(ModuleOp mlirModule, const llvm::Module *llvmModule,
return std::nullopt;
}
- llvm::MDString *valMD = dyn_cast<llvm::MDString>(tupleEntry->getOperand(1));
+ llvm::Metadata *valueMD = tupleEntry->getOperand(1).get();
+ if (!valueMD) {
+ emitWarning(mlirModule.getLoc())
+ << "expected string metadata value for key 'ProfileFormat': null";
+ return std::nullopt;
+ }
+
+ llvm::MDString *valMD = dyn_cast<llvm::MDString>(valueMD);
+ if (!valMD) {
+ emitWarning(mlirModule.getLoc())
+ << "expected string metadata value for key 'ProfileFormat': "
+ << diagMD(valueMD, llvmModule);
+ return std::nullopt;
+ }
std::optional<ProfileSummaryFormatKind> fmtKind =
symbolizeProfileSummaryFormatKind(valMD->getString());
if (!fmtKind) {
diff --git a/mlir/test/Target/LLVMIR/Import/import-failure.ll b/mlir/test/Target/LLVMIR/Import/import-failure.ll
index ba854d8616144..9015eff87a8c7 100644
--- a/mlir/test/Target/LLVMIR/Import/import-failure.ll
+++ b/mlir/test/Target/LLVMIR/Import/import-failure.ll
@@ -533,3 +533,37 @@ define i32 @metadata_ref_global_dtors() {
}
!0 = !{ptr @llvm.global_dtors}
+
+; // -----
+
+; CHECK: warning: expected string metadata value for key 'ProfileFormat'
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"ProfileSummary", !1}
+!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
+!2 = !{!"ProfileFormat", i64 0}
+!3 = !{!"TotalCount", i64 1}
+!4 = !{!"MaxCount", i64 1}
+!5 = !{!"MaxInternalCount", i64 1}
+!6 = !{!"MaxFunctionCount", i64 1}
+!7 = !{!"NumCounts", i64 1}
+!8 = !{!"NumFunctions", i64 1}
+!9 = !{!"DetailedSummary", !10}
+!10 = !{!11}
+!11 = !{i32 10000, i64 1, i32 1}
+
+; // -----
+
+; CHECK: warning: expected string metadata value for key 'ProfileFormat': null
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"ProfileSummary", !1}
+!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
+!2 = !{!"ProfileFormat", null}
+!3 = !{!"TotalCount", i64 1}
+!4 = !{!"MaxCount", i64 1}
+!5 = !{!"MaxInternalCount", i64 1}
+!6 = !{!"MaxFunctionCount", i64 1}
+!7 = !{!"NumCounts", i64 1}
+!8 = !{!"NumFunctions", i64 1}
+!9 = !{!"DetailedSummary", !10}
+!10 = !{!11}
+!11 = !{i32 10000, i64 1, i32 1}
More information about the Mlir-commits
mailing list