analyzer: follow macro aliases for named constant [PR125265] #226

Closed
azoff wants to merge 1 commit from azoff/gcc:pr/macro-aliases into trunk
Member

Ok for trunk?

I'm unsure if this should also go into releases/gcc-16, WDYT?

--

CC: David Malcolm dmalcolm@redhat.com

Ok for trunk? I'm unsure if this should also go into releases/gcc-16, WDYT? -- CC: David Malcolm <dmalcolm@redhat.com>
analyzer: follow macro aliases for named constant [PR125265]
All checks were successful
/ format-checks (pull_request) Successful in 1m35s
650c07cdb2
Newlib, picolibc, and probably other libc implementations, use

  #define O_CREAT  _FCREAT
  #define O_TRUNC  _FTRUNC
  #define O_EXCL   _FEXCL

In r17-177-g9a5f89005dc49d, support was added to identify redundant
flags, but the implementation requires that the value of the macros
O_CREAT, O_EXCL, O_RDWR to be a number.  This patch extends the support
to also allow macro aliases.  It will follow up to 8 levels of macros in
order to reach the number.

This change fixes

FAIL: gcc.dg/analyzer/mkostemp-1.c  (test for warnings, line 109)
FAIL: gcc.dg/analyzer/mkostemp-1.c  (test for warnings, line 115)
FAIL: gcc.dg/analyzer/mkostemps-1.c  (test for warnings, line 115)
FAIL: gcc.dg/analyzer/mkostemps-1.c  (test for warnings, line 121)

Regtested with arm-none-eabi (with newlib) on r17-3738-gaaa0f6b1e87bc6.

gcc/c/ChangeLog:

	PR analyzer/125265
	* c-parser.cc: Follow, up to eight, macro alias to get the value
	for a named constant.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Member

Hi @azoff. This bot helps send your PR as a patch series to the mailing list.

Next steps

  1. Write a clear PR description. It will be used as the cover letter.
  2. To CC extra people, add lines like this at the end of the PR description: CC: Reviewer1 <revi.ewer@example.com>, Reviewer2 <an.other@example.com>.
  3. To preview the emails, comment with /preview.
  4. When ready, request review in the Reviewers section. Or, if you just want to send the series, comment with /submit.
  5. Use the cover-letter links below to follow replies.
  6. For a new patch series, push your changes, update the PR description with a Changes since vX section, and comment with /submit again.

See Submitting Patches and UsingForge.

Consider joining the gcc and gcc-patches mailing lists..
For real time communication, check the gcc irc channels.

Or join #overseers on Libera Chat, particularly if this automation is not working (stay online to get replies, IRC does not save messages if people are not online).

<!-- pr-welcome --> Hi @azoff. This bot helps send your PR as a patch series to the mailing list. ## Next steps 1. Write a clear PR description. It will be used as the cover letter. 2. To CC extra people, add lines like this **at the end** of the PR description: `CC: Reviewer1 <revi.ewer@example.com>, Reviewer2 <an.other@example.com>`. 3. To preview the emails, comment with `/preview`. 4. When ready, request review in the Reviewers section. Or, if you just want to send the series, comment with `/submit`. 5. Use the cover-letter links below to follow replies. 6. For a new patch series, push your changes, update the PR description with a `Changes since vX` section, and comment with `/submit` again. See [Submitting Patches](https://gcc.gnu.org/contribute.html#patches) and [UsingForge](https://gcc.gnu.org/wiki/UsingForge). Consider joining the [gcc and gcc-patches mailing lists.](https://gcc.gnu.org/lists.html). For real time communication, check the [gcc irc channels](https://gcc.gnu.org/wiki/GCConIRC). Or join [`#overseers`](https://web.libera.chat/#overseers) on Libera Chat, particularly if this automation is not working (stay online to get replies, IRC does not save messages if people are not online).
azoff requested review from dmalcolm 2026-08-31 06:26:55 +00:00
Member

Version 1 of this pull request has been stored. It includes the following commits:

<!-- pr-new-version --> Version 1 of this pull request has been stored. It includes the following commits: - analyzer: follow macro aliases for named constant [PR125265] - 650c07cdb28058525967b479fb10934f44f12d1d
Author
Member

/submit

/submit
azoff force-pushed pr/macro-aliases from 650c07cdb2
All checks were successful
/ format-checks (pull_request) Successful in 1m35s
to 2b29c43709
Some checks failed
/ format-checks (pull_request) Failing after 1m31s
2026-10-03 10:30:32 +00:00
Compare
azoff force-pushed pr/macro-aliases from 2b29c43709
Some checks failed
/ format-checks (pull_request) Failing after 1m31s
to 8ac305a10b
All checks were successful
/ format-checks (pull_request) Successful in 1m32s
2026-10-03 10:33:48 +00:00
Compare
Author
Member

