Skip to content

Conversation

@aborisovich
Copy link
Contributor

@aborisovich aborisovich commented Feb 14, 2023

New Xtensa xt-clang driver issues new warnings that were not present before when using xt-xcc driver.
Fixed warnings related to enum cast to other enum. Silenced warnings related to C/C++ interoptability.

Signed-off-by: Andrey Borisovich andrey.borisovich@intel.com

Copy link
Collaborator

@paulstelian97 paulstelian97 left a comment

Choose a reason for hiding this comment

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

Your change can hide a genuine bug (at least from a superficial analysis); see review comments.

I could probably approve this if given a good answer in that situation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to have a conversion between different enums in the first place?

Copy link
Member

Choose a reason for hiding this comment

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

@aborisovich which enums are impacted here ? Sounds like we may need an alignment.

Copy link
Contributor Author

@aborisovich aborisovich Feb 15, 2023

Choose a reason for hiding this comment

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

Well, when sof/lib/dai.h is included, depth is a uint32_t type member of dai_plat_fifo_data struct.
However when we compile with IPC4 config option, header src\include\ipc4\base-config.h is used and depth is enum ipc4_bit_depth type what causes the warning:

implicit conversion from enumeration type 'enum ipc4_bit_depth' to different enumeration type 'enum sof_ipc_frame' [-Wenum-conversion]

Copy link
Contributor Author

@aborisovich aborisovich Feb 15, 2023

Choose a reason for hiding this comment

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

Yes, as @paulstelian97 indicated this looks like a serious bug.
Enums are implicitly cast to numerical values so what we do here,
is trying to assign one of the values from this set { 8, 16, 24, 32, 64, 65 } (values of enumerators of enum ipc4_bit_depth) as enumerator with such index to enum sof_ipc_frame which has enumerator values { 0, 1, 2, 3, 4 }.
I'm quite positive this is undefined behavior.

@aborisovich aborisovich changed the title Fixed warnings issued by new xt-clang compiler [DNM] Fixed warnings issued by new xt-clang compiler Feb 15, 2023
@aborisovich aborisovich marked this pull request as draft February 15, 2023 13:39
@aborisovich
Copy link
Contributor Author

Converted back to draft, we need to verify & fix the case with enum casting.

@aborisovich aborisovich force-pushed the fix-warnings-issued-by-xt-clang branch from 4ac827b to b346639 Compare February 16, 2023 23:09
@aborisovich aborisovich changed the title [DNM] Fixed warnings issued by new xt-clang compiler Fixed warnings issued by new xt-clang compiler Feb 16, 2023
@aborisovich aborisovich marked this pull request as ready for review February 16, 2023 23:10
@aborisovich
Copy link
Contributor Author

Resolved issue with enum casting - converting back to normal PR.
Resolution: removed assignment from incompatible enumerator value:
frame_fmt = cfg->base_cfg.audio_fmt.depth &
frame_fmt = cd->sink_format
Motivation: assignment is not needed. Actually frame_fmt variable is not needed at all in the body of the:
static void build_config(struct comp_data *cd, struct module_config *cfg)
function. audio_stream_fmt_conversion function writes to frame_fmt as output, so this assignments are pointless.
Existence of frame_fmt is actually pointless too, as cd->source_format and corresponding cd->sink_format could be used
as arguments to audio_stream_fmt_conversion function.

However, this PR is not about refactoring but fixing the warnings issues by xt-clang.
Why warnings are issued by clang? Because they can.
Some explanation from C standard draft ISO/IEC 9899:TC3:

Annex I
(informative)
Common warnings
An implementation may generate warnings in many situations, none of which are
specified as part of this International Standard. The following are a few of the more
common situations.
(...)

  • A value is given to an object of an enumerated type other than by assignment of an
    enumeration constant that is a member of that type, or an enumeration object that has
    the same type, or the value of a function that returns the same enumerated type
    (6.7.2.2).

