Directive filter ineffective when source has no user-defined functions
(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 <iostream>, no user functions: https://godbolt.org/z/osbnnM786
→ Produces ~5000 lines of asm from the standard library
Working — same code plus any user function: https://godbolt.org/z/dzrxKc4ba → 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):
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 <iostream> 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.
Source: compiler-explorer/compiler-explorer