Skip to content

Draft: meson: increase compiler checks#7

Open
vjardin wants to merge 3 commits intomainfrom
vj_fixcompile
Open

Draft: meson: increase compiler checks#7
vjardin wants to merge 3 commits intomainfrom
vj_fixcompile

Conversation

@vjardin
Copy link
Owner

@vjardin vjardin commented Nov 26, 2025

Use:
'warning_level=everything',
'werror=true',

 Use:
    'warning_level=everything',
    'werror=true',
@vjardin vjardin requested review from Copilot and thbtcllt and removed request for Copilot November 26, 2025 01:38
@vjardin vjardin changed the title meson: increase compiler checks Draft: meson: increase compiler checks Nov 26, 2025
TODO: set Werror only for runners on github.
gcc provides good tips on pure C functions, let's ack't them.

pure: functions that are idempotent since they do not rely on internal
states. They are like some "const", weaker. They do not have side
effects.

use case:
  x = le16(p);
  y = le16(p);
could be optimized to:
  x = le16(p); # le16 is pure
  y = x;
Copilot AI review requested due to automatic review settings November 26, 2025 08:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR increases the compiler warning level from 3 to "everything" in the Meson build configuration, addressing warnings that arise from stricter compiler checks. The PR is marked as draft with werror=true commented out, indicating that not all warnings may be resolved yet.

  • Introduces a D() macro for explicit double type conversions to satisfy type-checking warnings
  • Adds self-header includes to all implementation files to ensure header self-containment
  • Converts type declarations from int to more appropriate types (size_t, uint8_t) for improved type safety

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
meson.build Changes warning level from 3 to "everything"; werror commented out (draft)
src/pmbus_io.h Adds D() macro for double casts, BMR_PURE attribute, changes pmbus_wr_block len param to uint8_t
src/pmbus_io.c Updates le16/le32 formatting, adds BMR_PURE attributes, updates pmbus_wr_block signature
src/util_lin.h Updates u16_round_sat_pos with D() macro, changes literals to UINT16_MAX, includes pmbus_io.h
src/util_json.c Changes add_hex_ascii parameter from int to size_t, adds proper casts
src/temp_cmd.c Rewrites sign_extend function to avoid UB, adds epsilon-based zero comparison, adds assert.h
src/timing_cmd.c Adds explicit padding field (__pad1) to timing_profile struct
src/read_cmd.c Adds default case with __builtin_unreachable() to switch statement
src/operation_cmd.c Adds default case with error handling to switch statement
src/fault_cmd.c Adds default case returning error string to resp_mode_name function
src/mfr_user_data.c Changes loop variable and length tracking from int to size_t, adds length validation
src/mfr_hrr.c Introduces FLAG_SET8/CLEAR8/ISSET8 macros for type-safe flag operations
src/mfr_fwdata.c Changes loop variables from int to size_t
src/main.c Changes opt_addr from int to uint8_t
src/vout_cmd.c Updates double literals using D() macro
src/vin_cmd.c Adds self-header include
src/write_protect_cmd.c Adds self-header include
src/status_cmd.c Adds self-header include
src/salert_cmd.c Adds self-header include
src/rw_cmd.c Adds self-header include
src/pgood_cmd.c Adds self-header include
src/onoff_cmd.c Adds self-header include
src/mfr_status_data.c Adds self-header include
src/mfr_snapshot.c Adds self-header include
src/mfr_save_restore.c Adds self-header include
src/mfr_restart.c Adds self-header include
src/mfr_ramp_data.c Adds self-header include
src/mfr_multipin.c Adds self-header include
src/mfr_id.c Adds self-header include
src/mfr_addr_offset.c Adds self-header include
src/interleave_cmd.c Adds self-header include
src/freq_cmd.c Adds self-header include
src/capability_cmd.c Adds self-header include

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (v == D(0.0f))
return 0;
#else
/* epsilon: smallest assume it is same than 0 */
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

Typo in comment: "smallest assume it is same than 0" should be "smallest value assumed to be the same as 0" or similar.

Suggested change
/* epsilon: smallest assume it is same than 0 */
/* epsilon: values smaller than this are assumed to be zero */

Copilot uses AI. Check for mistakes.
return 0;
#else
/* epsilon: smallest assume it is same than 0 */
const double lin11_eps = D(1.0f / (float)(1u << 16));
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

[nitpick] The expression D(1.0f / (float)(1u << 16)) performs the division in float precision before casting to double. This can lead to precision loss. Consider using 1.0 / (double)(1u << 16) or D(1.0) / D(65536.0) to ensure the calculation is done in double precision.

