Skip to content

Remove unreachable statements warnings #11439

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

Merged

Conversation

hugueskamba
Copy link
Collaborator

Description

Remove unreachable statements warnings reported when building with the IAR toolchain.

Warnings observed when building the mbed-os-example-blinky example project with the following command:
mbed compile -t IAR -m K64F

Pull request type

[X] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

Release Notes

@ciarmcom ciarmcom requested review from a team September 9, 2019 09:00
@ciarmcom
Copy link
Member

ciarmcom commented Sep 9, 2019

@hugueskamba, thank you for your changes.
@ARMmbed/mbed-os-hal @ARMmbed/mbed-os-core @ARMmbed/mbed-os-maintainers please review.

evedon
evedon previously requested changes Sep 9, 2019
@hugueskamba hugueskamba force-pushed the hk-remove-unreachable-statement-warnings branch from 1041181 to f02a4f1 Compare September 10, 2019 06:28
@hugueskamba hugueskamba force-pushed the hk-remove-unreachable-statement-warnings branch from f02a4f1 to 682e2ef Compare September 10, 2019 07:02
@kjbracey
Copy link
Contributor

Note that some environments would actually treat an ASSERT as a guarantee in a release build - they might optimise the rest of the code on the assumption that the condition wasn't met.

For example:

 CUSTOM_ASSERT(x > 3);
 if (x <= 3) {
      return;
 }

When NDEBUG is off, the compiler must check for !(x > 3) in the assert, and if it knows an assert failure doesn't return, then it knows x > 3 if it reaches the if, so it doesn't need to actually put the if (x <=3) return; code in, and probably won't.

But conceivably in a release build with NDEBUG, it could leave out the assert failure check, but still believe the assertion - assume that x > 3 as we claim, and hence still leave out the if. (This would be achieved by using a __builtin_unreachable() directive in the NDEBUG assert implementation).

We (and the standard C library assert) don't do that - instead both guarantee that our macro does nothing if NDEBUG is set, rather than believing the assertion. But it is a possible different assert implementation.

I guess my point is to consider what would happen if the compiler believed our assertions. Would the rest of the code make sense? If not, you probably want to have more explicit "if (condition) error or return" code.

@0xc0170 0xc0170 requested a review from evedon September 10, 2019 09:17
@hugueskamba hugueskamba force-pushed the hk-remove-unreachable-statement-warnings branch from 682e2ef to eb5574d Compare September 11, 2019 09:26
@hugueskamba
Copy link
Collaborator Author

This force-push uses the "if (condition) error or return" code instead of assertions.

Copy link
Contributor

@kjbracey kjbracey left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me.

@hugueskamba hugueskamba force-pushed the hk-remove-unreachable-statement-warnings branch from eb5574d to e58f40b Compare September 11, 2019 10:57
@0xc0170
Copy link
Contributor

0xc0170 commented Sep 11, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Sep 11, 2019

Test run: FAILED

Summary: 1 of 4 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-IAR

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 12, 2019

CI restarted

@mbed-ci
Copy link

mbed-ci commented Sep 12, 2019

Test run: FAILED

Summary: 2 of 11 test jobs failed
Build number : 2
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test
  • jenkins-ci/mbed-os-ci_cloud-client-test

@mbed-ci
Copy link

mbed-ci commented Sep 12, 2019

Test run: FAILED

Summary: 3 of 4 test jobs failed
Build number : 3
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-IAR

@hugueskamba
Copy link
Collaborator Author

Test run: FAILED

Summary: 3 of 4 test jobs failed
Build number : 3
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-IAR

@0xc0170,
Is this an internal error? I am sure which log file to look at.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 12, 2019

Will restart after rc2 generation, need 2 more patches to get in

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 12, 2019

Aborted, rc2 jobs are in now, will be restarted

@mbed-ci
Copy link

mbed-ci commented Sep 12, 2019

Test run: FAILED

Summary: 6 of 11 test jobs failed
Build number : 4
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_mbed2-build-ARM
  • jenkins-ci/mbed-os-ci_cloud-client-test
  • jenkins-ci/mbed-os-ci_mbed2-build-IAR
  • jenkins-ci/mbed-os-ci_dynamic-memory-usage
  • jenkins-ci/mbed-os-ci_greentea-test
  • jenkins-ci/mbed-os-ci_exporter

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 12, 2019

Ci restarted

@mbed-ci
Copy link

mbed-ci commented Sep 12, 2019

Test run: FAILED

Summary: 2 of 11 test jobs failed
Build number : 5
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_cloud-client-test
  • jenkins-ci/mbed-os-ci_greentea-test

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 13, 2019

tests restarted

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 16, 2019

Ci restarted again

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 18, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Sep 18, 2019

Test run: FAILED

Summary: 2 of 11 test jobs failed
Build number : 6
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_cloud-client-test
  • jenkins-ci/mbed-os-ci_greentea-test

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 18, 2019

Test restarted

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 19, 2019

CI restarted again

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 20, 2019

Restarted entire pipeline

@mbed-ci
Copy link

mbed-ci commented Sep 20, 2019

Test run: FAILED

Summary: 2 of 11 test jobs failed
Build number : 7
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_cloud-client-test
  • jenkins-ci/mbed-os-ci_greentea-test

@@ -41,8 +41,9 @@ static void initialize(const ticker_data_t *ticker)

const ticker_info_t *info = ticker->interface->get_info();
uint32_t frequency = info->frequency;

MBED_ASSERT(info->frequency == 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please review latest failures. Looks like we are hitting this assert in the tests. ERROR reported for all platforms there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The warnings are observed when building with the IAR toolchain.
@hugueskamba hugueskamba force-pushed the hk-remove-unreachable-statement-warnings branch from e58f40b to 5724c4c Compare September 23, 2019 10:58
@hugueskamba
Copy link
Collaborator Author

This force-push uses the "if (condition) error or return" code instead of assertions for mbed-os/hal/mbed_ticker_api.c.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 24, 2019

CI restarted

@mbed-ci
Copy link

mbed-ci commented Sep 24, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 8
Build artifacts

@0xc0170 0xc0170 merged commit ba7b479 into ARMmbed:master Sep 26, 2019
@hugueskamba hugueskamba deleted the hk-remove-unreachable-statement-warnings branch December 22, 2019 22:12
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.

6 participants