Skip to content

fix: declare external scanner create functions with (void) - #311

Merged
calebdw merged 1 commit into
tree-sitter:masterfrom
LucasGutknecht:fix/scanner-void-prototypes
Nov 19, 2026
Merged

calebdw merged 1 commit into
tree-sitter:masterfrom
LucasGutknecht:fix/scanner-void-prototypes

Conversation

@LucasGutknecht

Copy link
Copy Markdown

Problem

tree_sitter_php_external_scanner_create() and tree_sitter_php_only_external_scanner_create() are defined with an empty parameter list. Before C23 that is a non-prototype declaration, while the runtime calls them through a void *(*)(void) pointer.

This is valid C17, but Clang's -fsanitize=function (enabled by -fsanitize=undefined since Clang 17) compares the exact types and reports:

runtime error: call to function tree_sitter_php_external_scanner_create through pointer to incorrect function type 'void *(*)(void)'

Any project that embeds the grammar and runs its tests under UBSan with Clang hits this (seen with Clang 21 on Ubuntu and Clang 23 on macOS).

Change

Use (void) in both wrappers and in external_scanner_create in common/scanner.h. No behavior change; this matches the external scanner signatures in the tree-sitter docs and silences -Wstrict-prototypes.

Testing

  • Built a C17 project that embeds the grammar with Clang 23 and -fsanitize=address,undefined: the runtime error is gone and its parsing tests pass.
  • clang -std=c17 -Wstrict-prototypes on php/src/scanner.c: 2 warnings before, 0 after.

The external scanner create functions were defined with an empty
parameter list, which in C before C23 is a non-prototype declaration.
The tree-sitter runtime calls them through a void *(*)(void) pointer.

The call is valid C17, but Clang's -fsanitize=function (part of
-fsanitize=undefined since Clang 17) compares the exact function types
and reports:

  runtime error: call to function tree_sitter_php_external_scanner_create
  through pointer to incorrect function type 'void *(*)(void)'

Using (void) makes the definitions real prototypes, matching the pointer
type and the tree-sitter documentation for external scanners. It also
silences -Wstrict-prototypes.
@calebdw
calebdw merged commit c1e1349 into tree-sitter:master Nov 19, 2026
2 of 5 checks passed
@calebdw

calebdw commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

thanks!

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.

2 participants