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

fix: EXLR flagged as error by plugin #121

Conversation

SWETAS04
Copy link
Contributor

This PR incudes a new operand type which accepts either a relocatable symbol or absolute immediate value( with a warning).
Other Instructions which suffer from the same problem are also changed.

SWETAS04 and others added 5 commits March 24, 2021 09:01
Signed-off-by: Sweta Shah <swetas04@gmail.com>
Signed-off-by: Sweta Shah <swetas04@GMAIL.COM>
Signed-off-by: Sweta Shah <swetas04@GMAIL.COM>
Signed-off-by: Sweta Shah <swetas04@GMAIL.COM>
@SWETAS04 SWETAS04 marked this pull request as draft April 19, 2021 14:23
Signed-off-by: Sweta Shah <swetas04@GMAIL.COM>
Signed-off-by: Sweta Shah <swetas04@GMAIL.COM>
Signed-off-by: Sweta Shah <swetas04@GMAIL.COM>
Signed-off-by: Sweta Shah <swetas04@GMAIL.COM>
Signed-off-by: Sweta Shah <swetas04@GMAIL.COM>
@SWETAS04 SWETAS04 marked this pull request as ready for review April 21, 2021 06:56
{
return diagnostic_op(diagnostic_severity::warning,
"D031",
" Operand value must be relocatable symbol with instruction " + instr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more useful to report the operand we're generating the warning for instead of the instruction name + replace must with should as this is a warning.

@@ -439,6 +439,7 @@ struct diagnostic_op
static diagnostic_op error_D023(const range& range);
static diagnostic_op error_D024(const range& range, const std::string& type);
static diagnostic_op warn_D025(const range& range, const std::string& type, const std::string& modifier);
static diagnostic_op warn_D031(const range& range, const std::string& modifier);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reorder, please.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test generating this message.

@@ -457,20 +458,20 @@ struct diagnostic_op

static diagnostic_op error_M112(const std::string& instr_name, const range& range);

static diagnostic_op error_M113(const std::string& instr_name, const range& range);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the original message ids, the messages relate to basically the same issues as before.

@@ -287,6 +287,13 @@ bool one_operand::check(
}
return true;
}
// simple operand with relocatable symbol or immediate value

if (to_check.identifier.type == machine_operand_type::RELOC_IMM && operand_identifier != "RELOC")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically reusing the operand_identifier as an flag, right? I suggest introducing that flag instead.

@@ -36,7 +36,7 @@ TEST(diagnostics, overall_correctness)

ASSERT_EQ(a.parser().getNumberOfSyntaxErrors(), (size_t)0);

ASSERT_EQ(dynamic_cast<hlasm_plugin::parser_library::diagnosable*>(&a)->diags().size(), (size_t)0);
ASSERT_EQ(dynamic_cast<hlasm_plugin::parser_library::diagnosable*>(&a)->diags().size(), (size_t)1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ASSERT_EQ(dynamic_cast<hlasm_plugin::parser_library::diagnosable*>(&a)->diags().size(), (size_t)1);
ASSERT_EQ(dynamic_cast<hlasm_plugin::parser_library::diagnosable*>(&a)->diags().size(), (size_t)0);

I suggest fixing the source instead.

@@ -236,7 +236,7 @@ TEST(diagnostics, mnemonics)

ASSERT_EQ(a.parser().getNumberOfSyntaxErrors(), (size_t)0);

ASSERT_EQ(dynamic_cast<hlasm_plugin::parser_library::diagnosable*>(&a)->diags().size(), (size_t)0);
ASSERT_EQ(dynamic_cast<hlasm_plugin::parser_library::diagnosable*>(&a)->diags().size(), (size_t)20);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ASSERT_EQ(dynamic_cast<hlasm_plugin::parser_library::diagnosable*>(&a)->diags().size(), (size_t)20);
ASSERT_EQ(dynamic_cast<hlasm_plugin::parser_library::diagnosable*>(&a)->diags().size(), (size_t)0);

The same here, we should be able to create jump targets that are far enough.

else if (res.value_kind() == context::symbol_value_kind::RELOC && type_hint
&& *type_hint == checking::machine_operand_type::RELOC_IMM)
{
return std::make_unique<checking::one_operand>("RELOC", res.get_reloc().offset());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code would accept instructions like:

RELOC LR 1,1
 EXRL 1,RELOC+5
 EXRL 1,RELOC+RELOC

The second one is definitely invalid, I am not sure about the first one.
We should generate this special operand only when the relocatable symbol is not complex (res.get_reloc().is_simple()) and maybe even just when it is just a simple symbol (not sure about the latter).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the exrl takes the difference in halfwords (multiples of 2 bytes), so reloc+5 cannot be represented at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but RELOC+4 would be fine?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, reloc+4 is ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Length being multiple of 2 bytes holds true only for exrl instruction or for all instructions with relative addressing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I know, it's for all reladdr operands.

SWETAS04 added 3 commits May 13, 2021 16:54
Signed-off-by: Sweta Shah <swetas04@GMAIL.COM>
Signed-off-by: Sweta Shah <swetas04@GMAIL.COM>
Comment on lines 157 to 160
if (lc.get_reloc().offset() > symb.get_reloc().offset())
return (left_->evaluate(info) - right_->evaluate(info));
else
return (right_->evaluate(info) - left_->evaluate(info));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this part... relative address may very well be positive or negative.
I'd expect simply target-location.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks for pointing out. I misunderstood it as difference should be always positive value, will change it to target - location.

SWETAS04 and others added 9 commits May 14, 2021 10:40
Co-authored-by: slavek-kucera <53339291+slavek-kucera@users.noreply.github.com>
Signed-off-by: Sweta Shah <swetas04@GMAIL.COM>
Signed-off-by: Sweta Shah <swetas04@GMAIL.COM>
Signed-off-by: Sweta Shah <swetas04@GMAIL.COM>
{
// replaced operands are skipped being immediate values
if (replaced.size() != 0 && replaced.at(position).first == position)
if (!replaced.empty() && replaced.at(position).first == position)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is wrong... The replaced vector contains index, value pairs, so if the replacement occurs at position 3, it contains a single pair 3,value, so .at(3) will throw.
Also there may be multiple replacements in a row, so this should probably be some kind of loop.

@michalbali256 - do you concur?

Comment on lines 546 to 551
if (auto mnem_tmp = context::instruction::mnemonic_codes.find(*instruction);
mnem_tmp != context::instruction::mnemonic_codes.end())
{
instruction_name = context::instruction::mnemonic_codes.at(*instruction).instruction->instr_name;
replaced = context::instruction::mnemonic_codes.at(*instruction).replaced;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified a bit to something like

Suggested change
if (auto mnem_tmp = context::instruction::mnemonic_codes.find(*instruction);
mnem_tmp != context::instruction::mnemonic_codes.end())
{
instruction_name = context::instruction::mnemonic_codes.at(*instruction).instruction->instr_name;
replaced = context::instruction::mnemonic_codes.at(*instruction).replaced;
}
const machine_instruction* instr;
const std::vector<std::pair<size_t, size_t>>* replaced = nullptr;
if (auto mnem_tmp = context::instruction::mnemonic_codes.find(*instruction);
mnem_tmp != context::instruction::mnemonic_codes.end())
{
instr = mnem_tmp->instruction;
replaced = &mnem_tmp->replaced;
}
else
{
instr = &context::instruction::machine_instructions.at(*instruction);
}

but it needs to be properly incorporated into the rest of the code

{
if (instruction->empty())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when does this happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a test "parse_bad_model" where it occurs

@SWETAS04 SWETAS04 requested a review from slavek-kucera June 9, 2021 10:57
Copy link
Contributor

@slavek-kucera slavek-kucera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

parser_library/src/diagnostic.cpp Outdated Show resolved Hide resolved
{
return diagnostic_op(diagnostic_severity::error,
"ME003",
"Relative Immediate Operand value must be signed number of halfwords.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message implies to me, that the user should write a number as the argument.

Suggested change
"Relative Immediate Operand value must be signed number of halfwords.",
"Relative immediate operand must evaluate into a number of halfwords (must result in even number of bytes)",

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just Relative immediate operand must evaluate into an even offset?

checking::address_state::UNRES, 0, 0, 0, checking::operand_state::ONE_OP);
}
}
std::unique_ptr<checking::operand> check_operand(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you rename this method? Now, it is not clear what is the difference between methods check_operand and make_check_operand

SWETAS04 and others added 3 commits June 9, 2021 15:42
Co-authored-by: Michal Bali <38988507+michalbali256@users.noreply.github.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 9, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

96.3% 96.3% Coverage
0.0% 0.0% Duplication

@michalbali256 michalbali256 merged commit e097903 into eclipse-che4z:development Jun 9, 2021
@slavek-kucera slavek-kucera linked an issue Jul 7, 2021 that may be closed by this pull request
@github-actions
Copy link

🎉 This PR is included in version 0.14.0-beta.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This PR is included in version 0.14.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EXRL instruction flagged as error by plugin
3 participants