/submit

/submit
Member

Version 2 of this pull request has been stored. It includes the following commits:

<!-- pr-new-version --> Version 2 of this pull request has been stored. It includes the following commits: - analyzer: follow macro aliases for named constant [PR125265] - 8ac305a10b5089b38f36eca1d1bc66132e95545f
Member

Sent patch version 2 as a single email to gcc-patches mailing list gcc-patches@gcc.gnu.org and cc'd David Malcolm dmalcolm@redhat.com.
Cover letter

Sent patch version 2 as a single email to gcc-patches mailing list <gcc-patches@gcc.gnu.org> and cc'd David Malcolm <dmalcolm@redhat.com>. [Cover letter](https://inbox.sourceware.org/gcc-patches/bmm.hmv4y5tlcc.gcc.gcc.azoff.226.2.0@forge-stage.sourceware.org)
dmalcolm requested changes 2026-10-05 23:55:53 +00:00
Dismissed
@ -33,1 +34,4 @@
Common Joined UInteger Var(param_analyzer_max_macro_alias_depth) Init(8) IntegerRange(0, 255)
Maximum number of macro aliases to follow when resolving named constants in the analyzer; zero disables alias following.
-param=asan-globals=
Member

Thanks for adding the param. Please can you add documentation for it to gcc/doc/params.texi.

Thanks for adding the param. Please can you add documentation for it to `gcc/doc/params.texi`.
Author
Member

Done in v3.

Done in v3.
azoff marked this conversation as resolved
azoff force-pushed pr/macro-aliases from 8ac305a10b
All checks were successful
/ format-checks (pull_request) Successful in 1m32s
to f5ef3a0b9d
All checks were successful
/ format-checks (pull_request) Successful in 1m31s
2026-10-06 16:49:04 +00:00
Compare
Author
Member

/submit

/submit
Member

Version 3 of this pull request has been stored. It includes the following commits:

<!-- pr-new-version --> Version 3 of this pull request has been stored. It includes the following commits: - analyzer: follow macro aliases for named constant [PR125265] - f5ef3a0b9d507945c14f74d41fb711dd74f7416a
Member

Pull Request versions:

# Base Head
1 aaa0f6b1e8 650c07cdb2 (diff)
2 aaa0f6b1e8 8ac305a10b (diff)
3 aaa0f6b1e8 f5ef3a0b9d (diff)

In order to compare , clone this repository and run

PR=226
git fetch origin "refs/versioned_pull/${PR}/*:refs/versioned_pull/${PR}/*"
PRV1=1
PRV2=2
git range-diff "refs/versioned_pull/${PR}/${PRV1}/base..refs/versioned_pull/${PR}/${PRV1}/head"  "refs/versioned_pull/${PR}/${PRV2}/base..refs/versioned_pull/${PR}/${PRV2}/head"
<!-- pr-versions --> Pull Request versions: | # | Base | Head | | | - | ---- | ---- | - | | 1 | aaa0f6b1e87bc62ea15da6eab431af6dcebf6414 | 650c07cdb28058525967b479fb10934f44f12d1d | [(diff)](https://forge.sourceware.org/gcc/gcc.git/compare/aaa0f6b1e87bc62ea15da6eab431af6dcebf6414...650c07cdb28058525967b479fb10934f44f12d1d) | | 2 | aaa0f6b1e87bc62ea15da6eab431af6dcebf6414 | 8ac305a10b5089b38f36eca1d1bc66132e95545f | [(diff)](https://forge.sourceware.org/gcc/gcc.git/compare/aaa0f6b1e87bc62ea15da6eab431af6dcebf6414...8ac305a10b5089b38f36eca1d1bc66132e95545f) | | 3 | aaa0f6b1e87bc62ea15da6eab431af6dcebf6414 | f5ef3a0b9d507945c14f74d41fb711dd74f7416a | [(diff)](https://forge.sourceware.org/gcc/gcc.git/compare/aaa0f6b1e87bc62ea15da6eab431af6dcebf6414...f5ef3a0b9d507945c14f74d41fb711dd74f7416a) | In order to compare , clone this repository and run ``` PR=226 git fetch origin "refs/versioned_pull/${PR}/*:refs/versioned_pull/${PR}/*" PRV1=1 PRV2=2 git range-diff "refs/versioned_pull/${PR}/${PRV1}/base..refs/versioned_pull/${PR}/${PRV1}/head" "refs/versioned_pull/${PR}/${PRV2}/base..refs/versioned_pull/${PR}/${PRV2}/head" ```
Member

