[Mlir-commits] [flang] [mlir] [mlir][func] Refactor FuncToLLVM discardable attributes algorithm (PR #188232)

Mehdi Amini llvmlistbot at llvm.org
Thu Mar 26 03:26:29 PDT 2026


================
@@ -3035,6 +3035,13 @@ void LLVMFuncOp::build(OpBuilder &builder, OperationState &result,
   if (functionEntryCount)
     result.addAttribute(getFunctionEntryCountAttrName(result.name),
                         builder.getI64IntegerAttr(functionEntryCount.value()));
+  std::optional<NamedAttribute> duplicate = result.attributes.findDuplicate();
+  if (duplicate.has_value()) {
+    llvm::report_fatal_error(
+        Twine("LLVMFuncOp propagated an attribute that is meant "
+              "to be constructed by the builder: ") +
+        duplicate->getName().str());
+  }
----------------
joker-eph wrote:

Looks like "assert behavior" to me?

So let's wrap it:


```suggestion
#ifndef NDEBUG
  std::optional<NamedAttribute> duplicate = result.attributes.findDuplicate();
  if (duplicate.has_value()) {
    llvm::report_fatal_error(
        Twine("LLVMFuncOp propagated an attribute that is meant "
              "to be constructed by the builder: ") +
        duplicate->getName().str());
  }
#endif
```

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


More information about the Mlir-commits mailing list