[Bug c/86053] New: Builtin fwrite arguments have non_null attribute and builtin function declaration not overloaded
olivier at wuillemin dot fr
gcc-bugzilla@gcc.gnu.org
Tue Jun 5 11:16:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86053
Bug ID: 86053
Summary: Builtin fwrite arguments have non_null attribute and
builtin function declaration not overloaded
Product: gcc
Version: 6.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: olivier at wuillemin dot fr
Target Milestone: ---
Builtin fwrite arguments have non_null attribute and builtin function
declaration not overloaded
I'm compiling ARM embedded software using Atmel Studio 7 and Atmel toolchain
6.3.1.508 a package of ARM's gcc-arm-embedded project 6-2017-q2-update1.
Files functions (fopen, fread, fwrite...) are embedded in a specific <stdio>
module, weak libc stdio functions are overloaded.
1°/ Buitin fwrite function seems to have the 4th parameter (file handle) with
nonnull attribute.
Compile this code :
#include <stdlib.h>
int main(void)
{
fwrite("Hello", 5, 1, NULL);
fread(NULL, 5, 1, NULL);
}
For the fwrite line a warning is generated :
main.c (6,2): null argument where non-null required (argument 4) [-Wnonnull]"
For the fread line, no warning is generated.
Some others warnings are without interest for this demonstration.
This warning is also generated using Codelite and TDM32 [gcc (tdm-1) 5.1.0].
Arm's toolchain stdio.h fwrite prototype doesn't have the nonnull attribute :
size_t _EXFUN(fwrite, (const _PTR __restrict , size_t _size, size_t
_n, FILE *));
TDM32's toolchain stdio.h fwrite prototype doesn't have the nonnull attribute
:
_CRTIMP size_t __cdecl __MINGW_NOTHROW fwrite (const void*, size_t, size_t,
FILE*);
- Is it normal that the builtin fwrite arguments have the non-null attribute ?
- Is it normal that read argument attibutes have not the same behaviour than
write ?
2°/ Buitin fwrite prototype overload local fwrite declaration
Compile this code :
#include <stdlib.h>
typedef struct {
unsigned foo;
} FILE;
size_t fwrite(const void *ptr, size_t size, size_t n, FILE *stream)
{
size_t lCount;
lCount = 0;
if (stream != NULL) {
lCount = size * n;
}
return (size_t)lCount;
}
size_t fread(void *ptr, size_t size, size_t n, FILE *stream)
{
size_t lCount;
lCount = 0;
if (stream != NULL) {
lCount = size * n;
}
return (size_t)lCount;
}
int main(int argc, char **argv)
{
fwrite("hello world\n", 5, 1, NULL);
fread(NULL, 5, 1, NULL);
return 0;
}
With ARM toolchain, 2 warnings are generated :
One for the fwrite call :
main.c(32,2): warning: null argument where non-null required (argument 4)
[-Wnonnull]
One for the the fwrite function :
main.c(12,6): warning: nonnull argument 'stream' compared to NULL
[-Wnonnull-compare]
Local fwrite declaration has no nonnull attribute for 4th parameter and :
- a warning is generated at fonction call.
- More strange is the warning generated inside the function itself. It's own
declaration is overload by builtin declaration. no effect.
Compiling the code with TDM32 generate only one warning at function call.
Compilers options are -O0 -Wall
When using compiler option -fno-builtin, warnings disappear.
Best regards,
Olivier
More information about the Gcc-bugs
mailing list