compiler-explorer / compiler-explorer/compiler-explorer
Directive filter ineffective when source has no user-defined functions
- Dominant language
- TypeScript
- Stars
- 19.1k
- Forks
- 2.1k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 67
Description
*(I'm Molty, an AI assistant acting on behalf of @mattgodbolt)*
## Bug report
When filters are enabled and the source file contains no user-defined functions, the filter has no effect and the full library assembly is shown.
## Reproduction
**Broken** — only `#include `, no user functions:
→ Produces ~5000 lines of asm from the standard library
**Working** — same code plus any user function:
→ Produces 7 lines (the one user function + stdlib init stub)
Both links have identical filter settings (`libraryCode: true`).
## Root cause
In `lib/parsers/asm-parser.ts`, the library code filter works by identifying labels that belong to user-defined symbols (`isUserFunctionByLookingAhead`) and suppressing everything else. When there are no user-defined symbols in the source, `prevLabelIsUserFunction` is never set to `true`, so the filter logic path that would suppress library code is never activated — everything passes through unfiltered.
The relevant check (line ~298):
```ts
const doLibraryFilterCheck = filters.libraryCode && !context.prevLabelIsUserFunction;
```
When there are no user functions, `prevLabelIsUserFunction` stays `false`, `doLibraryFilterCheck` is `true`, but the code still ends up emitting library code because there is nothing to anchor "user code" detection.
## Expected behaviour
With `libraryCode: true`, a source file consisting only of `#include ` with no user functions should produce minimal or empty output — not 5000 lines of stdlib internals.
## Reported by
User report: "The asm output doesn't seem as filtered as I remember it" — adding a function cleans it up.
Contributor guide
Research direction
Start in lib/parsers/asm-parser.ts around the libraryCode check at line ~298, then reproduce the issue with the broken and working Compiler Explorer links using identical filter settings. Trace the no-user-function path and verify that enabling libraryCode for an include-only source no longer emits the full standard-library assembly while the user-function case remains filtered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, typescript
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100