-
Notifications
You must be signed in to change notification settings - Fork 1.6k
ExprEngine: Handle pointer assignments in loops without bailout #2949
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,6 +138,7 @@ | |
| #include "symboldatabase.h" | ||
| #include "tokenize.h" | ||
|
|
||
| #include <cassert> | ||
| #include <limits> | ||
| #include <memory> | ||
| #include <iostream> | ||
|
|
@@ -2646,19 +2647,41 @@ static std::string execute(const Token *start, const Token *end, Data &data) | |
| data.assignStructMember(tok2, &*structVal, memberName, memberValue); | ||
| continue; | ||
| } | ||
|
|
||
| // Assign a pointer value | ||
| if (lhs->isUnaryOp("*") && lhs->astOperand1()->varId()) { | ||
| const Token *varToken = tok2->astOperand1()->astOperand1(); | ||
| // Get value of the pointer | ||
| ExprEngine::ValuePtr val = data.getValue(varToken->varId(), varToken->valueType(), varToken); | ||
| if (val && val->type == ExprEngine::ValueType::ArrayValue) { | ||
| // Try to assign "any" value | ||
| auto arrayValue = std::dynamic_pointer_cast<ExprEngine::ArrayValue>(val); | ||
| arrayValue->assign(std::make_shared<ExprEngine::IntRange>("0", 0, 0), std::make_shared<ExprEngine::BailoutValue>()); | ||
| if (!val || (val->type != ExprEngine::ValueType::ArrayValue && | ||
| val->type != ExprEngine::ValueType::AddressOfValue)) | ||
| throw ExprEngineException(tok2, "Unhandled assignment in loop"); | ||
|
jubnzv marked this conversation as resolved.
|
||
| // Handle the value that we are pointing to | ||
| int varid = varToken->varId(); | ||
| if (changedVariables.find(varid) != changedVariables.end()) | ||
| continue; | ||
| changedVariables.insert(varid); | ||
| auto oldValue = data.getValue(varid, nullptr, nullptr); | ||
| if (oldValue && oldValue->isUninit()) | ||
| call(data.callbacks, varToken, oldValue, &data); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are not trying to execute the loop yet. We should call callbacks later when the loop is executed. We also do not know if the variable will still have the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then why do we call them in variable assignments here? |
||
| if (val->type == ExprEngine::ValueType::ArrayValue) { | ||
| // Unknown pointer, array or struct | ||
| auto arrayValue = std::dynamic_pointer_cast<ExprEngine::ArrayValue>(val); | ||
| assert(arrayValue); | ||
| data.assignValue(tok2, varid, val); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as far as I see this assignment is redundant.. it assigns the same value as we already have. |
||
| } else if (val->type == ExprEngine::ValueType::AddressOfValue) { | ||
| // Address of a known variable | ||
| auto addressOf = std::dynamic_pointer_cast<ExprEngine::AddressOfValue>(val); | ||
| assert(addressOf); | ||
| data.assignValue(tok2, varid, val); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| if (!lhs->variable()) | ||
| throw ExprEngineException(tok2, "Unhandled assignment in loop"); | ||
| // give variable "any" value | ||
|
|
||
| // Give variable "any" value | ||
| int varid = lhs->varId(); | ||
| if (changedVariables.find(varid) != changedVariables.end()) | ||
| continue; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.