| From: | Grant Jurgensen <grant(at)kestrel(dot)edu> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Incompatible declarations of pg_reg_getcolor() in regcomp.c and regexec.c |
| Date: | 2026-11-06 20:04:52 |
| Message-ID: | 13a01caf-c4de-454e-aefa-92260aac7e64@kestrel.edu |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi,
This is a source-level problem with no user-visible effect, so there is
no SQL to reproduce it, but clang can show it (see below).
The regex compiler and executor declare the external function
pg_reg_getcolor() with incompatible types, which is undefined behavior
under C17 6.2.7p2:
- regguts.h:563 declares
extern color pg_reg_getcolor(struct colormap *cm, chr c);
and both regcomp.c and regexec.c include regguts.h. regcomp.c defines
the function (via regc_color.c), and regexec.c calls it through
GETCOLOR() in rege_dfa.c.
- struct colormap (regguts.h:236) has a member "struct vars *v"
(regguts.h:240).
- regcomp.c:281 and regexec.c:106 each define their own, unrelated
struct vars.
So struct colormap, and with it the type of pg_reg_getcolor(), differs
between the two translation units. Compilers accept this, but tools that
check declarations across translation units may reject it. (I ran into
this issue while processing PostgreSQL with a C front end developed in
the ACL2 theorem prover.)
It dates from commit c54159d44ce (PostgreSQL 10), which made
pg_reg_getcolor() external, and is still present on master (72b9498).
To reproduce it with clang, run these from src/backend/regex in a
configured tree:
clang -I../../../src/include -emit-ast regcomp.c regexec.c
clang -cc1 -ast-merge regcomp.ast -ast-merge regexec.ast
-fsyntax-only -x c /dev/null
Among other things, this reports:
regguts.h:563:14: warning: external function 'pg_reg_getcolor'
declared with incompatible types in different translation units [-Wodr]
The other -Wodr warnings, about struct types that differ between
translation units, are not problems in themselves in C.
Suggested fix (attached): rename the executor's struct to struct
exec_vars in regexec.c and rege_dfa.c. The struct vars pointer in struct
colormap exists only for error reporting during compilation, and the
executor never uses it, so struct vars simply stays incomplete in
regexec.c. It is a pure rename. On master with clang, the regex object
files are byte-identical before and after, make check and test_regex
pass, and the AST merge above reports nothing.
Thanks,
Grant Jurgensen
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Rename-regexec.c-s-struct-vars-to-struct-exec_var.patch | text/x-patch | 13.1 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-11-06 20:32:20 | Re: Incompatible declarations of pg_reg_getcolor() in regcomp.c and regexec.c |
| Previous Message | Magnus Hagander | 2026-11-06 15:47:11 | Re: Errors in pgdg repo packages |