Repository navigation
fix(c,cpp): a member whose type a macro renames links what the macro names - #3173
Merged
Merged
Conversation
…names redis-cli.c and redis-benchmark.c include hiredis's sdscompat.h, which has `#define sds hisds`. Their 24 `sds` members were linked to src/sds.h's namesake typedef, a false edge new in PR 3144: the parser sees `sds`, and a macro with no parameters has no node. matchCppDeclaredType now asks what the name is renamed to where it is written. Headers are read once per resolver, by a search for `define`, into an index by macro name, so a name nothing renames costs one lookup. A rename counts as the preprocessor applies it: the translation unit from the asking file must have certainly defined the macro by that line (isCppMacroDefinedAt, the existing include walk following one object-like macro). So not above the `#include` or the `#define`, not under a flag no file sets, and not when two arms disagree. A new name that is no project type leaves the name as written. The scan stops at 16 MB of headers per resolver: betaflight has 109 MB, nearly all vendor register maps. The same rule corrects two more that nobody had read: - redis's core sets REDISMODULE_CORE, so `RedisModuleString` is `robj` in module.c, 19 edges. A module that includes the same header keeps the typedef, as does the header read on its own. - jq's `#define YYLTYPE location`: bison's struct is compiled out, 3 edges. Validation against main 4499d00: - Tests: 5 of 7 fail on main, all pass. 9 mutations each fail a test. - redis 43 edges moved, 24 to `hisds` and 19 to `robj`, each checked against the includes and the flag; nothing lost. jq 3 moved, right. - rocksdb, leveldb, glfw, betaflight, gin, flask: nothing from this commit. - No extraction change. Cost: a resolver's scan is 26 ms on redis and 81 ms on rocksdb, once per worker; 49 ms of a redis index's profile in all. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
colbymchenry
force-pushed
the
claude/fix-c-macro-renames
branch
from
November 1, 2026 05:10
6c87525 to
c4683d1
Compare
bompus
added a commit
to bompus/codegraph
that referenced
this pull request
Nov 2, 2026
…names (colbymchenry#3173) Ported from upstream cb1e13d
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.
Summary
A struct member whose type a macro renames now links what the macro names. redis-cli.c's
sdsmembers are hiredis'shisds, not src/sds.h's namesake typedef.Second of a stack of four, on top of #3172.
Root cause
redis-cli.c and redis-benchmark.c include hiredis's sdscompat.h, which has
#define sds hisds. The parser seessds, and a macro with no parameters has no node, so #3144 linked 24 members to the onlysdsthe project declares.The fix
matchCppDeclaredTypeasks what the name is renamed to where it is written (src/resolution/c-macro-renames.ts).define, into an index by macro name. A name nothing renames costs one lookup. The scan stops at 16 MB of headers: betaflight has 109 MB, nearly all vendor register maps.isCppMacroDefinedAtis the existing include walk, following one object-like macro. So not above the#includeor the#define, and not under a flag no file sets.The same rule corrected two more that nobody had read:
REDISMODULE_CORE, soRedisModuleStringisrobjin module.c, 19 edges. A module that includes the same header keeps the typedef.#define YYLTYPE location: bison's struct is compiled out, 3 edges.Validation
Windows 11, main 4499d00.
Tests. 5 of the 7 new tests fail on main and all pass. 9 mutations each fail a test.
A/B against main.
hisds, 19 torobj, each checked against the includes and the flag. Nothing lostlocation, rightNo extraction change.
Cost. A resolver's scan is 26 ms on redis and 81 ms on rocksdb, once per worker; 49 ms of a redis index's profile in all. Whole-index CPU in the same run: redis +0.6%. rocksdb, 3 interleaved rounds on a busy machine: 132.3 to 129.7 s, level.
Left out. 551
callsedges in redis's CLI files have the same problem on both arms:#define sdslen hi_sdslenmeanssdslen(x)is hiredis's, and it links to src/sds.c's. The index added here would serve for that, but it is a change to call resolution and not on my list.Suite. 857 files passed and 6 skipped, 10,651 tests passed, 2 expected fail, 87 skipped, 4 workers, with the kernel, on the stack one clean rebase back (719ea417 on main 3bd9949). After the rebase onto 087de4c, whose hunks are apart from these: 138 files and 2,224 tests of the C, C++, Objective-C, Python and extraction suites pass on the tip.
🤖 Generated with Claude Code