Skip to content

build(linux): fix compilation with Clang #3998

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

Closed
wants to merge 1 commit into from

Conversation

AngryLoki
Copy link

@AngryLoki AngryLoki commented Jun 22, 2025

Description

Clang 20.1.7 fails with the following error:

/var/tmp/portage/net-misc/sunshine-2025.122.141614/work/Sunshine-2025.122.141614/src/platform/linux/misc.cpp:427:25: error: variable-sized object may not be initialized
  427 |       struct iovec iovs[(send_info.headers ? std::min(seg_max, send_info.block_count) : 1) * max_iovs_per_msg] = {};
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As VLAs are not part of the C++ standard, Clang barely supports their features. However, simple memset fixes the issue.

Issues Fixed or Closed

  • N/A

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update (updates to dependencies)
  • Documentation update (changes to documentation)
  • Repository update (changes to repository files, e.g. .github/...)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the in code docstring/documentation-blocks for new or existing methods/components

@AngryLoki AngryLoki changed the title Fix compilation with Clang build(linux): fix compilation with Clang Jun 22, 2025
@ReenigneArcher ReenigneArcher requested a review from Copilot June 22, 2025 22:45
Copy link

@Copilot 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 fixes a Clang compilation error by replacing inline initialization of variable-length arrays with explicit memset zeroing.

  • Removed direct initializer usage for VLAs and added memset calls to clear memory.
  • Applied the same fix to both iovs and msgs arrays in different code blocks.
Comments suppressed due to low confidence (2)

src/platform/linux/misc.cpp:427

  • Consider adding a short inline comment explaining that memset is used here to zero initialize the variable-length array because direct initializer lists are not supported by Clang.
      struct iovec iovs[(send_info.headers ? std::min(seg_max, send_info.block_count) : 1) * max_iovs_per_msg];

src/platform/linux/misc.cpp:511

  • Similarly, add a brief comment alongside the memset calls for msgs and iovs to clarify that this approach is a workaround for Clang's limitations with variable-length array initialization.
      struct mmsghdr msgs[send_info.block_count];

Clang 20.1.7 fails with the following error:
```
/var/tmp/portage/net-misc/sunshine-2025.122.141614/work/Sunshine-2025.122.141614/src/platform/linux/misc.cpp:427:25: error: variable-sized object may not be initialized
  427 |       struct iovec iovs[(send_info.headers ? std::min(seg_max, send_info.block_count) : 1) * max_iovs_per_msg] = {};
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

As VLAs are not part of the C++ standard, Clang barely support of their features. However, simple memset fixes the issue.
Copy link

sonarqubecloud bot commented Jul 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
1 New issue
1 New Code Smells (required ≤ 0)
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link

codecov bot commented Jul 6, 2025

Bundle Report

Bundle size has no change ✅

Copy link

codecov bot commented Jul 6, 2025

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 11.37%. Comparing base (7e95d53) to head (1b16ea6).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/platform/linux/misc.cpp 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3998      +/-   ##
==========================================
- Coverage   11.37%   11.37%   -0.01%     
==========================================
  Files          92       92              
  Lines       17549    17553       +4     
  Branches     8232     8231       -1     
==========================================
  Hits         1996     1996              
+ Misses      14868    13037    -1831     
- Partials      685     2520    +1835     
Flag Coverage Δ
Linux-AppImage 11.08% <0.00%> (-0.01%) ⬇️
Windows-AMD64 12.47% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/platform/linux/misc.cpp 9.58% <0.00%> (-0.09%) ⬇️

... and 31 files with indirect coverage changes

@cgutman
Copy link
Collaborator

cgutman commented Jul 6, 2025

Thanks for the contribution. I'm going to just remove the zeroing in #4052 since it's a bit overzealous anyway.

@cgutman cgutman closed this in #4052 Jul 6, 2025
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.

2 participants