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 853 - Asmprinter emits cast of constant wrong
Summary: Asmprinter emits cast of constant wrong
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Common Code Generator Code (show other bugs)
Version: 1.0
Hardware: All All
: P normal
Assignee: Chris Lattner
URL:
Keywords: compile-fail
Depends on:
Blocks:
 
Reported: 2006-07-28 19:51 PDT by Rib Rdb
Modified: 2010-02-22 12:44 PST (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments
inner-llvm.ll (79.90 KB, text/plain)
2006-07-28 20:22 PDT, Rib Rdb
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rib Rdb 2006-07-28 19:51:36 PDT
ribrdb@ribox:/tmp$ cat >inner.cc
#include <strstream> 
  class B : std::ostrstream{
   public:
    B() {}
    B(char* buf, int len, int ctr) : std::ostrstream(buf, len) { }
    virtual int foo() { return 0; }
  };
class A {
 public:
  A() : b((char*)0, 0, 0) { }
  B b;
};
class C : public B {
 public:
  virtual int foo();
};
int C::foo() { return 5;};

int main() {
  A *a = new A();
  B *b = new B((char*)0, 0, 0);
  b->foo();
  a->b.foo();
  return 0;
}
^D
ribrdb@ribox:/tmp$ gcc-3.4 -Wno-deprecated -S inner.cc
ribrdb@ribox:/tmp$ /usr/local/llvm/cfrontend/install/bin/llvm-gcc
-Wno-deprecated -S inner.cc -o inner-llvm.s
inner.cc:29: note: LLVM does not support aliases yet
inner.cc:29: note: LLVM does not support aliases yet
inner.cc:29: note: LLVM does not support aliases yet
inner.cc:29: note: LLVM does not support aliases yet

inner.s contains this vtable:
_ZTV1B:
	.long	56
	.long	0
	.long	_ZTI1B
	.long	_ZN1BD1Ev
	.long	_ZN1BD0Ev
	.long	_ZN1B3fooEv
	.long	-56
	.long	-56
	.long	_ZTI1B
	.long	_ZTv0_n12_N1BD1Ev
	.long	_ZTv0_n12_N1BD0Ev

but inner-llvm.s contains this vtable:
_ZTV1B:				# _ZTV1B
	.size _ZTV1B, 44
	.long	56
	.zero	4
	.long	_ZTI1B
	.long	_ZN1BD1Ev
	.long	_ZN1BD0Ev
	.long	_ZN1B3fooEv
	.long	18446744073709551560
	.long	-56
	.long	_ZTI1B
	.long	_ZTv0_n12_N1BD1Ev
	.long	_ZTv0_n12_N1BD0Ev
Comment 1 Chris Lattner 2006-07-28 20:14:33 PDT
Are you sure this is a problem?  18446744073709551560 = -56.

What platform (target triple) is this on?  Is .long a 32-bit value?  If so, this is definitely a bug.  Can you 
run:

/usr/local/llvm/cfrontend/install/bin/llvm-gcc
-Wno-deprecated -S inner.cc -o inner-llvm.ll -emit-llvm

and attach inner-llvm.ll plz ?

Thanks,

-Chris
Comment 2 Rib Rdb 2006-07-28 20:22:15 PDT
Created attachment 372 [details]
inner-llvm.ll
Comment 3 Rib Rdb 2006-07-28 20:25:06 PDT
It's 32 bit intel linux. When compiling the .s file, gcc says "Warning: bignum
truncated to 4 bytes"
Comment 4 Chris Lattner 2006-07-28 20:25:41 PDT
Definitely a bug.
Comment 5 Chris Lattner 2006-07-28 20:27:07 PDT
A reduced .ll testcase:

%X = global int* cast (ulong 18446744073709551560 to int*)

Produces:

_X:                             ; 'X'
        .long   18446744073709551560
Comment 6 Chris Lattner 2006-07-28 20:58:03 PDT
Fixed.  Testcase here: Regression/CodeGen/X86/2006-07-28-AsmPrint-Long-As-Pointer.ll

Patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20060724/036351.html

Thanks!

-Chris