llvm / llvm/llvm-project

Codegen for type-aware allocation attempts to compute the size of an incomplete type when building in c++17 mode

Open
#212,675 8 comments 0 reactions 0 assignees View on GitHub
good first issue
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

I've been trying to build a self-targeting fuzzer that does not involve LLMs by working with the various builtin clang AST tooling. Focused solely on operator new because that is something I found bugs in today. Currently it is in no way scalable :D

That aside it found a bug \o/

Prior to c++23 deleting an incomplete object was UB but only produced a warning. In c++23 it became a hard error, but the type-aware allocator logic _assumes_ the c++23 behaviour. As a result building this with clang in c++17 mode this triggers an assertion during codegen:

```cpp
class Foo;
typedef __SIZE_TYPE__ size_t;
namespace std {
enum class align_val_t : size_t {};
template struct type_identity {
typedef T type;
};
}
template void operator delete(std::type_identity, void *, size_t, std::align_val_t);

void f(Foo *o) {
delete o;
}
```

With libc++ this requires a manual declaration of std::type_identity as it availability gates on the c++ version, I think stdlibc++ does not apply this restriction.

Two possible fixes:
1. Explicitly limit type-aware allocators to >= c++23
2. Reject/don't attempt type aware delete of incomplete types

I think there are reasonable arguments in both directions.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied operator-delete example in clang codegen under C++17, then trace the type-aware allocator logic for deletion of the incomplete Foo type. Review how the same case is treated in C++23 and determine which of the two proposed directions is consistent with the language rules. Done means the C++17 build no longer triggers the codegen assertion and the behavior is covered by an appropriate compiler test.

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.