Sent patch version 3 as a single email to gcc-patches mailing list gcc-patches@gcc.gnu.org and cc'd David Malcolm dmalcolm@redhat.com.
Cover letter

Sent patch version 3 as a single email to gcc-patches mailing list <gcc-patches@gcc.gnu.org> and cc'd David Malcolm <dmalcolm@redhat.com>. [Cover letter](https://inbox.sourceware.org/gcc-patches/bmm.hmyqd56aw4.gcc.gcc.azoff.226.3.0@forge-stage.sourceware.org)
dmalcolm approved these changes 2026-10-06 17:08:31 +00:00
dmalcolm left a comment

Thanks; LGTM for trunk. Let's let it bake there for a bit before backporting.

Thanks; LGTM for trunk. Let's let it bake there for a bit before backporting.
Author
Member

@dmalcolm wrote in #226 (comment):

Thanks; LGTM for trunk. Let's let it bake there for a bit before backporting.

Should I leave this pull open until the backport is done or close it when I push to trunk?

@dmalcolm wrote in https://forge.sourceware.org/gcc/gcc/pulls/226#issuecomment-7728: > Thanks; LGTM for trunk. Let's let it bake there for a bit before backporting. Should I leave this pull open until the backport is done or close it when I push to trunk?
Author
Member

Linaro CI reported the following on v3:

  | # build_abe bootstrap:
  | # FAILED
  | # First few build errors in logs:
  | # 00:35:00 /home/tcwg-build/workspace/tcwg_gnu_7/abe/snapshots/gcc.git~master/gcc/c/c-parser.cc:2038:19: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare]
  | # 00:36:33 make[3]: *** [Makefile:1229: c/c-parser.o] Error 1
  | # 00:36:33 make[2]: *** [Makefile:5183: all-stage2-gcc] Error 2
  | # 00:36:33 make[1]: *** [Makefile:26491: stage2-bubble] Error 2
  | # 00:36:33 make: *** [Makefile:1139: all] Error 2

To fix this, I made the following change in the version that I pushed as r17-4966-gbaea2a0be30d84:

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index e03c06da9a2..8aa4f54eb0d 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -2022,9 +2022,13 @@ private:
      as doing so would require a parser.
      Also handle the case where MACRO's definition is a single identifier
      that is itself a macro name (e.g. "#define O_CREAT _FCREAT"), by
-     following the chain of aliases up to MAX_ALIAS_DEPTH deep.  */
-  tree consider_macro (cpp_macro *macro, unsigned int depth = 0) const
+     following the chain of aliases.  */
+  tree consider_macro (cpp_macro *macro, int depth = 0) const
   {
+    /* UInteger option variables are stored as int, so "depth" must be signed
+       to avoid a signed/unsigned comparison here. */
+    gcc_assert (depth >= 0);
+
     if (macro->paramc > 0)
       return NULL_TREE;
     if (macro->kind != cmk_macro)
Linaro CI reported the following on v3: ``` | # build_abe bootstrap: | # FAILED | # First few build errors in logs: | # 00:35:00 /home/tcwg-build/workspace/tcwg_gnu_7/abe/snapshots/gcc.git~master/gcc/c/c-parser.cc:2038:19: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare] | # 00:36:33 make[3]: *** [Makefile:1229: c/c-parser.o] Error 1 | # 00:36:33 make[2]: *** [Makefile:5183: all-stage2-gcc] Error 2 | # 00:36:33 make[1]: *** [Makefile:26491: stage2-bubble] Error 2 | # 00:36:33 make: *** [Makefile:1139: all] Error 2 ``` To fix this, I made the following change in the version that I pushed as r17-4966-gbaea2a0be30d84: ```diff diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index e03c06da9a2..8aa4f54eb0d 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -2022,9 +2022,13 @@ private: as doing so would require a parser. Also handle the case where MACRO's definition is a single identifier that is itself a macro name (e.g. "#define O_CREAT _FCREAT"), by - following the chain of aliases up to MAX_ALIAS_DEPTH deep. */ - tree consider_macro (cpp_macro *macro, unsigned int depth = 0) const + following the chain of aliases. */ + tree consider_macro (cpp_macro *macro, int depth = 0) const { + /* UInteger option variables are stored as int, so "depth" must be signed + to avoid a signed/unsigned comparison here. */ + gcc_assert (depth >= 0); + if (macro->paramc > 0) return NULL_TREE; if (macro->kind != cmk_macro) ```
azoff closed this pull request 2026-10-07 16:15:21 +00:00
All checks were successful
/ format-checks (pull_request) Successful in 1m31s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gcc/gcc!226
No description provided.