@@ -951,14 +951,10 @@ Attribute Parser::parseDenseElementsAttr(Type attrType) {
951951 return nullptr ;
952952 }
953953
954- // If the type is specified `parseElementsLiteralType` will not parse a type.
955- // Use the attribute location as the location for error reporting in that
956- // case.
957- auto loc = attrType ? attribLoc : getToken ().getLoc ();
958- auto type = parseElementsLiteralType (attrType);
954+ auto type = parseElementsLiteralType (attribLoc, attrType);
959955 if (!type)
960956 return nullptr ;
961- return literalParser.getAttr (loc , type);
957+ return literalParser.getAttr (attribLoc , type);
962958}
963959
964960Attribute Parser::parseDenseResourceElementsAttr (Type attrType) {
@@ -999,7 +995,7 @@ Attribute Parser::parseDenseResourceElementsAttr(Type attrType) {
999995// / elements-literal-type ::= vector-type | ranked-tensor-type
1000996// /
1001997// / This method also checks the type has static shape.
1002- ShapedType Parser::parseElementsLiteralType (Type type) {
998+ ShapedType Parser::parseElementsLiteralType (SMLoc loc, Type type) {
1003999 // If the user didn't provide a type, parse the colon type for the literal.
10041000 if (!type) {
10051001 if (parseToken (Token::colon, " expected ':'" ))
@@ -1010,12 +1006,14 @@ ShapedType Parser::parseElementsLiteralType(Type type) {
10101006
10111007 auto sType = dyn_cast<ShapedType>(type);
10121008 if (!sType ) {
1013- emitError (" elements literal must be a shaped type" );
1009+ emitError (loc, " elements literal must be a shaped type" );
10141010 return nullptr ;
10151011 }
10161012
1017- if (!sType .hasStaticShape ())
1018- return (emitError (" elements literal type must have static shape" ), nullptr );
1013+ if (!sType .hasStaticShape ()) {
1014+ emitError (loc, " elements literal type must have static shape" );
1015+ return nullptr ;
1016+ }
10191017
10201018 return sType ;
10211019}
@@ -1032,7 +1030,7 @@ Attribute Parser::parseSparseElementsAttr(Type attrType) {
10321030 // of the type.
10331031 Type indiceEltType = builder.getIntegerType (64 );
10341032 if (consumeIf (Token::greater)) {
1035- ShapedType type = parseElementsLiteralType (attrType);
1033+ ShapedType type = parseElementsLiteralType (loc, attrType);
10361034 if (!type)
10371035 return nullptr ;
10381036
@@ -1065,7 +1063,7 @@ Attribute Parser::parseSparseElementsAttr(Type attrType) {
10651063 if (parseToken (Token::greater, " expected '>'" ))
10661064 return nullptr ;
10671065
1068- auto type = parseElementsLiteralType (attrType);
1066+ auto type = parseElementsLiteralType (loc, attrType);
10691067 if (!type)
10701068 return nullptr ;
10711069
0 commit comments