[llvm] Improve diagnostic for malformed constant vectors (PR #216253)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 23 04:02:35 PDT 2026
================
@@ -4275,6 +4275,12 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
// ValID ::= '<' ConstVector '>' --> Vector.
// ValID ::= '<' '{' ConstVector '}' '>' --> Packed Struct.
Lex.Lex();
+
+ // guard constant vector elements must begin with a type.
+ if (Lex.getKind() == lltok::APSInt || Lex.getKind() == lltok::Type)
+ return error(Lex.getLoc(),
+ "constant vector elements must begin with a type");
----------------
im-lunex wrote:
Thanks for the review! I've reworked this in my latest update: the check now sits inside the `case lltok::less:` branch right after `bool isPackedStruct = EatIfPresent(lltok::lbrace);` and before `parseGlobalValueVector(Elts)` is called, so it is definitely reachable — it intercepts malformed vectors like `<123, 456>` and the redundant-prefix form `<2 x i16> <i16 123, i16 456>` from #29043 *before* the element parser can emit the confusing "expected type" error. It also only fires for bare literal tokens (APSInt/APFloat/FloatLiteral/FloatHexLiteral), so valid typed vectors like `<i16 123, i16 456>` are unaffected.
https://github.com/llvm/llvm-project/pull/216253
More information about the llvm-commits
mailing list