6.3 GNU conventions: the style checker, and the ChangeLog in the commit message

Source references in this chapter are to GCC 15.2.0 (releases/gcc-15.2.0).

You fix one function in gcc/tree-ssa-alias.cc. You add an entry to gcc/ChangeLog, as older guides tell you to, and you run git gcc-verify on the commit. It reports FAILED, and the error says: "ChangeLog, DATESTAMP, BASE-VER and DEV-PHASE updates should be done separately from normal commits" (git_commit.py:370-373).

Your entry is correct. It is in the wrong place. Since May 2020, a GCC ChangeLog entry is part of the commit message, and a parser in contrib/gcc-changelog/ decides whether it is well formed. The ChangeLog files are output: a daily job writes them from the commit history. The layout has a checker too, contrib/check_GNU_style.py, and you can run both before anyone reviews your commit.

This chapter assumes Chapter 2.1 for the directory map, because every ChangeLog entry belongs to a directory. It also assumes Chapter 6.1, because a change with a new test writes a second entry, for gcc/testsuite/. Chapter 6.4 takes the finished commit to the mailing list.

GNU rules, GCC rules, and the tree: codingconventions.html and .dir-locals.el

Two documents state the conventions, and neither is in the tree. The GNU Coding Standards apply to every GNU package. Their Formatting and Comments nodes set the C layout, and Change Logs sets the entry format. The GCC Coding Conventions page adds rules "beyond those in the GNU Coding Standards". The contribution page says that "All contributions must conform to the GNU Coding Standards". The GCC manual's Contributing node does not restate either. Its text is a pointer to https://gcc.gnu.org/contribute.html (gcc/doc/contribute.texi:13-19). The web pages change without a release. This chapter quotes them as they read on 2026-10-26.

Neither page marks where GNU ends and GCC begins. The table sorts the rules by where they are written, and adds the files in the tree that encode each one.

