Bug 26383 - -O3 and -Wall produce spurious warnings about builtin string functions
Summary: -O3 and -Wall produce spurious warnings about builtin string functions
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-20 16:39 UTC by Andrew Roberts
Modified: 2006-02-20 17:17 UTC (History)
2 users (show)

See Also:
Host: i386-redhat-linux
Target: i386-redhat-linux
Build: i386-redhat-linux
Known to work:
Known to fail:
Last reconfirmed:


Attachments
gcc -v -save-temps -O3 -Wall output (2.50 KB, text/plain)
2006-02-20 16:41 UTC, Andrew Roberts
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Roberts 2006-02-20 16:39:25 UTC
gcc version 4.1.0 20060219 (prerelease) produces spurious warnings when
used with -Wall and -O3 together. Previous released versions haven't had this behaviour. It appears to be issuing multiple warnings when string functions are inlined using the __builtin_ versions eg __builtin_strcmp. For example:

test-strcmp.c:9: warning: pointer targets in passing argument 1 of ‘strlen’ differ in signedness
test-strcmp.c:9: warning: pointer targets in passing argument 1 of ‘__builtin_strcmp’ differ in signedness
test-strcmp.c:9: warning: pointer targets in passing argument 1 of ‘__builtin_strcmp’ differ in signedness
test-strcmp.c:9: warning: pointer targets in passing argument 1 of ‘__builtin_strcmp’ differ in signedness

The inital warning about strlen is great, the rest is just about GCC internals and confusing. Here is a code snippet:

#include <string.h>

int main(void)
{
	int i;
	const char *s="Hello";
	unsigned char data[40];
	strcpy(data, s);
	i=strcmp(data, s);
	return 0;
}
this will show the problem when built with the prerelease version of gcc (4.1.0 20060219 (prerelease)) as follows:
gcc -O3 -Wall -o test test.c
 
I'll attach the build log from gcc -v -save-temps later.

Thanks

Andrew Roberts
Comment 1 Andrew Roberts 2006-02-20 16:41:40 UTC
Created attachment 10880 [details]
gcc -v -save-temps -O3 -Wall output
Comment 2 Andrew Pinski 2006-02-20 17:17:14 UTC
This is really  a glibc bug as far as I can tell.
Lets look into what glibc exands the string functions to:
 i=__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (data) && __builtin_constant_p (s) && (__s1_len = strlen (data), __s2_len = strlen (s), (!((size_t)(const void *)((data) + 1) - (size_t)(const void *)(data) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((s) + 1) - (size_t)(const void *)(s) == 1) || __s2_len >= 4)) ? __builtin_strcmp (data, s) : (__builtin_constant_p (data) && ((size_t)(const void *)((data) + 1) - (size_t)(const void *)(data) == 1) && (__s1_len = strlen (data), __s1_len < 4) ? (__builtin_constant_p (s) && ((size_t)(const void *)((s) + 1) - (size_t)(const void *)(s) == 1) ? __builtin_strcmp (data, s) : (__extension__ ({ __const unsigned char *__s2 = (__const unsigned char *) (__const char *) (s); register int __result = (((__const unsigned char *) (__const char *) (data))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((__const unsigned char *) (__const char *) (data))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((__const unsigned char *) (__const char *) (data))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((__const unsigned char *) (__const char *) (data))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (s) && ((size_t)(const void *)((s) + 1) - (size_t)(const void *)(s) == 1) && (__s2_len = strlen (s), __s2_len < 4) ? (__builtin_constant_p (data) && ((size_t)(const void *)((data) + 1) - (size_t)(const void *)(data) == 1) ? __builtin_strcmp (data, s) : (__extension__ ({ __const unsigned char *__s1 = (__const unsigned char *) (__const char *) (data); register int __result = __s1[0] - ((__const unsigned char *) (__const char *) (s))[0]; if (__s2_len > 0 && __result == 0) { __result = (__s1[1] - ((__const unsigned char *) (__const char *) (s))[1]); if (__s2_len > 1 && __result == 0) { __result = (__s1[2] - ((__const unsigned char *) (__const char *) (s))[2]); if (__s2_len > 2 && __result == 0) __result = (__s1[3] - ((__const unsigned char *) (__const char *) (s))[3]); } } __result; }))) : __builtin_strcmp (data, s)))); });

Yes that mess.

This is not a gcc bug, there is nothing GCC can do better.
Anyways with ppc-darwin, I only get the following warnings (not using the preprocessed source):
t.c:8: warning: pointer targets in passing argument 1 of 'strcpy' differ in signedness
t.c:9: warning: pointer targets in passing argument 1 of 'strcmp' differ in signedness

So this is a bug in the glibc headers which exposed the other warnings.