Skip to content

Commit add26fe

Browse files
committed
Organize checks in Verifier
1 parent f9180b3 commit add26fe

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3830,32 +3830,46 @@ void Verifier::visitCallBase(CallBase &Call) {
38303830
FoundAttachedCallBundle = true;
38313831
verifyAttachedCallBundle(Call, BU);
38323832
} else if (Tag == LLVMContext::OB_fp_control) {
3833-
Check(!FoundFpeControlBundle, "Multiple fp.control operand bundles",
3834-
Call);
3835-
Check(BU.Inputs.size() == 1,
3836-
"Expected exactly one fp.control bundle operand", Call);
3837-
auto *V = dyn_cast<MetadataAsValue>(BU.Inputs.front());
3838-
Check(V, "Value of fp.control bundle operand must be a metadata", Call);
3839-
auto *MDS = dyn_cast<MDString>(V->getMetadata());
3840-
Check(MDS, "Value of fp.control bundle operand must be a string", Call);
3841-
auto RM = convertBundleToRoundingMode(MDS->getString());
3842-
Check(RM.has_value(),
3843-
"Value of fp.control bundle operand is not a correct rounding mode",
3833+
Check(!FoundFpeControlBundle, "Multiple \"fp.control\" operand bundles",
38443834
Call);
3835+
bool FoundRoundingMode = false;
3836+
for (auto &U : BU.Inputs) {
3837+
Value *V = U.get();
3838+
Check(isa<MetadataAsValue>(V),
3839+
"Value of a \"fp.control\" bundle operand must be a metadata",
3840+
Call);
3841+
Metadata *MD = cast<MetadataAsValue>(V)->getMetadata();
3842+
Check(isa<MDString>(MD),
3843+
"Value of a \"fp.control\" bundle operand must be a string",
3844+
Call);
3845+
StringRef Item = cast<MDString>(MD)->getString();
3846+
if (convertBundleToRoundingMode(Item)) {
3847+
Check(!FoundRoundingMode, "Rounding mode is specified more that once",
3848+
Call);
3849+
FoundRoundingMode = true;
3850+
} else {
3851+
CheckFailed("Unrecognized value in \"fp.control\" bundle operand",
3852+
Call);
3853+
}
3854+
}
38453855
FoundFpeControlBundle = true;
38463856
} else if (Tag == LLVMContext::OB_fp_except) {
3847-
Check(!FoundFpeExceptBundle, "Multiple fp.except operand bundles", Call);
3857+
Check(!FoundFpeExceptBundle, "Multiple \"fp.except\" operand bundles",
3858+
Call);
38483859
Check(BU.Inputs.size() == 1,
3849-
"Expected exactly one fp.except bundle operand", Call);
3860+
"Expected exactly one \"fp.except\" bundle operand", Call);
38503861
auto *V = dyn_cast<MetadataAsValue>(BU.Inputs.front());
3851-
Check(V, "Value of fp.except bundle operand must be a metadata", Call);
3862+
Check(V, "Value of a \"fp.except\" bundle operand must be a metadata",
3863+
Call);
38523864
auto *MDS = dyn_cast<MDString>(V->getMetadata());
3853-
Check(MDS, "Value of fp.except bundle operand must be a string", Call);
3854-
auto EB = convertBundleToExceptionBehavior(MDS->getString());
3855-
Check(EB.has_value(),
3856-
"Value of fp.except bundle operand is not a correct exception "
3857-
"behavior",
3865+
Check(MDS, "Value of a \"fp.except\" bundle operand must be a string",
38583866
Call);
3867+
auto EB = convertBundleToExceptionBehavior(MDS->getString());
3868+
Check(
3869+
EB.has_value(),
3870+
"Value of a \"fp.except\" bundle operand is not a correct exception "
3871+
"behavior",
3872+
Call);
38593873
FoundFpeExceptBundle = true;
38603874
}
38613875
}

llvm/test/Verifier/fp-intrinsics.ll

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ entry:
5252
}
5353

5454
; Test multiple fp.control bundles.
55-
; CHECK-NEXT: Multiple fp.control operand bundles
55+
; CHECK-NEXT: Multiple "fp.control" operand bundles
5656
; CHECK-NEXT: %ftrunc = call double @llvm.trunc.f64(double %a) #{{[0-9]+}} [ "fp.control"(metadata !"rtz"), "fp.control"(metadata !"rtz") ]
5757
define double @f6(double %a) #0 {
5858
entry:
5959
%ftrunc = call double @llvm.trunc.f64(double %a) #0 [ "fp.control"(metadata !"rtz"), "fp.control"(metadata !"rtz") ]
6060
ret double %ftrunc
6161
}
6262

