This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

equality of label addresses


The GCC documentation is silent on the issue of equality of label
addresses for the C front-ends "labels as values" extension.

The program below works fine with `-O0', but gets an assertion failure
with `-O2', because with `-00', the two labels `label2' and `label3'
have different addresses, but with `-O2', GCC does some duplicate code
elimination and so the two labels end up pointing to the same code.
(This is with gcc 2.95 and 3.1.  I haven't tested this with
the current mainline.)
Is this a valid optimization?

Consistency with the C language's treatment of function addresses
would suggest that this optimization should not be permitted,
so if the intent is that it *is* permitted, then I think the GCC
documentation should make this explicit.

	#include <assert.h>
	int i;
	void foo() {}
	int main() {
		void * labels[] = { &&label0, &&label1, &&label2, &&label3 };
		goto *labels[i];
		label0:
			assert(labels[2] != labels[3]);
		label1:
			return 42;
		label2:
			foo();
			goto label0;
		label3:
			foo();
			goto label0;

	}

Even more worrying is that GCC 3.1 will do the same optimization
even if you insert ` asm volatile("nop"); ' in front of each
call to foo() -- the generated code contains only a single "nop"
instruction.  This seems to contradict the GCC documentation,
which says that volatile asm instructions will not be
"deleted, moved significantly, or combined".
Is this a bug?

If not, then I think the documentation for volatile asm instructions
should be clarified.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]