Skip to content

Commit

Permalink
Forbid the declaration of zero-length classical vectors
Browse files Browse the repository at this point in the history
If zero-length vectors are allowed, qvm crashes in
`allocate-memory-for-model` with the error:

    The value of QVM::SIZE is 0, which is not The SIZE wasn't a multiple of 8..
       [Condition of type SIMPLE-TYPE-ERROR]
  • Loading branch information
jbouwman authored and stylewarning committed Jan 12, 2024
1 parent 3448732 commit 5d8af80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/parser.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,10 @@ If REQUIRE-INDENT is T, a parse error is signalled if entries are not properly i
(:aref
(let ((top-token (pop line)))
(setf type (parse-quil-type (car (token-payload top-token))))
(setf length (cdr (token-payload top-token))))))
(let ((vector-length (cdr (token-payload top-token))))
(when (= 0 vector-length)
(quil-parse-error "Expected non-zero-length vector in DECLARE."))
(setf length vector-length)))))

;; Check for SHARING
(unless (endp line)
Expand Down
7 changes: 7 additions & 0 deletions tests/bad-test-files/bad-empty-vector.quil
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# zero-length vector

DECLARE r BIT[0]

I 0

MEASURE 0 r[0]

0 comments on commit 5d8af80

Please sign in to comment.