Skip to content
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

Fixed issues found by static analysis #3732

Merged
merged 6 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backends/common/removeComplexExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const IR::PathExpression* RemoveComplexExpressions::createTemporary(

const IR::Vector<IR::Argument>* RemoveComplexExpressions::simplifyExpressions(
const IR::Vector<IR::Argument>* args) {
bool changes = true;
bool changes = false;
auto result = new IR::Vector<IR::Argument>();
for (auto arg : *args) {
auto r = simplifyExpression(arg->expression, false);
Expand Down
4 changes: 2 additions & 2 deletions backends/graphs/graph_visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ class Graph_visitor : public Graphs {
void forLoopFullGraph(std::vector<Graph*>& graphsArray, fullGraphOpts* opts,
PrevType prev_type);

Util::JsonObject* json; // stores json that will be outputted
Util::JsonArray* programBlocks; // stores objects in top level array "nodes"
Util::JsonObject* json; // stores json that will be outputted
Util::JsonArray* programBlocks = nullptr; // stores objects in top level array "nodes"
const cstring graphsDir;
// options
const bool graphs; // output boost graphs to files
Expand Down
12 changes: 8 additions & 4 deletions frontends/common/constantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,8 @@ DoConstantFolding::Result DoConstantFolding::setContains(const IR::Expression* k
if (select->is<IR::BoolLiteral>()) {
auto key = getConstant(keySet);
if (key == nullptr) {
::error(ErrorType::ERR_TYPE_ERROR, "%1%: expression must evaluate to a constant", key);
::error(ErrorType::ERR_TYPE_ERROR, "%1%: expression must evaluate to a constant",
keySet);
return Result::No;
}
BUG_CHECK(key->is<IR::BoolLiteral>(), "%1%: expected a boolean", key);
Expand All @@ -867,7 +868,8 @@ DoConstantFolding::Result DoConstantFolding::setContains(const IR::Expression* k
// This must be an enum value
auto key = getConstant(keySet);
if (key == nullptr) {
::error(ErrorType::ERR_TYPE_ERROR, "%1%: expression must evaluate to a constant", key);
::error(ErrorType::ERR_TYPE_ERROR, "%1%: expression must evaluate to a constant",
keySet);
return Result::No;
}
auto sel = getConstant(select);
Expand All @@ -885,12 +887,14 @@ DoConstantFolding::Result DoConstantFolding::setContains(const IR::Expression* k
} else if (auto range = keySet->to<IR::Range>()) {
auto left = getConstant(range->left);
if (left == nullptr) {
::error(ErrorType::ERR_INVALID, "%1%: expression must evaluate to a constant", left);
::error(ErrorType::ERR_INVALID, "%1%: expression must evaluate to a constant",
range->left);
return Result::DontKnow;
}
auto right = getConstant(range->right);
if (right == nullptr) {
::error(ErrorType::ERR_INVALID, "%1%: expression must evaluate to a constant", right);
::error(ErrorType::ERR_INVALID, "%1%: expression must evaluate to a constant",
range->right);
return Result::DontKnow;
}
if (left->to<IR::Constant>()->value <= cst->value &&
Expand Down
2 changes: 1 addition & 1 deletion frontends/p4/createBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const IR::Node* CreateBuiltins::postorder(IR::Property* property) {
if (auto key = property->value->to<IR::Key>()) {
if (key->keyElements.size() == 0) return nullptr;
} else {
::error(ErrorType::ERR_INVALID, "%1%: must be a key", key);
::error(ErrorType::ERR_INVALID, "%1%: must be a key", property->value);
return nullptr;
}
return property;
Expand Down
2 changes: 1 addition & 1 deletion frontends/p4/def_use.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class Definitions : public IHasDbPrint {
/// (conservative approximation).
ordered_map<const BaseLocation*, const ProgramPoints*> definitions;
/// If true the current program point is actually unreachable.
bool unreachable;
bool unreachable = false;

public:
Definitions() = default;
Expand Down
4 changes: 2 additions & 2 deletions frontends/p4/methodInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ class Instantiation : public InstanceBase {
const IR::Declaration_Instance* instance;
const IR::Vector<IR::Type>* typeArguments;
const IR::Vector<IR::Argument>* constructorArguments;
const IR::ParameterList* constructorParameters;
const IR::TypeParameters* typeParameters;
const IR::ParameterList* constructorParameters = nullptr;
const IR::TypeParameters* typeParameters = nullptr;

static Instantiation* resolve(const IR::Declaration_Instance* instance,
DeclarationLookup* refMap, TypeMap* typeMap);
Expand Down
4 changes: 2 additions & 2 deletions frontends/p4/specialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class SpecializationMap {
const IR::Parameter* param);

public:
TypeMap* typeMap;
ReferenceMap* refMap;
TypeMap* typeMap = nullptr;
ReferenceMap* refMap = nullptr;
/** Add a specialization instance.
*
* @param invocation The constructor invocation.
Expand Down
2 changes: 1 addition & 1 deletion ir/pass_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef std::function<void(const char* manager, unsigned seqNo,
const char* pass, const IR::Node* node)> DebugHook;

class PassManager : virtual public Visitor, virtual public Backtrack {
bool early_exit_flag;
bool early_exit_flag = false;
mutable int never_backtracks_cache = -1;

protected:
Expand Down
11 changes: 6 additions & 5 deletions lib/exename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ static void convertToAbsPath(const char* const relPath, char (&output)[N]) {
}

const char* exename(const char* argv0) {
static char buffer[PATH_MAX];
// Leave 1 extra char for the \0
static char buffer[PATH_MAX+1];
if (buffer[0]) return buffer; // done already
int len;
/* find the path of the executable. We use a number of techniques that may fail
* or work on different systems, and take the first working one we find. Fall
* back to not overriding the compiled-in installation path */
if ((len = readlink("/proc/self/exe", buffer, sizeof(buffer))) > 0 ||
(len = readlink("/proc/curproc/exe", buffer, sizeof(buffer))) > 0 ||
(len = readlink("/proc/curproc/file", buffer, sizeof(buffer))) > 0 ||
(len = readlink("/proc/self/path/a.out", buffer, sizeof(buffer))) > 0) {
if ((len = readlink("/proc/self/exe", buffer, sizeof(buffer)-1)) > 0 ||
(len = readlink("/proc/curproc/exe", buffer, sizeof(buffer)-1)) > 0 ||
(len = readlink("/proc/curproc/file", buffer, sizeof(buffer)-1)) > 0 ||
(len = readlink("/proc/self/path/a.out", buffer, sizeof(buffer)-1)) > 0) {
buffer[len] = 0;
} else if (argv0 && argv0[0] == '/') {
snprintf(buffer, sizeof(buffer), "%s", argv0);
Expand Down
2 changes: 1 addition & 1 deletion midend/removeComplexExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const IR::PathExpression* RemoveComplexExpressions::createTemporary(

const IR::Vector<IR::Argument>* RemoveComplexExpressions::simplifyExpressions(
const IR::Vector<IR::Argument>* args) {
bool changes = true;
bool changes = false;
auto result = new IR::Vector<IR::Argument>();
for (auto arg : *args) {
auto r = simplifyExpression(arg->expression, false);
Expand Down
4 changes: 2 additions & 2 deletions midend/simplifyBitwise.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace P4 {
* @todo: Extend the optimization to handle multiple combinations of masks
*/
class SimplifyBitwise : public Transform {
IR::Vector<IR::StatOrDecl>* slice_statements;
const IR::AssignmentStatement* changing_as;
IR::Vector<IR::StatOrDecl>* slice_statements = nullptr;
const IR::AssignmentStatement* changing_as = nullptr;

void assignSlices(const IR::Expression* expr, big_int mask);

Expand Down