[LLVMdev] bug or expected behaviour?

Carl Norum carl at lytro.com
Tue Jun 4 15:55:31 PDT 2013


I've been chasing down a bug for a few days in some RTOS code I'm building with clang.  In the end it comes down to this code:

	void external(void);
	void test(char *x)
	{
	    x--;
	    if (!x)
	    {
	        external();
	    }
	}

When compiled for ARM with TOT clang (r183249) at -O1 or greater, no calls to 'external()' appear in the output code at all.  I have an example project I can send out if anyone's interested, but it's just the above source file and this makefile:

	.PHONY: all optimized unoptimized clean

	all: optimized unoptimized
		grep external *.s

	optimized:
		./clang -S -O1 example.c -o example-optimized.s

	unoptimized:
		./clang -S -O0 example.c -o example-unoptimized.s

	clean:
		rm -f *.s

When run, I get this output:

	$ make
	./clang -S -O1 example.c -o example-optimized.s
	./clang -S -O0 example.c -o example-unoptimized.s
	grep external *.s
	example-unoptimized.s:	bl	external

As you can see, 'example-optimized.s' contains no references to the 'external()' function.  Am I missing something subtle here standard-wise?  Or is this an optimizer bug?  If it's a bug, what's the right component to file it in?

I've attached the complete assembly output (both example-optimized.s and example-unoptimized.s) in case that's helpful.  Thanks for any insight!

Oh - almost forgot - version information from the compiler:

	$ ./clang --version
	clang version 3.4 (trunk 183249)
	Target: arm-none--eabi
	Thread model: posix

-- 
Carl Norum
carl at lytro.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: example-optimized.s
Type: application/octet-stream
Size: 273 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130604/06452103/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example-unoptimized.s
Type: application/octet-stream
Size: 479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130604/06452103/attachment-0001.obj>


More information about the llvm-dev mailing list