63-
; Test fp.control bundle that has more than one operands.
64-
; CHECK-NEXT: Expected exactly one fp.control bundle operand
63+
; Test fp.control bundle that has more than one rounding mode specification.
64+
; CHECK-NEXT: Rounding mode is specified more that once
6565
; CHECK-NEXT: %ftrunc = call double @llvm.trunc.f64(double %a) #{{[0-9]+}} [ "fp.control"(metadata !"rtz", metadata !"rte") ]
6666
define double @f7(double %a) #0 {
6767
entry:
@@ -70,7 +70,7 @@ entry:
7070
}
7171

7272
; Test fp.control bundle that has non-metadata operand.
73-
; CHECK-NEXT: Value of fp.control bundle operand must be a metadata
73+
; CHECK-NEXT: Value of a "fp.control" bundle operand must be a metadata
7474
; CHECK-NEXT: %ftrunc = call double @llvm.trunc.f64(double %a) #{{[0-9]+}} [ "fp.control"(i32 0) ]
7575
define double @f8(double %a) #0 {
7676
entry:
@@ -79,7 +79,7 @@ entry:
7979
}
8080

8181
; Test fp.control bundle that has non-string operand.
82-
; CHECK-NEXT: Value of fp.control bundle operand must be a string
82+
; CHECK-NEXT: Value of a "fp.control" bundle operand must be a string
8383
; CHECK-NEXT: %ftrunc = call double @llvm.trunc.f64(double %a) #{{[0-9]+}} [ "fp.control"(metadata i64 3) ]
8484
define double @f9(double %a) #0 {
8585
entry:
@@ -88,7 +88,7 @@ entry:
8888
}
8989

9090
; Test fp.control bundle that specifies incorrect value.
91-
; CHECK-NEXT: Value of fp.control bundle operand is not a correct rounding mode
91+
; CHECK-NEXT: Unrecognized value in "fp.control" bundle operand
9292
; CHECK-NEXT: %ftrunc = call double @llvm.trunc.f64(double %a) #{{[0-9]+}} [ "fp.control"(metadata !"qqq") ]
9393
define double @f10(double %a) #0 {
9494
entry:
@@ -97,7 +97,7 @@ entry:
9797
}
9898

9999
; Test multiple fp.except bundles.
100-
; CHECK-NEXT: Multiple fp.except operand bundles
100+
; CHECK-NEXT: Multiple "fp.except" operand bundles
101101
; CHECK-NEXT: %ftrunc = call double @llvm.trunc.f64(double %a) #{{[0-9]+}} [ "fp.except"(metadata !"strict"), "fp.except"(metadata !"strict") ]
102102
define double @f11(double %a) #0 {
103103
entry:
@@ -106,7 +106,7 @@ entry:
106106
}
107107

108108
; Test fp.except bundle that has more than one operands.
109-
; CHECK-NEXT: Expected exactly one fp.except bundle operand
109+
; CHECK-NEXT: Expected exactly one "fp.except" bundle operand
110110
; CHECK-NEXT: %ftrunc = call double @llvm.trunc.f64(double %a) #{{[0-9]+}} [ "fp.except"(metadata !"strict", metadata !"strict") ]
111111
define double @f12(double %a) #0 {
112112
entry:
@@ -115,7 +115,7 @@ entry:
115115
}
116116

117117
; Test fp.except bundle that has non-metadata operand.
118-
; CHECK-NEXT: Value of fp.except bundle operand must be a metadata
118+
; CHECK-NEXT: Value of a "fp.except" bundle operand must be a metadata
119119
; CHECK-NEXT: %ftrunc = call double @llvm.trunc.f64(double %a) #{{[0-9]+}} [ "fp.except"(i32 0) ]
120120
define double @f13(double %a) #0 {
121121
entry:
@@ -124,7 +124,7 @@ entry:
124124
}
125125

126126
; Test fp.except bundle that has non-string operand.
127-
; CHECK-NEXT: Value of fp.except bundle operand must be a string
127+
; CHECK-NEXT: Value of a "fp.except" bundle operand must be a string
128128
; CHECK-NEXT: %ftrunc = call double @llvm.trunc.f64(double %a) #{{[0-9]+}} [ "fp.except"(metadata i64 3) ]
129129
define double @f14(double %a) #0 {
130130
entry:
@@ -133,7 +133,7 @@ entry:
133133
}
134134

135135
; Test fp.except bundle that specifies incorrect value.
136-
; CHECK-NEXT: Value of fp.except bundle operand is not a correct exception behavior
136+
; CHECK-NEXT: Value of a "fp.except" bundle operand is not a correct exception behavior
137137
; CHECK-NEXT: %ftrunc = call double @llvm.trunc.f64(double %a) #{{[0-9]+}} [ "fp.except"(metadata !"qqq") ]
138138
define double @f15(double %a) #0 {
139139
entry:

0 commit comments

Comments
 (0)