Skip to content

Commit 5d8af80

Browse files
jbouwmanstylewarning
authored andcommitted
Forbid the declaration of zero-length classical vectors
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]
1 parent 3448732 commit 5d8af80

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/parser.lisp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,10 @@ If REQUIRE-INDENT is T, a parse error is signalled if entries are not properly i
13011301
(:aref
13021302
(let ((top-token (pop line)))
13031303
(setf type (parse-quil-type (car (token-payload top-token))))
1304-
(setf length (cdr (token-payload top-token))))))
1304+
(let ((vector-length (cdr (token-payload top-token))))
1305+
(when (= 0 vector-length)
1306+
(quil-parse-error "Expected non-zero-length vector in DECLARE."))
1307+
(setf length vector-length)))))
13051308

13061309
;; Check for SHARING
13071310
(unless (endp line)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# zero-length vector
2+
3+
DECLARE r BIT[0]
4+
5+
I 0
6+
7+
MEASURE 0 r[0]

0 commit comments

Comments
 (0)