microsoft / microsoft/STL

`<expected>`: Investigate reusing tail padding of the union

Open
#4,131 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

performance
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

Given [[msvc::no_unique_address]] landed in Clang 18, we can applied it to union members (possibly with the whole union) in expected.

E.g. in this example

struct IC {
    int i;
    char c;
};
std::expected<IC, int> e;

its possible to make sizeof(e) == 8 because the size of the union is 8, while the first 5 bytes are value bytes, and bool flag can live in the tail padding of the union.

We need to ensure that the tail padding won't be furtherly reused - otherwise, when the expected object is itself potentially-overlapping, reconstruction of a union member may overwrite the data not controlled by the implementation.

See also LLVM-68552, LLVM-68733, and LLVM-69673.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test is named; start by reading the expected implementation and the referenced LLVM-68552, LLVM-68733, and LLVM-69673 issues. Determine whether union tail padding can safely hold the flag and whether further reuse is prevented, then validate the proposed layout with the supplied IC example.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.