Skip to content

Conversation

@mkannwischer
Copy link
Contributor

This commit enables additional warnings (-Wconversion, -Wsign-conversions) requiring more explicit casts.
All of those casts should already be safe as checked by CBMC.

@mkannwischer mkannwischer force-pushed the wconversion branch 4 times, most recently from 878529f to 776981c Compare October 24, 2025 04:58
@mkannwischer mkannwischer marked this pull request as ready for review October 24, 2025 07:03
@mkannwischer mkannwischer requested a review from a team as a code owner October 24, 2025 07:03
Copy link
Contributor

@hanno-becker hanno-becker left a comment

Choose a reason for hiding this comment

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

Thank you @mkannwischer for embarking on this! There are a few cases where I think we should document why the cast is safe, or try to avoid it altogether. Otherwise, we may as well leave the warnings off.

@mkannwischer mkannwischer force-pushed the wconversion branch 2 times, most recently from 51a6d72 to 3b6dd16 Compare October 25, 2025 05:35
@mkannwischer mkannwischer force-pushed the wconversion branch 2 times, most recently from 85beb05 to 3858af1 Compare October 25, 2025 10:11
Copy link
Contributor

@hanno-becker hanno-becker left a comment

Choose a reason for hiding this comment

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

Thank you @mkannwischer, this is definitely an improvement. I quite like how the conversion warnings force you to think about the bounds.

This commit introduces helper functions mld_cast_uint32_to_int32,
mld_cast_int32_to_uint32, and mld_cast_int64_to_uint32
for int64_t->uint32_t, and int32_t <-> uint32_t.

This cleans up prior code and also removes the need for some pragmas stopping
CBMC from flagging value-changing integer conversions.

This commit is based on
pq-code-package/mlkem-native@e5adf3a
(but for 32-bit integers.

Signed-off-by: Matthias J. Kannwischer <[email protected]>
This commit enables additional warnings (-Wconversion, -Wsign-conversions)
requiring more explicit casts.
All of those casts should already be safe as checked by CBMC.

Resolves #543

Signed-off-by: Matthias J. Kannwischer <[email protected]>
Since the addition of -Wconversion and -Wsign-conversion to the default
CFLAGS, compilation of the CMSIS files for AN547 fails.

This commit allows custom Makefiles to not only provide EXTRA_SOURCES
to specify additional sources, but also EXTRA_SOURCES_CFLAGS for additional
CFLAGS, which in particular may overwrite default CFLAGS (they apply later).

This is leveraged in the case of m55-an547/platform.mk to disable
conversion and sign-conversion warnings for all CMSIS files.

Port of
pq-code-package/mlkem-native@15fa58e

Signed-off-by: Matthias J. Kannwischer <[email protected]>
@mkannwischer mkannwischer merged commit 056f91d into main Oct 25, 2025
245 checks passed
@mkannwischer mkannwischer deleted the wconversion branch October 25, 2025 12:20
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.

Add -Wconversion and -Wsign-conversion warnings (and resolve findings)

3 participants