[PATCH] C undefined behavior fix

Linus Torvalds torvalds@transmeta.com
Fri Jan 4 13:54:00 GMT 2002


In article <E16Lvh8-0006E6-00@the-village.bc.nu> you write:
>> Yes, but doesn't -ffreestanding imply that gcc _can't_ assume this is
>> the standard library, and that strcpy _might_ not be what it thinks, and
>> to just call strpy?
>
>strcpy is part of the C standard. You'd need a -fits-not-c-its-linux

No. strcpy() is part of the C standard, yes, but so are a lot of other
things, including the rules on arithmetic and pointer conversion. The
current gcc strcpy() optimization is clearly illegal if it doesn't allow
for those other C rules.

While the expression

	"string" - TASK_BASE

may be undefined, the expression

	(void *)((unsigned long)"string" - TASK_BASE)

is _not_ undefined, and gcc cannot play it's illegal games with it.

		Linus



More information about the Gcc mailing list