llvm / llvm/llvm-project

PPMemoryAllocationsTest.PPMacroDefinesAllocations fails under AddressSanitizer

Open Beginner friendly
#207,084 1 comment 0 reactions 0 assignees View on GitHub
clang test-suite
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The test `PPMemoryAllocationsTest.PPMacroDefinesAllocations` in `clang/unittests/Lex/PPMemoryAllocationsTest.cpp` fails when building with `-DLLVM_USE_SANITIZER='Address'`:

```
Preprocessor allocator memory for 1000000 #define: 136839168
Bytes per #define: 1.368392e+02
clang/unittests/Lex/PPMemoryAllocationsTest.cpp:92: Failure
Expected: (BytesPerDefine) < (130.0f), actual: 136.839172 vs 130
```

It looks like the test asserts that per #define memory usage stays below 130 bytes. Under ASAN, the BumpPtrAllocator adds a red zone to every allocation (controlled by RedZoneSize). This inflates total slab memory from approx 120 to approx 137 bytes per define, exceeding the threshold.

This was introduced in https://github.com/llvm/llvm-project/pull/205711 which restructured RedZoneSize gating. The commit message states the test was validated at "120.06 B/define". It looks like that measurement was done without ASAN. Leading to a bug.

I propose to add something like:
```
#if LLVM_ADDRESS_SANITIZER_BUILD
// ASAN red zones add overhead to each bump-ptr allocation within the slab.
EXPECT_LT(BytesPerDefine, 140.0f);
#else
EXPECT_LT(BytesPerDefine, 130.0f);
#endif
```

Contributor guide

Open the contributing guide

Research direction

Start in clang/unittests/Lex/PPMemoryAllocationsTest.cpp at PPMemoryAllocationsTest.PPMacroDefinesAllocations and compare the existing expectation with normal and AddressSanitizer builds. Update the sanitizer-specific allocation bound described in the issue, then run this test in both configurations and confirm each reports passing results.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.