Skip to content

Do not treat -c as consuming the next compile argument - #60

Open
mateusz-olczyk wants to merge 1 commit into
EngFlow:mainfrom
mateusz-olczyk:fix/stray-c-compile-flag
Open

mateusz-olczyk wants to merge 1 commit into
EngFlow:mainfrom
mateusz-olczyk:fix/stray-c-compile-flag

Conversation

@mateusz-olczyk

Copy link
Copy Markdown

-c takes no argument in gcc/clang; the extractors merely place the source right after it. Two places assumed otherwise:

  • reconstruct._source_from_compile_args took the first -c <x> as the translation unit's source.
  • canonicalize listed -c in _DRIVER_PAIR_FLAGS and dropped it together with the following token.

Real projects can carry a redundant -c inside their flags (e.g. CMAKE_C_FLAGS="... -c -std=c11 ..."); gcc ignores the repetition. With such flags every TU of a CMake target was keyed by -std=c11, so all of them collapsed into a single bogus TU, and -std=c11 itself was hidden from the flag comparison on both sides. The diff then compared a single TU per target instead of every source, so missing sources and per-file flag gaps went unreported.

Now -c is dropped on its own, and the next token is only treated as the source (and dropped) when it is not a flag. Source detection skips a -c followed by a flag; the existing extension scan remains the fallback.

Tests cover canonicalization of a stray -c, distinct TUs for two sources under such flags, convergence when both sides set the flag after the stray -c, and an error when Bazel is missing it. All three fail without the fix. docs/REFERENCE-cmake.md documents the behavior.

`-c` takes no argument in gcc/clang; the extractors merely place the
source right after it. Two places assumed otherwise:

* reconstruct._source_from_compile_args took the first `-c <x>` as the
  translation unit's source.
* canonicalize listed `-c` in _DRIVER_PAIR_FLAGS and dropped it together
  with the following token.

Real projects can carry a redundant `-c` inside their flags (e.g.
`CMAKE_C_FLAGS="... -c -std=c11 ..."`); gcc ignores the repetition. With
such flags every TU of a CMake target was keyed by `-std=c11`, so all of
them collapsed into a single bogus TU, and `-std=c11` itself was hidden
from the flag comparison on both sides. The diff then compared a single
TU per target instead of every source, so missing sources and per-file
flag gaps went unreported.

Now `-c` is dropped on its own, and the next token is only treated as
the source (and dropped) when it is not a flag. Source detection skips
a `-c` followed by a flag; the existing extension scan remains the
fallback.

Tests cover canonicalization of a stray `-c`, distinct TUs for two
sources under such flags, convergence when both sides set the flag
after the stray `-c`, and an error when Bazel is missing it. All three
fail without the fix. docs/REFERENCE-cmake.md documents the behavior.
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