Git development
 help / color / mirror / Atom feed
From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
Subject: Re: [PATCH v2 4/4] Makefile: precompile "git-compat-util.h"
Date: Sat, 3 Oct 2026 21:00:21 +0200	[thread overview]
Message-ID: <asFQxeh+IUGrlu6W@szeder.dev> (raw)
In-Reply-To: <20260915060952.569535-5-szeder.dev@gmail.com>

On Tue, Sep 15, 2026 at 08:09:52AM +0200, SZEDER Gábor wrote:
>     - The precompiled header should not change what actually gets
>       compiled.  Therefore, use the precompiled header only when
>       compiling source files that start with including
>       "git-compat-util.h" (directly or indirectly, e.g. via
>       "builtin.h"), or its inclusion is only preceeded by #define
>       directives that don't influence "git-compat-util.h" between its
>       include guards [2] (currently DISABLE_SIGN_COMPARE_WARNINGS,
>       USE_THE_REPOSITORY_VARIABLE or GIT_TEST_PROGRESS_ONLY). [3]

Well, it turns out the precompiled header does change what gets
compiled, and it causes a visible behavior difference, though I think
it's really minor.

The crux of the issue is that without the precompiled header the
compiler processes "git-compat-util.h", but with it, for some reason,
it processes "./git-compat-util.h".

This is visible when expanding __FILE__ in "git-compat-util.h", e.g.
in the assert macro in regexec_buf().  When the assertion is
triggered, e.g. with this diff:

diff --git a/common-main.c b/common-main.c
index 6b7ab077b0..dd2a90c849 100644
--- a/common-main.c
+++ b/common-main.c
@@ -5,6 +5,9 @@ int main(int argc, const char **argv)
 {
 	int result;
 
+	/* Intentionally bogus regexec_buf() call to trigger its assert() */
+	regexec_buf(NULL, NULL, 0, 0, NULL, 0);
+
 	init_git(argv);
 	result = cmd_main(argc, argv);
 
Then without the precompiled header we get:

  $ ./git
  git: git-compat-util.h:1002: regexec_buf: Assertion `nmatch > 0 && pmatch' failed.
  Aborted (core dumped)

But with the precompiled header:

  $ ./git
  git: ./git-compat-util.h:1002: regexec_buf: Assertion `nmatch > 0 && pmatch' failed.
  Aborted (core dumped)

Similar could happen when the ALLOC_GROW_BY() macro is invoked with
bogus parameters to trigger a BUG().

(Sidenote: While this assert does prevent us from invoking regexec()
with nonsense, the source file name and line number in the resulting
error message are not as useful as they could be, it would be better
to show the caller's filename and line number.)

Since in "git-compat-util.h" __FILE__ is only expanded in error
messages that should basically never happen (BUG() and assert()), I
think this is acceptable.


BTW, this is also visible in compiler error messages:

diff --git a/git-compat-util.h b/git-compat-util.h
index a0f901ce79..00c1f26911 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1,6 +1,8 @@
 #ifndef GIT_COMPAT_UTIL_H
 #define GIT_COMPAT_UTIL_H
 
+trigger_compiler_error
+
 #if __STDC_VERSION__ - 0 < 199901L
 /*
  * Git is in a testing period for mandatory C99 support in the compiler.  If

Without precompiled header:

      CC daemon.o
  In file included from daemon.c:3:
  git-compat-util.h:4:23: error: expected ‘;’ before ‘typedef’
      4 | trigger_compiler_error
        |                       ^
        |                       ;

With precompiled header:

      CC tools/precompiled.h.gch
  In file included from tools/precompiled.h:1:
  ./git-compat-util.h:4:23: error: expected ‘;’ before ‘typedef’
      4 | trigger_compiler_error
        |                       ^
        |                       ;


      parent reply	other threads:[~2026-10-03 19:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 19:50 [PATCH 0/4] make: precompile "git-compat-util.h" SZEDER Gábor
2026-09-09 19:50 ` [PATCH 1/4] Makefile: remove XDIFF_OBJS initialization SZEDER Gábor
2026-09-09 19:50 ` [PATCH 2/4] cmake: remove any "$(*_OBJS)" variables when parsing Makefile for sources SZEDER Gábor
2026-09-09 19:50 ` [PATCH 3/4] Makefile: reintroduce REFTABLE_OBJS SZEDER Gábor
2026-09-09 21:07   ` Junio C Hamano
2026-09-09 19:50 ` [PATCH 4/4] Makefile: precompile "git-compat-util.h" SZEDER Gábor
2026-09-09 19:57   ` SZEDER Gábor
2026-09-15  6:09 ` [PATCH v2 0/4] make: " SZEDER Gábor
2026-09-15  6:09   ` [PATCH v2 1/4] Makefile: remove XDIFF_OBJS initialization SZEDER Gábor
2026-09-15  6:09   ` [PATCH v2 2/4] cmake: remove any "$(*_OBJS)" variables when parsing Makefile for sources SZEDER Gábor
2026-09-15  6:09   ` [PATCH v2 3/4] Makefile: reintroduce REFTABLE_OBJS SZEDER Gábor
2026-09-15  6:09   ` [PATCH v2 4/4] Makefile: precompile "git-compat-util.h" SZEDER Gábor
2026-09-24 23:52     ` Jeff King
2026-09-25  9:25       ` SZEDER Gábor
2026-10-03 19:00     ` SZEDER Gábor [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=asFQxeh+IUGrlu6W@szeder.dev \
    --to=szeder.dev@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox