LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1047 - attempt to define llvm intrinsic not rejected by verifier
Summary: attempt to define llvm intrinsic not rejected by verifier
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Core LLVM classes (show other bugs)
Version: 1.9
Hardware: Macintosh MacOS X
: P normal
Assignee: Chris Lattner
URL: http://gendou.com/crap/temp/llvm-bug2...
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2006-12-12 17:07 PST by Gendou
Modified: 2010-02-22 12:50 PST (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gendou 2006-12-12 17:07:34 PST
To reproduce the bug:

 1. unzip llvm-bug.zip
 2. cd into the directory
 3. run make

you will see the diff of hello1.ll and hello2.ll
hello1.c and hello2.c are similar hello world examples using our custom libc
the makefile should compile them without using the default system libraries

notice that the string literal "Hello World!\n" is not an argument to printf in hello1.
instead, int 0 is the only argument.
it looks like it has been optimized to nothing.

rather than being a bug in my library, i believe this is an optimizer problem, because you can edit the 
Makefile, removing the -O3 optimization argument, and the problem seems to disappear.

this is my first bugzilla report, pardon me if my n00bness is apparent! :P

thanks!
Comment 1 Chris Lattner 2006-12-12 22:17:34 PST
The reason that you get the:
WARNING: While resolving call to function '__stdio_outs' arguments were dropped!

warnings is because you are relying undefined behavior.  In vprintf you cast __stdio_outs to take three 
parameters.  __v_printf passes three arguments to it, but __stdio_outs only takes two arguments.

LLVM "devirtualizes" the function pointer, turning it into a direct call, at which point it sees that you're 
passing three arguments (the third being fn->data) instead of two.  You should really change 
__stdio_outs to take three arguments.

However, there is still an llvm bug.  I'm investigating.

-Chris
Comment 2 Chris Lattner 2006-12-12 22:23:56 PST
The bug is in your code.  This is not valid LLVM:

void %llvm.memcpy.i32(sbyte*, sbyte*, uint, uint) {
entry:
        ret void
}

You've turned memcpy and others into a noop.  I will make the verifier reject this.  What are you trying to 
accomplish?
Comment 3 Chris Lattner 2006-12-12 22:33:31 PST
Fixed, patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20061211/041334.html

Testcase here:
Verifier/2006-12-12-IntrinsicDefine.ll

-Chris
Comment 4 Gendou 2006-12-15 13:42:09 PST
My purpose for defining intrinsics is to eliminate all declares from the final linked bytecode.
Declares are not handled by our compiler, so I need to resolve all of them.
I will fix the problem by writing C definitions for the intrinsics, and renaming them by hand.
That will allow me to link them in.
Thanks for all your help!
Comment 5 Chris Lattner 2006-12-15 13:57:31 PST
another solution is to handle intrinsics like llvm.mempcy.* as calls to memcpy.

-Chris
Comment 6 Gendou 2006-12-15 17:52:24 PST
Yes, after some discussion we decided to do it that way.
Thanks again for your help!
Comment 7 Gendou 2006-12-15 18:26:05 PST
I have made the two changes you mentioned.
I got rid of llvm.o which re-defined intrinsics.
Shame on me for doing that in the first place!
Also, __stdio_puts() now has a thrid parameter.

However, the problem still exists.
>> tail call void (int, ...)* %printf( int 0 )
This problem is only apparent when using optimizer passes.

Am I still doing something stupid?
Should I open a new bug report and let you close this one?

I uploaded llvm-bug2.zip (see bug URL) so you can see it for yourself.
Comment 8 Gendou 2006-12-15 18:39:54 PST
Ok, I just talked to nicholas, and he realized that the string literal is being accessed directly in printf() 
instead of being passed as an argument.

So, I was chasing a red haring. Sorry!!

I set the bug back to fixed.