Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

🐛 Register-reference validation is incomplete in the parser

未关闭
#468 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
cpp
领域
compilers

调研方向

首先跟踪 preprocessCode 以及提到的入口点 validateTargets、parseBitRegisterRef 和 parseClassicConditionExpression,使用 definedRegisters 了解现有的量子比特检查。为两个相关路径添加标识符、寄存器存在性、索引边界和 expectedValue 范围验证。完成的标准是拒绝格式错误的引用和不可能的比较,同时列出的范围外情况保持不变。

由索引模型根据 Issue 内容生成。

描述

🤖 AI text below 🤖

Problem statement

The parser has three related gaps in how it validates register references and comparison values:

  1. Well-formed identifier checking. Neither validateTargets (for qubit targets in gate calls) nor parseBitRegisterRef (for classical bits in if conditions) rejects malformed register names on lexical grounds. Inputs like c2] (dangling ]) or @# (not an identifier at all) slip through the shape check. On the qubit side the eventual definedRegisters lookup rejects them indirectly with an "unknown register" error; on the classical side there is no lookup, so the error surfaces even later in the DD backend.

  2. Classical bit reference against declared registers. validateTargets verifies that qubit targets exist in definedRegisters and that the bit index fits within the register size. Nothing analogous runs for the register mentioned in an if condition: if (nonexistent == 1) and if (c[999] == 1) (with creg c[3]) both parse without complaint.

  3. expectedValue within the register's representable range. if (c == 999) on creg c[3] (3 bits, values 0 to 7) is impossible to satisfy but the parser accepts it. The comparison always evaluates to false at runtime.

Surfaced during the review of PR #463.

Proposed solution

Add the three missing checks and share them where the same code path applies to qubits and classical bits:

  • Extract a small isValidIdentifier helper (letter or underscore followed by letters, digits, or underscores). Use it in validateTargets (before the definedRegisters lookup) and in parseBitRegisterRef (before returning the reference).
  • Extend preprocessCode so it also runs an existence + bounds check on the register mentioned in the condition of an if, using the same definedRegisters map already available there. The exact placement (inside parseClassicConditionExpression or a separate validateClassicCondition pass) is an implementation detail.
  • Reject expectedValue values that exceed what the referenced register can hold (whole register or single bit).
Out of scope
  • Reserved-word checking (qreg, creg, measure, etc.). Separate semantic concern.
  • Compound expressions in the condition (out of scope of the parser as a whole today).
主要语言
C++
星标
21
派生
8
平均合并
5 小时 17 分钟
30 天内合并 PR
21

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

munich-quantum-toolkit/debugger 的其他 Issue

查看 munich-quantum-toolkit/debugger 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。