Suggested change
const double lin11_eps = D(1.0f / (float)(1u << 16));
const double lin11_eps = D(1.0) / D(65536.0);

Copilot uses AI. Check for mistakes.
@@ -5,6 +5,15 @@
#include <stdint.h>
#include <stdbool.h>

Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

[nitpick] The D() macro casts float literals to double, but using float literals (e.g., 0.0f) that are then cast to double is unnecessary and may reduce precision. Consider using double literals directly (e.g., 0.0 instead of D(0.0f)) to avoid the intermediate float conversion and potential precision loss.

Suggested change
/* Use double literals (e.g., 0.0), not float literals (e.g., 0.0f), with D() to avoid unnecessary float-to-double conversion and potential precision loss. */

Copilot uses AI. Check for mistakes.
json_object_set_new(o, "dls_mode", json_string(((uint8_t) rb & BIT_DLS) ? "nonlinear" : "linear"));
json_object_set_new(o, "artdlc_enabled", json_boolean(!!((uint8_t) rb & BIT_ARTDLC)));
json_object_set_new(o, "dbv_enabled", json_boolean(!!((uint8_t) rb & BIT_DBV)));
json_object_set_new(o, "require_pec", json_boolean(FLAG_ISSET8(rb,BIT_PEC)));
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

Missing space after FLAG_ISSET8(rb, - there should be a space after the comma for consistency with the other calls on lines 225-228.

Suggested change
json_object_set_new(o, "require_pec", json_boolean(FLAG_ISSET8(rb,BIT_PEC)));
json_object_set_new(o, "require_pec", json_boolean(FLAG_ISSET8(rb, BIT_PEC)));

Copilot uses AI. Check for mistakes.
u16_round_sat_pos(double x) {
if (isnan(x))
return 0;
if ((x <= D(0.0f)) || isnan(x))
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

The condition check (x <= D(0.0f)) now rejects zero values, but the original code only checked if x was NaN. This changes the function behavior - zero is a valid positive value that should return 0, not be rejected. The condition should be (x < D(0.0f)) (strictly less than) rather than <= to maintain the original behavior for zero.

Suggested change
if ((x <= D(0.0f)) || isnan(x))
if ((x < D(0.0f)) || isnan(x))

Copilot uses AI. Check for mistakes.

if (pmbus_wr_block(fd, MFR_USER_DATA_00, b, n) < 0) {
if (n > 255) {
fprintf(stderr, "USER_DATA_00 write: len %zu > 255", n);
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

Missing newline character at end of error message. The error message should end with \n for consistent formatting: fprintf(stderr, "USER_DATA_00 write: len %zu > 255\n", n);

Suggested change
fprintf(stderr, "USER_DATA_00 write: len %zu > 255", n);
fprintf(stderr, "USER_DATA_00 write: len %zu > 255\n", n);

Copilot uses AI. Check for mistakes.
Comment on lines +115 to +119
return (uint16_t)(
(uint16_t)p[0]
| ((uint16_t)p[1] << 8)
);

Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

[nitpick] Inconsistent formatting: the closing parenthesis and semicolon are on a separate line with extra blank line, while le32 below maintains the traditional formatting. Consider keeping the formatting consistent between these two functions.

Suggested change
return (uint16_t)(
(uint16_t)p[0]
| ((uint16_t)p[1] << 8)
);
return (uint16_t) p[0]
| ((uint16_t) p[1] << 8)
;

Copilot uses AI. Check for mistakes.
json_object_set_new(dst, "ascii", json_stringn((const char *) buf, n));

char *hex = (char *) malloc((size_t) n * 2 + 1);
char *hex = (char *) malloc(n * 2 + 1);
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

Missing NULL check after malloc. If malloc fails and returns NULL, the subsequent sprintf call on line 17 will cause a segmentation fault. Add a NULL check: if (!hex) return; or similar error handling.

Suggested change
char *hex = (char *) malloc(n * 2 + 1);
char *hex = (char *) malloc(n * 2 + 1);
if (!hex)
return;

Copilot uses AI. Check for mistakes.
break;
default:
fprintf(stderr, "invalid pmbus operation\n");
return 2;
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

Tab character used for indentation instead of spaces. This is inconsistent with the surrounding code which uses spaces.

Suggested change
return 2;
return 2;

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@thbtcllt thbtcllt left a comment

Choose a reason for hiding this comment

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

Set warning_level to everything is a little bit excessive.
Fix some warnings will lead to strange code especially when MACRO are used.
For example to fix the clang warning:
STATUS_TEMPERATURE_FIELDS(EMIT_STATUS_BYTE);
it is necessary to remove the ';' that will be very ugly when we read the code.

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.

3 participants