Skip to content

Fix C++ bundling of GCC pragmas and assertion headers - #442

Open
adamant-pwn wants to merge 3 commits into
online-judge-tools:masterfrom
adamant-pwn:fix/pragma-gcc-target-bundler
Open

Fix C++ bundling of GCC pragmas and assertion headers#442
adamant-pwn wants to merge 3 commits into
online-judge-tools:masterfrom
adamant-pwn:fix/pragma-gcc-target-bundler

Conversation

@adamant-pwn

@adamant-pwn adamant-pwn commented Dec 8, 2025

Copy link
Copy Markdown

GCC preprocessing can inject macro definitions for #pragma GCC target() and #pragma GCC optimize(), breaking the bundler's source-line count assertion. Separately, the bundler drops <cassert> after <bits/stdc++.h> and deduplicates repeated assertion headers. Current libstdc++ excludes <cassert> from that umbrella header, so bundled programs can fail to compile; deduplication also breaks changes to assert when NDEBUG changes.

Temporarily mark the two GCC pragmas during preprocessing and restore them afterward. Always preserve <cassert> and <assert.h>, including repeated includes and includes following the supported GNU umbrella headers.

Validation: all 9 tests in python -m unittest tests.test_bundle pass. The new compile-and-run regression covers both assertion headers with no umbrella header and with each of bits/stdc++.h, bits/extc++.h, and bits/stdtr1c++.h, toggling NDEBUG in each case. All eight subcases fail before the assertion-header fix and pass afterward. Existing pragma regression coverage is retained.

Fixes #438

When GCC preprocesses with -dD flag and encounters #pragma GCC target(),
it emits extra macro definitions for compiler features (__AVX2__, __SSE4_1__, etc).
This causes a line count mismatch in the bundler's assertion that line counts
must be equal between raw source and uncommented code.

Solution: Temporarily comment out #pragma GCC target() before preprocessing,
then uncomment in the output. Uses OJ_BUNDLE_PRAGMA marker to distinguish
from user-written comments.

Fixes online-judge-tools#438
@adamant-pwn adamant-pwn changed the title Fix: Handle #pragma GCC target() in C++ bundler Fix: Handle #pragma GCC target() and optimize() in C++ bundler Sep 6, 2026
@adamant-pwn adamant-pwn changed the title Fix: Handle #pragma GCC target() and optimize() in C++ bundler Fix C++ bundling of GCC pragmas and assertion headers Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

oj-bundle no longer works with avx2 GCC pragma

1 participant