[llvm] [IR] Verify DISubrange/DISubrangeType bounds are ConstantInt (PR #217570)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 11 18:37:41 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- llvm/lib/IR/AsmWriter.cpp llvm/lib/IR/DebugInfoMetadata.cpp llvm/lib/IR/LLVMContextImpl.h llvm/lib/IR/Verifier.cpp llvm/unittests/IR/MetadataTest.cpp llvm/unittests/IR/VerifierTest.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index c7e5de08e..eb1d7507e 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -413,8 +413,7 @@ template <> struct MDNodeKeyImpl<DIGenericSubrange> {
auto *MD = dyn_cast_or_null<ConstantAsMetadata>(CountNode);
if (CountNode && MD)
if (auto *CV = dyn_cast<ConstantInt>(MD->getValue()))
- return hash_combine(CV->getSExtValue(), LowerBound, UpperBound,
- Stride);
+ return hash_combine(CV->getSExtValue(), LowerBound, UpperBound, Stride);
return hash_combine(CountNode, LowerBound, UpperBound, Stride);
}
};
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index dc3bd7800..8cb012a79 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -1122,22 +1122,20 @@ void Verifier::visitDISubrangeType(const DISubrangeType &N) {
auto *BaseType = N.getRawBaseType();
CheckDI(!BaseType || isType(BaseType), "BaseType must be a type");
auto *LBound = N.getRawLowerBound();
- CheckDI(!LBound || isConstantIntMetadata(LBound) ||
- isa<DIVariable>(LBound) || isa<DIExpression>(LBound) ||
- isa<DIDerivedType>(LBound),
+ CheckDI(!LBound || isConstantIntMetadata(LBound) || isa<DIVariable>(LBound) ||
+ isa<DIExpression>(LBound) || isa<DIDerivedType>(LBound),
"LowerBound must be signed constant or DIVariable or DIExpression or "
"DIDerivedType",
&N);
auto *UBound = N.getRawUpperBound();
- CheckDI(!UBound || isConstantIntMetadata(UBound) ||
- isa<DIVariable>(UBound) || isa<DIExpression>(UBound) ||
- isa<DIDerivedType>(UBound),
+ CheckDI(!UBound || isConstantIntMetadata(UBound) || isa<DIVariable>(UBound) ||
+ isa<DIExpression>(UBound) || isa<DIDerivedType>(UBound),
"UpperBound must be signed constant or DIVariable or DIExpression or "
"DIDerivedType",
&N);
auto *Stride = N.getRawStride();
- CheckDI(!Stride || isConstantIntMetadata(Stride) ||
- isa<DIVariable>(Stride) || isa<DIExpression>(Stride),
+ CheckDI(!Stride || isConstantIntMetadata(Stride) || isa<DIVariable>(Stride) ||
+ isa<DIExpression>(Stride),
"Stride must be signed constant or DIVariable or DIExpression", &N);
auto *Bias = N.getRawBias();
CheckDI(!Bias || isConstantIntMetadata(Bias) || isa<DIVariable>(Bias) ||
@@ -1154,26 +1152,26 @@ void Verifier::visitDISubrange(const DISubrange &N) {
CheckDI(!N.getRawCountNode() || !N.getRawUpperBound(),
"Subrange can have any one of count or upperBound", &N);
auto *CBound = N.getRawCountNode();
- CheckDI(!CBound || isConstantIntMetadata(CBound) ||
- isa<DIVariable>(CBound) || isa<DIExpression>(CBound),
+ CheckDI(!CBound || isConstantIntMetadata(CBound) || isa<DIVariable>(CBound) ||
+ isa<DIExpression>(CBound),
"Count must be signed constant or DIVariable or DIExpression", &N);
auto Count = N.getCount();
CheckDI(!Count || !isa<ConstantInt *>(Count) ||
cast<ConstantInt *>(Count)->getSExtValue() >= -1,
"invalid subrange count", &N);
auto *LBound = N.getRawLowerBound();
- CheckDI(!LBound || isConstantIntMetadata(LBound) ||
- isa<DIVariable>(LBound) || isa<DIExpression>(LBound),
+ CheckDI(!LBound || isConstantIntMetadata(LBound) || isa<DIVariable>(LBound) ||
+ isa<DIExpression>(LBound),
"LowerBound must be signed constant or DIVariable or DIExpression",
&N);
auto *UBound = N.getRawUpperBound();
- CheckDI(!UBound || isConstantIntMetadata(UBound) ||
- isa<DIVariable>(UBound) || isa<DIExpression>(UBound),
+ CheckDI(!UBound || isConstantIntMetadata(UBound) || isa<DIVariable>(UBound) ||
+ isa<DIExpression>(UBound),
"UpperBound must be signed constant or DIVariable or DIExpression",
&N);
auto *Stride = N.getRawStride();
- CheckDI(!Stride || isConstantIntMetadata(Stride) ||
- isa<DIVariable>(Stride) || isa<DIExpression>(Stride),
+ CheckDI(!Stride || isConstantIntMetadata(Stride) || isa<DIVariable>(Stride) ||
+ isa<DIExpression>(Stride),
"Stride must be signed constant or DIVariable or DIExpression", &N);
}
diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp
index 313219b29..8b5007522 100644
--- a/llvm/unittests/IR/MetadataTest.cpp
+++ b/llvm/unittests/IR/MetadataTest.cpp
@@ -2068,14 +2068,15 @@ TEST_F(DISubrangeTypeTest, boundsEqualDistinctConstantAsMetadata) {
auto *Lower2 =
ConstantAsMetadata::get(ConstantInt::get(Context, APInt(64, -7, true)));
ASSERT_NE(Lower1, Lower2);
- auto *Upper = ConstantAsMetadata::get(ConstantInt::get(Context, APInt(32, 23, true)));
+ auto *Upper =
+ ConstantAsMetadata::get(ConstantInt::get(Context, APInt(32, 23, true)));
auto *N1 = DISubrangeType::get(Context, StringRef(), File, 101, Scope, 32, 0,
- DINode::FlagZero, Base, Lower1, Upper,
- nullptr, nullptr);
+ DINode::FlagZero, Base, Lower1, Upper, nullptr,
+ nullptr);
auto *N2 = DISubrangeType::get(Context, StringRef(), File, 101, Scope, 32, 0,
- DINode::FlagZero, Base, Lower2, Upper,
- nullptr, nullptr);
+ DINode::FlagZero, Base, Lower2, Upper, nullptr,
+ nullptr);
EXPECT_EQ(N1, N2);
}
@@ -2090,17 +2091,19 @@ TEST_F(DISubrangeTypeTest, boundsCompareNonConstantIntSafely) {
DILocalScope *Scope = getSubprogram();
DIFile *File = getFile();
- auto *Lower1 = ConstantAsMetadata::get(UndefValue::get(Type::getInt32Ty(Context)));
+ auto *Lower1 =
+ ConstantAsMetadata::get(UndefValue::get(Type::getInt32Ty(Context)));
auto *Lower2 =
ConstantAsMetadata::get(ConstantInt::get(Context, APInt(32, -7, true)));
- auto *Upper = ConstantAsMetadata::get(ConstantInt::get(Context, APInt(32, 23, true)));
+ auto *Upper =
+ ConstantAsMetadata::get(ConstantInt::get(Context, APInt(32, 23, true)));
auto *N1 = DISubrangeType::get(Context, StringRef(), File, 101, Scope, 32, 0,
- DINode::FlagZero, Base, Lower1, Upper,
- nullptr, nullptr);
+ DINode::FlagZero, Base, Lower1, Upper, nullptr,
+ nullptr);
auto *N2 = DISubrangeType::get(Context, StringRef(), File, 102, Scope, 32, 0,
- DINode::FlagZero, Base, Lower2, Upper,
- nullptr, nullptr);
+ DINode::FlagZero, Base, Lower2, Upper, nullptr,
+ nullptr);
EXPECT_NE(N1, N2);
}
diff --git a/llvm/unittests/IR/VerifierTest.cpp b/llvm/unittests/IR/VerifierTest.cpp
index 70924c7ed..ffc1ad0ce 100644
--- a/llvm/unittests/IR/VerifierTest.cpp
+++ b/llvm/unittests/IR/VerifierTest.cpp
@@ -316,9 +316,8 @@ TEST(VerifierTest, DISubrangeNonConstantIntBound) {
TEST(VerifierTest, DISubrangeTypeNonConstantIntBound) {
LLVMContext C;
Module M("M", C);
- auto *Base =
- DIBasicType::get(C, dwarf::DW_TAG_base_type, "int", 32, 0,
- dwarf::DW_ATE_signed, DINode::FlagZero);
+ auto *Base = DIBasicType::get(C, dwarf::DW_TAG_base_type, "int", 32, 0,
+ dwarf::DW_ATE_signed, DINode::FlagZero);
auto *NonIntBound =
ConstantAsMetadata::get(UndefValue::get(Type::getInt32Ty(C)));
auto *N = DISubrangeType::get(C, StringRef(), nullptr, 0, nullptr, 32, 0,
``````````
</details>
https://github.com/llvm/llvm-project/pull/217570
More information about the llvm-commits
mailing list