-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Go: Fix data flow through variable defined in type switch guard #16120
Conversation
Liking that we apparently don't even need to touch the SSA layer -- this becomes just another instruction that defines a fresh variable 👍 |
f68e6c0
to
72f7212
Compare
72f7212
to
8027f3a
Compare
I found a way to identify the implicitly declared objects without a new table. This simplifies the PR a bit. |
8027f3a
to
74711ec
Compare
It represents the implicit declaration of a variable at the beginning of a case clause
74711ec
to
a65b02e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QL changes look good; trivial suggestion re: change note. Haven't examined the test expectations in detail.
go/ql/lib/change-notes/2024-04-06-type-switch-implicitly-declared-variables.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Chris Smowton <[email protected]>
QA results all look good. |
Reported here.
Consider a typical type switch statement.
It looks like a new variable
inputWithType
is defined in the guard, and is used in the case clauses. But the go compiler can't represent it like that internally becauseinputWithType
has a different type in each case clause. So it has to make a variable for each case clause. The CodeQL Go library is not currently dealing with this. We end up with an object forinputWithType
which doesn't have a declaration, which means that there is noSsaDefinition
relating to it. This causes data flow to not work.I tried fixing this in the extractor, but it was a bit messy, and I realised it was better to accept that these variables don't have an explicit declaration and add an
IR::Instruction
for their implicit declaration. This causes SSA to work properly again. I have added tests for control flow and data flow.