Skip to content

Commit faa1ef2

Browse files
committed
Place checking for empty string in verifier
1 parent 7aafd7b commit faa1ef2

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

mlir/lib/Dialect/DLTI/DLTI.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ static ParseResult parseKeyValuePair(AsmParser &parser,
6060

6161
std::string ident;
6262
OptionalParseResult parsedStr = parser.parseOptionalString(&ident);
63-
if (parsedStr.has_value() && !ident.empty()) {
64-
if (failed(parsedStr.value()))
65-
return parser.emitError(parser.getCurrentLocation())
66-
<< "error while parsing string DLTI key";
67-
63+
if (parsedStr.has_value() && succeeded(parsedStr.value())) {
6864
if (failed(parser.parseEqual()) || failed(parser.parseAttribute(value)))
6965
return failure(); // Assume that an error has already been emitted.
7066

@@ -148,7 +144,10 @@ static LogicalResult verifyEntries(function_ref<InFlightDiagnostic()> emitError,
148144
if (key.isNull())
149145
return emitError() << "contained invalid DLTI key";
150146
if (!allowTypes && dyn_cast<Type>(key))
151-
return emitError() << "type as DLIT key is not allowed";
147+
return emitError() << "type as DLTI key is not allowed";
148+
if (auto strKey = dyn_cast<StringAttr>(key))
149+
if (strKey.getValue().empty())
150+
return emitError() << "empty string as DLTI key is not allowed";
152151
if (!keys.insert(key).second)
153152
return emitError() << "repeated DLTI key: " << keyToStr(key);
154153
if (!entry.getValue())

mlir/test/Dialect/DLTI/invalid.mlir

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525

2626
// -----
2727

28+
// expected-error@below {{empty string as DLTI key is not allowed}}
29+
"test.unknown_op"() { test.unknown_attr = #dlti.map<"" = 42> } : () -> ()
30+
31+
// -----
32+
2833
// expected-error@below {{repeated DLTI key: "test.id"}}
2934
"test.unknown_op"() { test.unknown_attr = #dlti.dl_spec<
3035
#dlti.dl_entry<"test.id", 42>,

0 commit comments

Comments
 (0)