openqasm / qe-compiler

An MLIR based compiler dynamic circuit compiler for real-time control systems supporting OpenQASM 3
Other
46 stars 15 forks source link

handle switch statement with no default case #145

Closed kevinsung closed 1 year ago

github-actions[bot] commented 1 year ago

clang-tidy review says "All clean, LGTM! :+1:"

kevinsung commented 1 year ago

How do I fix the formatting issues? I see the command ninja check-format but I don't know what command actually applies the fixes.

bcdonovan commented 1 year ago

How do I fix the formatting issues? I see the command ninja check-format but I don't know what command actually applies the fixes.

I usually edit the check-format.sh script locally to make the changes for me.

I modify the end of check-format.sh to be:

+#diff <(cat ${files}) <(${clang_format_bin} --style=file ${files})
+${clang_format_bin} -i --style=file ${files}

I think run ninja check-format, this will make the changes in place which you may then view before committing.

github-actions[bot] commented 1 year ago

clang-tidy review says "All clean, LGTM! :+1:"

mbhealy commented 1 year ago

How do I fix the formatting issues? I see the command ninja check-format but I don't know what command actually applies the fixes.

ninja fix-format

kevinsung commented 1 year ago

Ok, I've added a LIT-based test and removed the Python test (by the way, what is LIT?). There are a few issues that I would like help with if they need to be addressed:

OK. DeclarationNode(type=ASTTypeInt, IntNode(signed=true, value=15, bits=32)) DeclarationNode(type=ASTTypeQubitContainer, QubitContainerNode(QubitNode(name=$0:0, bits=1))) SwitchStatementNode(SwitchQuantity(name=i, type=ASTTypeIdentifier), statements=[ CaseStatementNode(case=0, ), ], default statement=[ PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump:

  1. Program arguments: ./bin/qss-compiler -X=qasm --emit=ast-pretty test.qasm

    0 0x0000000003433134 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0

    1 0x000000000343036b SignalHandler(int) Signals.cpp:0:0

    2 0x00007fcf5157eb70 __restore_rt (/lib64/libc.so.6+0x3db70)

    3 0x0000000000a29174 qssc::frontend::openqasm3::PrintQASM3Visitor::visit(QASM::ASTSwitchStatementNode const*) /home/kevinsung/projects/qic-rta-driver/compiler/qss-compiler/lib/Frontend/OpenQASM3/PrintQASM3Visitor.cpp:137:52

    4 0x0000000000a2325c qssc::frontend::openqasm3::BaseQASM3Visitor::visit(QASM::ASTStatementList const*) /home/kevinsung/projects/qic-rta-driver/compiler/qss-compiler/lib/Frontend/OpenQASM3/BaseQASM3Visitor.cpp:74:27

    5 0x0000000000a215ba qssc::frontend::openqasm3::PrintQASM3Visitor::~PrintQASM3Visitor() /home/kevinsung/projects/qic-rta-driver/compiler/qss-compiler/include/Frontend/OpenQASM3/PrintQASM3Visitor.h:24:7

    6 0x0000000000a215ba qssc::frontend::openqasm3::parse(std::__cxx11::basic_string<char, std::char_traits, std::allocator> const&, bool, bool, bool, bool, mlir::ModuleOp&, std::optional<std::function<void (qssc::Diagnostic const&)>>) /home/kevinsung/projects/qic-rta-driver/compiler/qss-compiler/lib/Frontend/OpenQASM3/OpenQASM3Frontend.cpp:204:3

    7 0x00000000006bc053 std::_Optional_payload_base<std::function<void (qssc::Diagnostic const&)>>::_M_reset() /usr/include/c++/13/optional:317:2

    8 0x00000000006bc053 std::_Optional_payload<std::function<void (qssc::Diagnostic const&)>, false, false, false>::~_Optional_payload() /usr/include/c++/13/optional:439:65

    9 0x00000000006bc053 std::_Optional_base<std::function<void (qssc::Diagnostic const&)>, false, false>::~_Optional_base() /usr/include/c++/13/optional:510:12

    10 0x00000000006bc053 std::optional<std::function<void (qssc::Diagnostic const&)>>::~optional() /usr/include/c++/13/optional:705:11

    11 0x00000000006bc053 compile_(int, char const*, std::__cxx11::basic_string<char, std::char_traits, std::allocator>, std::optional<std::function<void (qssc::Diagnostic const&)>>) /home/kevinsung/projects/qic-rta-driver/compiler/qss-compiler/lib/API/api.cpp:577:46

    12 0x00000000006bc9fd std::_Optional_payload_base<std::function<void (qssc::Diagnostic const&)>>::_M_reset() /usr/include/c++/13/optional:317:2

    13 0x00000000006bc9fd std::_Optional_payload<std::function<void (qssc::Diagnostic const&)>, false, false, false>::~_Optional_payload() /usr/include/c++/13/optional:439:65

    14 0x00000000006bc9fd std::_Optional_base<std::function<void (qssc::Diagnostic const&)>, false, false>::~_Optional_base() /usr/include/c++/13/optional:510:12

    15 0x00000000006bc9fd std::optional<std::function<void (qssc::Diagnostic const&)>>::~optional() /usr/include/c++/13/optional:705:11

    16 0x00000000006bc9fd qssc::compile(int, char const*, std::__cxx11::basic_string<char, std::char_traits, std::allocator>, std::optional<std::function<void (qssc::Diagnostic const&)>>) /home/kevinsung/projects/qic-rta-driver/compiler/qss-compiler/lib/API/api.cpp:666:76

    17 0x000000000060cedd std::_Optional_payload_base<std::function<void (qssc::Diagnostic const&)>>::_M_reset() /usr/include/c++/13/optional:317:2

    18 0x000000000060cedd std::_Optional_payload<std::function<void (qssc::Diagnostic const&)>, false, false, false>::~_Optional_payload() /usr/include/c++/13/optional:439:65

    19 0x000000000060cedd std::_Optional_base<std::function<void (qssc::Diagnostic const&)>, false, false>::~_Optional_base() /usr/include/c++/13/optional:510:12

    20 0x000000000060cedd std::optional<std::function<void (qssc::Diagnostic const&)>>::~optional() /usr/include/c++/13/optional:705:11

    21 0x000000000060cedd main /home/kevinsung/projects/qic-rta-driver/compiler/qss-compiler/tools/qss-compiler/qss-compiler.cpp:20:23

    22 0x00007fcf51568b4a __libc_start_call_main (/lib64/libc.so.6+0x27b4a)

    23 0x00007fcf51568c0b __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x27c0b)

    24 0x00000000006ab545 _start (./bin/qss-compiler+0x6ab545)

    zsh: segmentation fault (core dumped) ./bin/qss-compiler -X=qasm --emit=ast-pretty test.qasm

github-actions[bot] commented 1 year ago

clang-tidy review says "All clean, LGTM! :+1:"

taalexander commented 1 year ago

You likely need to add a similar change (and test) to the print visitor - https://github.com/Qiskit/qss-compiler/blob/main/include/Frontend/OpenQASM3/PrintQASM3Visitor.h

kevinsung commented 1 year ago

Thanks, done.

github-actions[bot] commented 1 year ago

clang-tidy review says "All clean, LGTM! :+1:"