RuleGNU Coding StandardsGCC Coding ConventionsIn the tree
Function name, and its opening brace, in column oneFormattingno rulecontrib/clang-format
A space before (Formattingno rulecheck_GNU_style.py, contrib/clang-format
Two columns per indent level, block braces on their own linesFormatting, by exampleC++ cases onlycontrib/vimrc, check_GNU_style.py
A tab for every eight columns of indentno ruleno rule.dir-locals.el, contrib/vimrc, .gitattributes, check_GNU_style.py, contrib/clang-format
Break a long expression before an operatorFormattingno rulecheck_GNU_style.py, contrib/clang-format
Line length79 characters or lessat most 80 columnschecker: 80, editors: 79
Two spaces after a full stopCommentsfor Texinfo onlycheck_GNU_style.py
* file (function): change.Change LogsChangeLogscontrib/gcc-changelog/
Entry in the commit message, files generatedallowedrequiredcontrib/gcc-changelog/

Two rows stand out. The tab rule is in no document. Only the tree states it. And the documents disagree on line length by one column. The checker follows GCC's 80 (check_GNU_style_lib.py:78-91). The editor settings follow GNU's 79: fill-column is 79 in .dir-locals.el, and textwidth is 79 in contrib/vimrc.

GNU layout in one function: access_check in gcc.cc

One short function in the driver shows most of the GNU layout:

/* Check whether NAME can be accessed in MODE.  This is like access,
   except that it never considers directories to be executable.  */

static int
access_check (const char *name, int mode)
{
  if (mode == X_OK)
    {
      struct stat st;

      if (stat (name, &st) < 0
	  || S_ISDIR (st.st_mode))
	return -1;
    }

  return access (name, mode);
}

Listing 6.3-1: a function in GNU layout (gcc/gcc.cc:3007-3023).

Read it from the top:

  • The comment is two complete sentences. There are two spaces after the first full stop, and two before */. The second line starts under the text, with no *. The GNU Comments node asks for the two spaces "so that the Emacs sentence commands will work".
  • NAME and MODE are in capitals. The same node writes a parameter in upper case "when you are speaking about the value rather than the variable itself".
  • The return type has its own line, so the name starts in column one. The GNU Formatting node says that this "helps people to search for function definitions". grep -n '^access_check' gcc/gcc.cc finds the definition and none of the calls.
  • Every call has a space before its (: stat (name, &st).
  • The braces of the if body are on their own lines, two columns in from the if. The body is two columns further in.
  • The long condition breaks before ||, not after it.

The listing cannot show which white space is a tab. Two of its lines start with one:

$ sed -n '3017,3019p' gcc/gcc.cc | cat -A
      if (stat (name, &st) < 0$
^I  || S_ISDIR (st.st_mode))$
^Ireturn -1;$

Indentation goes in steps of two columns, and each full eight columns of it is one tab. return -1; is at column 8, so it is one tab. The || line is at column 10, so it is a tab and two spaces.

One more GNU rule is invisible. The Formatting node asks for form feeds "to divide the program into pages at logical places". gcc/gcc.cc has 30 lines that hold only a form feed (grep -c $'^\f$' gcc/gcc.cc). Python's str.splitlines treats a form feed as a line break, so it counts different line numbers. This book reads them with sed -n and grep -n.

The tab rule: contrib/vimrc, .dir-locals.el and .gitattributes

The tab rule is in the editor settings that the tree ships. Emacs reads .dir-locals.el, which selects the GNU style for C and C++ and sets indent-tabs-mode to t (.dir-locals.el:21-27). Vim users source contrib/vimrc:

  if l:ext != "py"
    setlocal tabstop=8
    setlocal softtabstop=2
    setlocal shiftwidth=2
    setlocal noexpandtab
  endif

Listing 6.3-2: the indent settings (contrib/vimrc:36-41).

shiftwidth=2 is the indent step. tabstop=8 is the width of a tab. noexpandtab keeps the tabs. The settings skip Python files.

.gitattributes turns the rule into a git warning:

*.[cCh] whitespace=indent-with-non-tab,space-before-tab,trailing-space
*.cc whitespace=indent-with-non-tab,space-before-tab,trailing-space
ChangeLog whitespace=indent-with-non-tab,space-before-tab,trailing-space

Listing 6.3-3: whitespace classes for C, C++ and ChangeLog (.gitattributes:4-6).

indent-with-non-tab "treats a line that is indented with space characters instead of the equivalent tabs as an error" (git-config). git diff --check reports these errors. With git 2.43, in a scratch repository that has the same attribute line, a new line indented with eight spaces gives:

$ git diff --check
a.c:6: indent with spaces.
+        y = 1;

The command exits with status 2. A line indented with six spaces passes, because six spaces are less than one tab. git diff --check needs no contrib/ script, so run it before every commit.

contrib/clang-format encodes the GNU brace placement, SpaceBeforeParens: Always and UseTab: Always (:27-53, :215-217). Its header asks for clang-format 7.0.1, and applies it through clang-format-diff to the lines a patch touches (contrib/clang-format:16-25).

The tree does not obey its own rules everywhere. In the same file as Listing 6.3-1, remove_outfile_spec_function has a comment with * at the start of each line. It also has a statement indented with eight spaces (gcc/gcc.cc:10491-10510). The GCC Coding Conventions page expects this: "Some existing code may not follow these conventions, but they must be used for new code." It also asks you to send changes that only fix the conventions apart from any other change. So the rules apply to the lines you add. A reformat of the lines around them is a separate patch.

Running contrib/check_GNU_style.py on a diff

This chapter was written without a GCC checkout, so the contrib/ commands below were not run. Where the chapter says what a script prints, it cites the line that prints it.

$ pip3 install unidiff termcolor
$ git diff | contrib/check_GNU_style.py -
$ git diff > my.patch
$ contrib/check_GNU_style.py -f quickfix my.patch

The script reads a patch file, or standard input when the name is - (contrib/check_GNU_style.py:29-45). Without unidiff and termcolor it stops with status 3 and tells you what to install (check_GNU_style_lib.py:25-55). Two filters decide what it checks:

    for pfile in patch.added_files + patch.modified_files:
        t = pfile.target_file.lstrip('b/')
        # Skip testsuite files
        if 'testsuite' in t or t.endswith('.py'):
            continue

        for hunk in pfile:
            delta = 0
            for line in hunk:
                if line.is_added and line.target_line_no != None:
                    for check in checks:
                        line_chomp = line.value.replace('\n', '')
                        e = check.check(t, line.target_line_no, line_chomp)
                        if e != None:
                            errors.append(e)

Listing 6.3-4: the lines that are checked (contrib/check_GNU_style_lib.py:281-295).

The script skips every path that contains testsuite, and every Python file. In the other files, it checks only the added lines. The checker judges the lines you add, and it never reads a test. Each check that matches adds an error:

MessageWhat it matchesSource
lines should not exceed 80 charactersmore than 80 columns, a tab counted as 8:78-91
blocks of 8 spaces should be replaced with tabseight spaces anywhere in the line:93-102
a space should not precede a taba space, then a tab:104-114
trailing whitespacewhite space at the end:116-127
dot, space, space, new sentencea word, a full stop, one space or three or more, a word:129-139
dot, space, space, end of commentthe wrong spacing before */, or no full stop:141-162
there should be exactly one space between function name and parenthesisf( or f (:164-178
there should be no space before a left square bracketa [i], except in .md files:180-193
there should be no space before closing parenthesisf (a ):195-205
braces should be on a separate line) { or else {:207-218
trailing operatoran indented line that ends in an operator:220-230

The default output groups the errors by message, and the script exits with 1 if there is any error. -f quickfix writes errors.err for Vim instead (:297-319).

The parenthesis check skips every line that contains #define. C requires that exception. The cpp manual documents it under Function-like Macros: a space between the macro name and the parenthesis "does not define a function-like macro, it defines an object-like macro whose expansion happens to begin with a pair of parentheses". So a function-like macro is defined as #define MAX(a, b), with no space.

The checks are regular expressions, and some give false positives. e.g. the matches the sentence check. The brace check warns: "This will give false positives for C99 compound literals." Use the output as a list of places to look. The older shell version, contrib/check_GNU_style.sh, says the same in its usage text: the checks "are not always accurate, and complete" (check_GNU_style.sh:24-38). After you run contrib/gcc-git-customization.sh, git gcc-style HEAD sends a commit through the Python checker (gcc-git-customization.sh:33-37).

The ChangeLog entry: * file (function): change.

The entry format is GNU's, from the Style of Change Logs node. The first entry after the release line in gcc/ChangeLog shows every part:

2025-08-07  Uros Bizjak  <ubizjak@gmail.com>

	Backported from master:
	2025-08-06  Uros Bizjak  <ubizjak@gmail.com>

	PR target/96226
	* config/i386/predicates.md (and_operator): New operator.
	* config/i386/i386.md (splitter after *<rotate_insn><mode>3_mask):
	Use and_operator to match AND RTX and use its mode
	in the split pattern.

Listing 6.3-5: a generated entry (gcc/ChangeLog:5-14).

  • The header line is a date, two spaces, a name, two spaces and an address in angle brackets (git_commit.py:789-798, git_repository.py:63).
  • Every other line starts with a tab.
  • PR target/96226 names the Bugzilla component and bug number.
  • Each change is * file (entity): description. The file path is relative to the directory that owns this ChangeLog, here gcc/. The entity in parentheses is a function, a macro or a type. In a machine description it names a pattern, and a pattern with no name is given by its position: splitter after *<rotate_insn><mode>3_mask. The description is a sentence, and long lines continue after a tab.
  • The Backported from master: block is how the job records a cherry-pick. It writes the original author and date under the backport's own header (git_commit.py:831-840). The text is fixed, whatever branch the commit came from. Chapter 6.4 says when a backport is allowed.

Two content rules are GNU-wide. Name each entity in full, so that a search for the name finds the entry. And keep the reason out of the entry. The Change Log Concepts node says: "The best place to explain how parts of the new code work with other code is in comments in the code, not in the change log". The entry says what changed. The free text above it in the commit message says why.

mklog.py uses set phrases: New file., New test., Removed., Regenerate., and Move to... with ...here. for a rename (mklog.py:267-285). The contribution page asks you to note a regenerated file, as in * configure: Regenerate.

One ChangeLog per directory: default_changelog_locations

GNU lets a directory keep its own ChangeLog or share its parent's. GCC fixes the choice in code. default_changelog_locations lists the directories that own a ChangeLog, 59 of them at the pin (git_commit.py:27-87). A file belongs to the nearest listed directory above it (:680-686).

So gcc/cp/ has its own ChangeLog, apart from gcc/. gcc/config/i386/ is not in the list, so its files go in gcc/ChangeLog with paths that start with config/i386/, as in Listing 6.3-5. gcc/testsuite/ has its own file. A C++ front-end fix with a test therefore needs at least two blocks, one for gcc/cp/ and one for gcc/testsuite/. A file under the wrong block fails with wrong ChangeLog location, and the message names the right one (:779-787).

The commit message is the entry: contrib/gcc-changelog/git_commit.py

The scripts arrived on 2020-05-13 (contrib/ChangeLog:2071-2076). On 2020-05-25 Jakub Jelinek turned on the strict mode of the server hook. His announcement on the gcc list says that "ChangeLog entry should be solely in the commit message". The daily script "will be updating the ChangeLog files for you" (gcc list, 2020-05-25). The ChangeLogs section of the GCC Coding Conventions page documents the parts that the parser accepts, with an example. git_commit.py is the definition. It finds the entry by looking for the first line that looks like a ChangeLog line:

    def parse_lines(self, all_are_ignored):
        body = self.info.lines

        for i, b in enumerate(body):
            if not b:
                continue
            if (changelog_regex.match(b) or self.find_changelog_location(b)
                    or star_prefix_regex.match(b) or pr_regex.match(b)
                    or dr_regex.match(b) or author_line_regex.match(b)
                    or b.lower().startswith(CO_AUTHORED_BY_PREFIX)):
                self.changes = body[i:]
                return
        if not all_are_ignored:
            self.errors.append(Error('cannot find a ChangeLog location in '
                                     'message'))

Listing 6.3-6: where the entry starts (contrib/gcc-changelog/git_commit.py:451-465).

Everything above that line is free text: the subject, an empty line, and your explanation. Everything from that line down is the entry. A message for a middle-end fix with a test looks like this (the PR number and test name are invented):

alias: Check that the offset fits in a HWI

Explain the bug and the fix here.  This text goes to the git log and
the mailing list, but not to the ChangeLog files.

	PR tree-optimization/12345

gcc/ChangeLog:

	* tree-ssa-alias.cc (ao_ref_init_from_ptr_and_range): Check
	the pointer offset fits in a HWI when represented in bits.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr12345.c: New test.

A PR line above the first location line goes into every block (:548-554). The form of the subject line belongs to Chapter 6.4. Apart from the empty line after it, the parser reads the subject only for PR numbers. A PR component/number in the subject must use a valid component, and the entry must name the same PR (:351-358, :391-393). The parser does not check the length of the subject.

The errors you will meet most often:

MessageWhat it rejectsSource
Expected empty second line in commit messagea subject that continues on line 2:329-330
cannot find a ChangeLog location in messagea message with no entry:463-465
line should start with a taban entry line indented with spaces:566-568
first line should start with a tab, an asterisk and a spacea block that does not start with * :589-592
line exceeds 100 character limita line over 100 columns, a tab counted as 8:477-481
missing PR component, invalid PR componentPR 12345, or a component not in bug_components:507-516, :89-143
changed file not mentioned in a ChangeLoga modified file with no entry:766-767
unchanged file mentioned in a ChangeLogan entry for a file that the commit does not touch:714-721
missing description of a change(name): with no text after it:620-628
bad parentheses wrappinga ( with no ) by the end of the block:630-634

The 100-column limit is for the entry only. Code lines stop at 80.

The parser is lenient in four places. The date and author line is optional, because git records both (:800-825). The location line is optional when all the files in a block belong to one ChangeLog (:653-671). A new file with no entry gets New file. automatically, and a warning (:749-755). Some directories need no entry at all, for example libsanitizer/ and gcc/go/gofrontend/ (:145-155). The parser reads trailers too. Co-Authored-By: adds an author to every block, and the parser skips Reviewed-by: and its relatives (:188-190, :524-531). The (cherry picked from commit ...) line that git cherry-pick -x writes is what makes the job write Backported from master: (:533-541).

The error from the start of the chapter comes from this block:

        # Allow complete deletion of ChangeLog files in a commit
        project_files = [f for f in self.info.modified_files
                         if (self.is_changelog_filename(f[0], allow_suffix=True) and f[1] != 'D')
                         or f[0] in misc_files]
        ignored_files = [f for f in self.info.modified_files
                         if self.in_ignored_location(f[0])]
        if len(project_files) == len(self.info.modified_files):
            # All modified files are only MISC files
            return
        elif project_files:
            err = 'ChangeLog, DATESTAMP, BASE-VER and DEV-PHASE updates ' \
                  'should be done separately from normal commits\n' \
                  '(note: ChangeLog entries will be automatically ' \
                  'added by a cron job)'
            self.errors.append(Error(err))
            return

Listing 6.3-7: the ChangeLog file guard (contrib/gcc-changelog/git_commit.py:360-375).

A commit that changes only ChangeLog files, or the version files, returns before the parser looks for an entry. That is how you correct an entry after the job wrote it: edit the ChangeLog file alone, in its own commit, as the 2020 announcement advises.

Check a commit, or a patch file, before you send it:

$ contrib/gcc-git-customization.sh
$ git gcc-verify
$ git gcc-verify -p -n 3
$ contrib/gcc-changelog/git_email.py 0001-alias-Check-offset.patch

git gcc-verify runs git_check_commit.py on HEAD, or on the last three commits with -n 3. -p prints the entries it parsed (git_check_commit.py:31-45). For each commit it prints Checking <hash>: OK or FAILED, then one ERR: line per error (:53-73). It needs the GitPython package (git_repository.py:23-29). git_email.py checks a file from git format-patch without a repository. It needs python-dateutil and unidiff (git_email.py:26-30, :95-105).

A skeleton to fill in: contrib/mklog.py and git gcc-commit-mklog

contrib/mklog.py reads a diff and writes the skeleton of an entry. The skeleton has the location lines, a * file (function): line for each file, and the PR lines that the script finds in new tests (mklog.py:184-334). Its test file shows the output for a diff that adds two macros to gcc/config/riscv/riscv.h:

EXPECTED1 = '''\
gcc/ChangeLog:

	* config/riscv/riscv.h (C_S_BITS):
	(CSW_MAX_OFFSET):

'''

Listing 6.3-8: the expected skeleton for one header (contrib/test_mklog.py:65-71).

The skeleton stops at the colon. The script knows where you changed code, not what you changed. git gcc-verify rejects the skeleton as it stands. A (name): line followed by another item, or by nothing, is a "missing description of a change" (git_commit.py:179, :620-628). Write a description after each colon.

For a new file under a testsuite directory, mklog.py reads the first ten lines for a PR component/number comment. It also takes a number from a file name such as pr50209.c (mklog.py:210-243). A number from a file name has no component, so the line reads PR 50209 (test_mklog.py:242-262), and the checker rejects it as a missing PR component. -p asks Bugzilla for the component and the title, and corrects the line (mklog.py:151-164). -b adds PR numbers that you give.

$ pip3 install requests unidiff
$ git diff | contrib/mklog.py -p
$ git gcc-commit-mklog -b 12345

mklog.py imports requests and unidiff when it starts, so it needs both even without -p (mklog.py:38-40).

git gcc-commit-mklog runs git commit with GCC_FORCE_MKLOG=1 set (git-commit-mklog.py:44-60). Only with that variable does the prepare-commit-msg hook, which gcc-git-customization.sh offers to install, do anything (gcc-git-customization.sh:145-157, prepare-commit-msg:32-37). It sends the staged diff to git gcc-mklog -c (prepare-commit-msg:81), which puts the skeleton after your text and before any Signed-off-by: trailer. With an empty subject and exactly one PR, it also writes a subject of the form component: [PRnnnnn] (mklog.py:425-447).

Who writes the ChangeLog files: git_update_version.py

On master and the release branches, contrib/gcc-changelog/git_update_version.py writes the ChangeLog files once a day. It walks back to the last Daily bump. commit by gccadmin@gcc.gnu.org (:111-123), and runs each newer commit through the same parser:

def prepend_to_changelog_files(repo, folder, git_commit, add_to_git):
    if not git_commit.success:
        logging.info(f"While processing {git_commit.info.hexsha}:")
        for error in git_commit.errors:
            logging.info(error)
        raise AssertionError()
    for entry, output in git_commit.to_changelog_entries(use_commit_ts=True):
        full_path = os.path.join(folder, entry, 'ChangeLog')
        logging.info('writing to %s' % full_path)
        if os.path.exists(full_path):
            with open(full_path) as f:
                content = f.read()
        else:
            content = ''
        with open(full_path, 'w+') as f:
            f.write(output)
            if content:
                f.write('\n\n')
                f.write(content)
        if add_to_git:
            repo.git.add(full_path)

Listing 6.3-9: one commit becomes text at the top of each ChangeLog (contrib/gcc-changelog/git_update_version.py:65-85).

Each entry goes on top of the old file contents. Then the job writes the date to gcc/DATESTAMP and commits Daily bump. (:148-155). The bump commit changes only ChangeLog files and DATESTAMP, so it passes the guard in Listing 6.3-7.

A commit that the parser rejects would stop the job with an AssertionError. The server runs the same check earlier, on a push to master or a release branch, and refuses the push. The hook configuration is not in the tree, and the only record this chapter found is from May 2020. The day after the strict mode started, a contributor posted a refused push to releases/gcc-10. In it, the server quotes the message from Listing 6.3-7 under remote: *** ChangeLog format failed: (gcc list, 2020-05-26).

The job passes use_commit_ts=True (git_update_version.py:71). So for a normal commit the file gets the commit date, not the date line you wrote, but it keeps the names (git_commit.py:800-825).

Three things to carry away

The ChangeLog entry goes in the commit message, and the ChangeLog files are generated. A commit that edits one together with other files fails git gcc-verify and the push.

contrib/gcc-changelog/git_commit.py defines the format. Run git gcc-verify before you send, and write a description after every colon that mklog.py leaves empty.

The tab rule is in the tree, not in either document. Two columns per level, a tab for each eight, and only on the lines you add.

Things that surprise people

git gcc-verify accepts * file.c: with nothing after it. The empty-description check needs a name in parentheses (git_commit.py:179). mklog.py writes such a line for every test file you modify (test_mklog.py:242-262).

The date you write is not the date in the ChangeLog file. The daily job uses the commit date.

A line of exactly 80 columns passes check_GNU_style.py. GCC allows 80. The GNU Coding Standards ask for 79, and so do the editor settings in the tree.

check_GNU_style.py never checks a test. It skips every path that contains testsuite.

Documentation coverage

The GCC manual's Contributing node (gcc/doc/contribute.texi:5, included at gcc/doc/gcc.texi:187 and gcc/doc/gccint.texi:140) only points to https://gcc.gnu.org/contribute.html. The internals manual lists *ChangeLog* under Miscellaneous Docs as "Change log files for various parts of GCC" (gcc/doc/sourcebuild.texi:495-497), and does not say how they are written. The cpp manual documents the macro rule behind the #define exception under Function-like Macros (gcc/doc/cpp.texi:1327-1330). Chapter 6.2 shows how these .texi files become the rendered pages.

The rules themselves are on web pages outside the tree, read on 2026-10-26: the GNU Coding Standards nodes Formatting, Comments, Change Logs and Style of Change Logs, and GCC's Coding Conventions, whose ChangeLogs section lists the parts the parser accepts. Contributing names contrib/check_GNU_style.sh and git gcc-commit-mklog, and Read-write Git access lists the git gcc-* aliases.

What is not documented:

  • The tab rule. Neither document states it. .dir-locals.el, contrib/vimrc, .gitattributes and the checker do.
  • That check_GNU_style.py checks only added lines, and skips every path that contains testsuite and every Python file.
  • The list of directories that own a ChangeLog, and the rule that a file belongs to the nearest one above it.
  • The 100-column limit on entry lines.
  • That the skeleton from mklog.py fails git gcc-verify until you write the descriptions, and that a PR number taken from a file name has no component.
  • That a commit which changes only ChangeLog files skips the entry check. This is the way to correct a generated entry. Only the 2020 list message describes it.
  • That the daily job writes the commit date, not the date in the message.

Next: how a patch gets proposed: reading MAINTAINERS, posting to gcc-patches, and what a submission must hold besides its ChangeLog entry.


All source references in this chapter are to GCC 15.2.0 (releases/gcc-15.2.0). Line numbers in other releases will differ; the surrounding code rarely does. Where behaviour itself changed across a major version, it is flagged inline.