Fix C++ bundling of GCC pragmas and assertion headers - #442
Open
adamant-pwn wants to merge 3 commits into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 toassertwhenNDEBUGchanges.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_bundlepass. The new compile-and-run regression covers both assertion headers with no umbrella header and with each ofbits/stdc++.h,bits/extc++.h, andbits/stdtr1c++.h, togglingNDEBUGin each case. All eight subcases fail before the assertion-header fix and pass afterward. Existing pragma regression coverage is retained.Fixes #438