[llvm] [IR] Add assertions for unchecked getAsInteger() calls in atrib merging (PR #194713)
JP Hafer via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 28 14:54:34 PDT 2026
https://github.com/jph-13 updated https://github.com/llvm/llvm-project/pull/194713
>From be9f0dbaab1ec7e8f049450995163139ce92e5ae Mon Sep 17 00:00:00 2001
From: Jason Hafer <jhafer at mathworks.com>
Date: Tue, 28 Apr 2026 15:52:53 -0400
Subject: [PATCH] [IR] Use getFnAttributeAsParsedInteger for attribute merging
Replace hand-rolled getAsInteger calls in adjustCallerStackProbeSize,
adjustMinLegalVectorWidth, and updateMinLegalVectorWidthAttr with
Function::getFnAttributeAsParsedInteger(). This produces a proper
error diagnostic instead of silently operating on uninitialized values
if an attribute string is not a valid integer.
---
llvm/lib/IR/Attributes.cpp | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 4087b25951a1c..63719711c1719 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -2686,9 +2686,10 @@ adjustCallerStackProbeSize(Function &Caller, const Function &Callee) {
if (CalleeAttr.isValid()) {
Attribute CallerAttr = Caller.getFnAttribute("stack-probe-size");
if (CallerAttr.isValid()) {
- uint64_t CallerStackProbeSize, CalleeStackProbeSize;
- CallerAttr.getValueAsString().getAsInteger(0, CallerStackProbeSize);
- CalleeAttr.getValueAsString().getAsInteger(0, CalleeStackProbeSize);
+ uint64_t CallerStackProbeSize =
+ Caller.getFnAttributeAsParsedInteger("stack-probe-size");
+ uint64_t CalleeStackProbeSize =
+ Callee.getFnAttributeAsParsedInteger("stack-probe-size");
if (CallerStackProbeSize > CalleeStackProbeSize) {
Caller.addFnAttr(CalleeAttr);
@@ -2714,9 +2715,10 @@ adjustMinLegalVectorWidth(Function &Caller, const Function &Callee) {
if (CallerAttr.isValid()) {
Attribute CalleeAttr = Callee.getFnAttribute("min-legal-vector-width");
if (CalleeAttr.isValid()) {
- uint64_t CallerVectorWidth, CalleeVectorWidth;
- CallerAttr.getValueAsString().getAsInteger(0, CallerVectorWidth);
- CalleeAttr.getValueAsString().getAsInteger(0, CalleeVectorWidth);
+ uint64_t CallerVectorWidth =
+ Caller.getFnAttributeAsParsedInteger("min-legal-vector-width");
+ uint64_t CalleeVectorWidth =
+ Callee.getFnAttributeAsParsedInteger("min-legal-vector-width");
if (CallerVectorWidth < CalleeVectorWidth)
Caller.addFnAttr(CalleeAttr);
} else {
@@ -2812,8 +2814,8 @@ void AttributeFuncs::updateMinLegalVectorWidthAttr(Function &Fn,
uint64_t Width) {
Attribute Attr = Fn.getFnAttribute("min-legal-vector-width");
if (Attr.isValid()) {
- uint64_t OldWidth;
- Attr.getValueAsString().getAsInteger(0, OldWidth);
+ uint64_t OldWidth =
+ Fn.getFnAttributeAsParsedInteger("min-legal-vector-width");
if (Width > OldWidth)
Fn.addFnAttr("min-legal-vector-width", llvm::utostr(Width));
}
More information about the llvm-commits
mailing list