Skip to content

fix: resolve all compiler warnings in extension source#246

Merged
tjgreen42 merged 5 commits intomainfrom
fix/build-warnings
Mar 2, 2026
Merged

fix: resolve all compiler warnings in extension source#246
tjgreen42 merged 5 commits intomainfrom
fix/build-warnings

Conversation

@tjgreen42
Copy link
Copy Markdown
Collaborator

Summary

  • Remove unused variables in build.c (metabuf, metapage, metap, snapshot)
  • Add missing prototype for tp_extract_terms_from_tsvector to am.h (removes -Wmissing-prototypes and the extern in build_parallel.c)
  • Silence unused parameter warnings with (void) casts in dshash callbacks (posting.c, stringtable.c) and parallel build estimation (build_parallel.c)
  • Remove excess initializer elements in relopt_parse_elt (handler.c) — PG17 struct has 3 fields, not 4
  • Fix shadow variable in score.c (inner int i shadowed function-scope i)
  • Initialize min_page/min_offset to suppress -Wmaybe-uninitialized (merge.c)
  • Suppress -Wpacked-not-aligned for intentionally packed on-disk structs (segment.h) with GCC-only diagnostic pragmas
  • Fix -Waddress-of-packed-member in scan.c by using local ItemPointerData + memcpy instead of taking address of packed member directly
  • Suppress -Wclobbered false positives from GCC inlining functions into PG_TRY callers (query.c, state.c)

After this change, make -j produces zero source-level warnings (only the expected pgxs Makefile recipe override notice).

Test plan

  • make format-check passes
  • make clean && make -j$(nproc) produces no source warnings
  • All 48 SQL regression tests pass

@tjgreen42 tjgreen42 closed this Mar 2, 2026
@tjgreen42 tjgreen42 reopened this Mar 2, 2026
- Remove unused variables (build.c: metabuf/metapage/metap/snapshot)
- Add missing prototype for tp_extract_terms_from_tsvector to am.h
- Silence unused parameter warnings with (void) casts in dshash
  callbacks (posting.c, stringtable.c) and parallel build (build_parallel.c)
- Remove excess initializer elements in relopt_parse_elt (handler.c)
- Fix shadow variable in score.c (remove inner redeclaration of i)
- Initialize min_page/min_offset to suppress maybe-uninitialized (merge.c)
- Suppress -Wpacked-not-aligned for intentionally packed on-disk structs
- Fix address-of-packed-member in scan.c via local + memcpy
- Suppress -Wclobbered false positives from PG_TRY inlining (query.c, state.c)
- Restore snapshot variable needed for PG18's UnregisterSnapshot,
  suppress set-but-not-used with (void) cast on PG17
- Use designated initializers for relopt_parse_elt to handle PG17
  (3 fields) vs PG18 (4 fields with isset_offset) without warnings
CI was passing CFLAGS="-Werror" to make, but pgxs overrides CFLAGS
from pg_config, so -Werror was silently dropped. Warnings were never
treated as errors despite the CI step suggesting they were.

Switch to PG_CFLAGS="-Werror -Wno-error=unused-parameter" which pgxs
correctly appends to the compiler flags. The unused-parameter exclusion
is needed for warnings from Postgres headers (ilist.h, bufmgr.h) that
we cannot fix.

Also initialize dict_buf in segment.c to fix a maybe-uninitialized
warning that -Werror now catches.
Move -Wno-clobbered and -Wno-packed-not-aligned to PG_CPPFLAGS in the
Makefile instead of wrapping each site with 4-line #if/#pragma blocks.
Add -Wno-unknown-warning-option so clang (used for .bc bitcode) silently
ignores the GCC-specific flags.

Removes 28 lines of pragma boilerplate from 3 source files.
@tjgreen42 tjgreen42 force-pushed the fix/build-warnings branch from c17304a to 04ed729 Compare March 2, 2026 23:07
- CID 644692: Add null check after merge_sink_init_pages in
  tp_merge_level_segments before dereferencing sink.writer.pages
- CID 644691: Same null check pattern in tp_build_parallel
  (original function removed but same pattern existed)
- CID 644690: Zero-initialize iter.block_access in
  tp_segment_posting_iterator_init to avoid uninitialized
  buffer field when calling _free
- CID 644689: Always allocate docmap output arrays in
  build_merged_docmap (palloc(0) is valid in PG), removing
  conditional NULL assignment
- CID 644341: Remove dead code in tp_score_documents by
  making multi-term BMW path unconditional (query_term_count
  >= 2 is guaranteed by the early return above)
@tjgreen42 tjgreen42 merged commit 4f2d271 into main Mar 2, 2026
15 checks passed
@tjgreen42 tjgreen42 deleted the fix/build-warnings branch March 2, 2026 23:53
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.

1 participant