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

Switch From Clang To GCC #1184

Merged

Conversation

garethellis0
Copy link
Contributor

@garethellis0 garethellis0 commented Feb 29, 2020

Please fill out the following before requesting review on this PR

Description

This is basically #1177 with some extra changes to fix test segfaults, build issues, and code coverage.

Testing Done

Builds and passes in CI, coverage is properly generated.

Resolved Issues

resolves #1124

Length Justification

Review Checklist

It is the reviewers responsibility to also make sure every item here has been covered

  • Function & Class comments: All function definitions (usually in the .h file) should have a javadoc style comment at the start of them. For examples, see the functions defined in thunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class.
  • Remove all commented out code
  • Remove extra print statements: for example, those just used for testing
  • Resolve all TODO's: All TODO (or similar) statements should either be completed or associated with a github issue
  • Justify drops in code coverage: If this PR results in a non-trivial drop in code coverage (a bot should post a coverage diagram as a comment), please justify why we can't test the code that's not covered.

@MathewMacDougall
Copy link
Contributor

@jonathanlew segfaults were due to variables in some of my physics tests being destroyed in a different order due to change in compilers. In some low-level tests certain variables must always be destroyed first due to how Box2D manages its pointers.

@garethellis0
Copy link
Contributor Author

Looks a lot cleaner. I'm not sure how you fixed the segfaults but I'm glad you did. Can you also comment on why we need a build switch?

Sorry, not sure what a "build switch" is?

Copy link
Contributor

@MathewMacDougall MathewMacDougall left a comment

Choose a reason for hiding this comment

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

another question for my sanity

- bash <(curl -s https://codecov.io/bash)
# Build our CPU-specific targets
- bazel build //firmware_new/... --cpu=stm32h7
bazel coverage //software/... \
Copy link
Contributor

Choose a reason for hiding this comment

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

just want to double check. Bazel's CLI-Reference says the coverage command "Generates code coverage report for specified test targets". It seems it's roughly the same as test but with coverage. Does this mean we're not building all the code, ie. missing the top-level code not associated with tests?

I know we need to build code with covarege enabled to get the coverage data (so doesn't make sense to necessarily call build here).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, I just thought of this while I was cleaning this up..........

We could run bazel build //software:full_system_main as well, but the different command line options would probably trigger a re-compile of basically everything.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe worth trying locally. Or perhaps we can somehow pass the coverage flags to build first? My understanding is that the main difference is the extra symbols / tracking built in for coverage to consume

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just made some changes to full_system_main.cpp and it failed. No test depends on that target, so looks like bazel builds everything. So this is actually a non-issue! 🎉

@jonathanlew
Copy link
Contributor

Looks a lot cleaner. I'm not sure how you fixed the segfaults but I'm glad you did. Can you also comment on why we need a build switch?

Sorry, not sure what a "build switch" is?

Commented in line

@jonathanlew jonathanlew mentioned this pull request Mar 2, 2020
5 tasks
Copy link
Member

@akhilveeraghanta akhilveeraghanta left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:

jonathanlew
jonathanlew previously approved these changes Mar 5, 2020
Copy link
Contributor

@jonathanlew jonathanlew left a comment

Choose a reason for hiding this comment

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

LGTM pending CI 👍

@MathewMacDougall
Copy link
Contributor

Ok so after some investigation it turns out you can't pass matrices as float** in c++. This is the cause of the CI failure.

Eg.

void matrix_test(int rows, int cols, float** matrix){
    for (int i = 0; i < rows; i++){
        for (int j = 0; j < cols; j++){
            volatile float a = matrix[i][j];
        }
    }
}
int main(int argc, char ** argv) {
    int num_rows = 10;
    int num_cols = 10;
    float matrix[num_rows][num_cols];
    for (int i = 0; i < num_rows; i++) {
        for (int j = 0; j < num_cols; j++){
            matrix[i][j] = i*j;
        }
    }
    matrix_test(num_rows, num_cols, matrix);
}

This is valid C code, but invalid C code. (although C does throw a warning).

The easiest solution was to move the offending matrix / linear algebra code to a new file and build target, so it can be purely built as C and use Variable Length Arrays. We should consider proper "Shareable" matrix and vector types moving forwards, but that's out of scope for this PR.

The commits I pushed move the matrix functions to a new file, and also removed any unused functions.

Copy link
Contributor

@MathewMacDougall MathewMacDougall left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Contributor

@jonathanlew jonathanlew left a comment

Choose a reason for hiding this comment

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

👍

@garethellis0 garethellis0 merged commit 86498cd into UBC-Thunderbots:master Mar 6, 2020
@garethellis0 garethellis0 deleted the gareth/switch-to-gcc branch March 6, 2020 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compile Software with gcc instead of clang
5 participants