Research done:

  • debugged build_ut/test/cmocka/src/audio/selector/selector_test unit test with GDB.
    Unfortunately, the test is not calling static void build_config(...) function that is a part of the static int selector_init(...) function, what is completely bizarre situation (unit tests not calling code under test?)
  • debugged some end-to-end tests on MTL from "TestDmicMicselPeakvolHdaPipe" family hoping to resolve related bugs but fixing enum assignments did not bring any improvement.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this file be in a separate commit?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Even if it's not a functional change, it very much looks like one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's focus on what it actually is and not what it looks to be. As some people say "don't judge the book by the cover" :-)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@aborisovich You do need to explain this in the git commit in some way why is it ok to remove these two lines. This is not unheard of to have code that doesn't do anything, but expectation is that you explain in commit to explain why this is the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok sure, I'll add some proper message

Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

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

Commit msg needs a bit more rationale...

Copy link
Collaborator

Choose a reason for hiding this comment

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

@aborisovich You do need to explain this in the git commit in some way why is it ok to remove these two lines. This is not unheard of to have code that doesn't do anything, but expectation is that you explain in commit to explain why this is the case.

@aborisovich aborisovich force-pushed the fix-warnings-issued-by-xt-clang branch from a203fb5 to e6ecc28 Compare February 17, 2023 09:18
@aborisovich
Copy link
Contributor Author

aborisovich commented Feb 17, 2023

You do need to explain this in the git commit in some way why is it ok to remove these two lines. This is not unheard of to have code that doesn't do anything, but expectation is that you explain in commit to explain why this is the case.

Provided more description to commit message. Is this ok now @kv2019i ?

@aborisovich aborisovich requested a review from kv2019i February 17, 2023 09:19
Copy link
Collaborator

@paulstelian97 paulstelian97 left a comment

Choose a reason for hiding this comment

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

I'm fine with the commit, just a few minor things with the message (that I can allow).

First, "interoperability" is the right spelling.

The other thing is I would have appreciated some blank lines between the individual paragraphs on the commit description.

@aborisovich aborisovich force-pushed the fix-warnings-issued-by-xt-clang branch from e6ecc28 to 6d406a3 Compare February 17, 2023 09:42
New Xtensa xt-clang driver issues new warnings that were not
present before when using xt-xcc driver.

Fixed warnings related to enum cast to other enum by removing
"frame_fmt" local variable assignment in the selector.c file.
Assignment was not needed in the build_config function body, as the
variable "frame_fmt" is passed in the next line to
audio_stream_fmt_conversion function, that writes to this variable as
output.

Silenced warnings related to C/C++ interoperability.

Signed-off-by: Andrey Borisovich <andrey.borisovich@intel.com>
@aborisovich aborisovich force-pushed the fix-warnings-issued-by-xt-clang branch from 6d406a3 to 13a86e8 Compare February 17, 2023 09:44
@aborisovich
Copy link
Contributor Author

First, "interoperability" is the right spelling.

Thanks for caching this, fixed the spelling. Added some line breaks too.

Copy link
Collaborator

@paulstelian97 paulstelian97 left a comment

Choose a reason for hiding this comment

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

Re-approving, looks good now. I'd suggest for future work to eventually look at the enum issue you uncovered in a previous version of this.

@kv2019i kv2019i requested a review from aiChaoSONG February 17, 2023 10:47
@kv2019i
Copy link
Collaborator

kv2019i commented Feb 17, 2023

This is racing with #7058 but as this now has tests passing and reviews are ok, let's have this go in first. @aiChaoSONG you probably need to rebase.

One fail in https://sof-ci.01.org/sofpr/PR7096/build4004/devicetest/index.html in the suspend-resume case, but seems unrelated to this PR. Proceeding with merge.

@kv2019i kv2019i merged commit 9453183 into thesofproject:main Feb 17, 2023
@aborisovich aborisovich deleted the fix-warnings-issued-by-xt-clang branch June 11, 2023 15:33
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.

9 participants