Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC gcc.dg/pr118224.c fails for AVR #1007

Open
dinuxbg opened this issue Jan 18, 2025 · 3 comments
Open

GCC gcc.dg/pr118224.c fails for AVR #1007

dinuxbg opened this issue Jan 18, 2025 · 3 comments

Comments

@dinuxbg
Copy link

dinuxbg commented Jan 18, 2025

The gcc.dg/pr118224.c GCC test case fails for AVR backend with an abort when executing with a simulator.

Since the test case calls calloc, I'm filing this as a potential issue in avr-libc.

The failing snippet is:

  if (__builtin_calloc ((~(__SIZE_TYPE__) 0) / 2, 3))
    __builtin_abort ();

The multiplication of the two calloc arguments overflows, and calloc returns non-zero value.

@sprintersb
Copy link
Collaborator

As far as I understand, the purpose of that GCC test case is to make sure that the compiler doesn't call calloc when it knows in advance that too much memory is being requested.

So the question is why the compiler is mapping __builtin_calloc to a calloc call instead of replacing the built-in call with NULL.

@dinuxbg
Copy link
Author

dinuxbg commented Jan 19, 2025

So the question is why the compiler is mapping __builtin_calloc to a calloc call instead of replacing the built-in call with NULL.

My understanding is the opposite - the call is left on purpose. See this comment in GCC bugzilla. Also the commit message describes the intention to avoid dead-code elimination:

... the following patch will fail to DCE
allocation calls if they have constant size which is too large ..

From the following quote in PR118224 I understand that calloc implementation must reject invalid sizes:

The calloc function returns either a pointer to the allocated space or a null
pointer if the space cannot be allocated or if the product nmemb * size would
wraparound size_t.

Section 7.24.3.1 "The aligned_alloc function" Paragraph 3 ISO/IEC 9899:2024

@sprintersb
Copy link
Collaborator

Ok, in that case maybe the best is to XFAIL the test case or similar, rather than turning calloc's MULT into a widening one.

Also @dl8dtl may have an opinion on it.

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

No branches or pull requests

2 participants