mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-11-30 10:44:33 -06:00
Fixes #8964. Directive filtering runs over the whole listing, including the region between `#APP` and `#NO_APP`. That region is the user's own inline asm, so filtering it changes what the block says. For the case in the issue: ```cpp int square(int num) { asm(".rept 5\nnop\n.endr"); return num * num; } ``` `.rept 5` and `.endr` go away and a single `nop` is left, which reads as one instruction where the source asks for five. The parser already tracks the region: `updateParsingState` calls `enterCustomAssembly` on `#APP` and `exitCustomAssembly` on `#NO_APP`, and `isInCustomAssembly()` was being used only to fix label indentation. `shouldSkipDirective` now consults it too. ### What still gets dropped Not everything in the block is the user's. GCC interleaves its own line markers, as @Alcaro pointed out on the issue: ``` #APP # 3 "/app/example.cpp" 1 .rept 5 nop .endr # 0 "" 2 .loc 1 4 5 view .LVU3 # /app/example.cpp:4: return num * num; .loc 1 4 18 is_stmt 0 view .LVU4 #NO_APP ``` So the rule is narrower than "skip filtering inside the block": inside it, a directive is dropped only when it is a source-location marker. That set is not a new list, it is the one `SourceLineHandler` already consumes to build the source mapping (`.loc`, `.d2line`, `.cv_loc`, `.dbg line`, `.stabn`), exposed as `isSourceLocationDirective`. Anything the handler does not claim is text the compiler was asked to assemble, and it stays. The `#` lines above are comments and are unaffected, they still go with the comment filter. ### The changed snapshots `nvcc-x86-host-example` gains three lines: `.section .nv_fatbin, "a"`, `.align 8` and `.text`, all inside its `#APP` block. The hundreds of `.quad` lines in that block were already surviving the directive filter, because `fatbinData:` sets `prevLabel` and `dataDefn` lines under a used label are kept, so this is three lines added to output that was already showing the blob, not the blob becoming visible. `NvccCompiler.removeNvccFatbinaryBlob` is what actually hides it, and it is unaffected. No other case in `filters-cases` moves. `bug-577_gcc` and `bug-577_clang` have `#APP` blocks with no directives in them. ### Tests Three in `test/asm-parser-tests.ts`: the directives survive, the `.loc` markers inside the same block still do not, and filtering resumes after `#NO_APP`. The first and third fail on `main`. I ran the full suite in `node:22-bookworm`, since `filter-tests.ts` returns early on Windows: 2631 passed.