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

Avoid creating an empty if block #83

Closed
rfalke opened this issue Jan 10, 2018 · 2 comments
Closed

Avoid creating an empty if block #83

rfalke opened this issue Jan 10, 2018 · 2 comments

Comments

@rfalke
Copy link

rfalke commented Jan 10, 2018

Version: web version at https://retdec.com/service/api
File: https://github.com/rfalke/decompiler-subjects/tree/master/from_holdec/condition_structure/ia32_elf
Output:

// Address range: 0x8048437 - 0x8048465
int32_t test_1_blocks_1_targets_direct_variant_0(void) {
    // 0x8048437
    if (g2 == 0) {
        // 0x8048437
        // branch -> 0x8048439
    } else {
        // 0x8048457
        puts("then/else block 3");
        // branch -> 0x8048439
    }
    // 0x8048439
    puts("return block");
    return 0;
}

Expected:

The condition should be inverted and there should only be the then-block without else.

@s3rvac
Copy link
Member

s3rvac commented Jan 11, 2018

Thank you for the report. I confirm that the empty body of the if statement is also generated by the current master (8c4b23d).

@s3rvac s3rvac changed the title Avoid creating empty block Avoid creating an empty if block Jan 11, 2018
PeterMatula added a commit to avast/retdec-regression-tests that referenced this issue Feb 21, 2019
@PeterMatula
Copy link
Collaborator

Output by the current master, after the new LLVM IR to BIR convertor became the default convertor in llvmir2hll:

// Address range: 0x8048437 - 0x8048466
int32_t test_1_blocks_1_targets_direct_variant_0(void) {
    // 0x8048437
    if (g4 != 0) {
        // 0x8048457
        puts("then/else block 3");
    }
    // 0x8048439
    puts("return block");
    return 0;
}

I can't say empty if bodies are never going to be generated, but the current output (all the functions) look quite ok at the moment - nice test binary by the way. If you come across another issue, open an issue :-)
I added regression test (avast/retdec-regression-tests@82b3735) for the reported problem, but unfortunately I did not came up with a way to test all the control-flow structures in all the functions. The test itself is quite ugly - hard-coded string to check for. I don't think we have a better mechanism to check for things like this, and it would be a lot of work anyway, since there is a huge number of test cases in the subject.exe sample.

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

No branches or pull requests

3 participants