llvm / llvm/llvm-project

`[[clang::trivial_abi]]` on class with non-trivial for purposes of calls members is not ignored

Open
#215,142 3 comments 0 reactions 0 assignees View on GitHub
clang:codegen
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

https://godbolt.org/z/jWcYsG3Tx

```cpp
struct B {
~B();
};

struct
[[clang::trivial_abi]]
A {
B b;
};

static_assert(__can_pass_in_regs(A));

[[gnu::weak]]
void consume(A){}

void use() { consume(A{}); }
```

Note destructor of B in consume asm

Removing the attribute: https://godbolt.org/z/E39x4nb15
No destructor in consume

From docs https://clang.llvm.org/docs/AttributeReference.html#trivial-abi
> Attribute trivial_abi has no effect in the following cases:
> The class has a non-static data member whose type is non-trivial for the purposes of calls

Contributor guide

Open the contributing guide

Research direction

Reproduce the example on the linked Godbolt pages and compare the generated consume assembly with and without [[clang::trivial_abi]]. Read the trivial_abi documentation cited in the issue, then trace Clang's handling of classes with members non-trivial for calls. Done means behavior matches the documented exception and a regression test covers this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.