[LLVMdev] Appending globals

S3 scubed at nostratic.lingcog.iit.edu
Tue May 19 23:50:39 PDT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I tried to write a simple program to use appending globals
to get a feel for how they work.
(See attached.)
I intend it to print out:
x!
y!
z!
in any order.
However, when I compile it, I get
...
	%lt = icmp ult i32 %counter, udiv (i32 sub (i32 ptrtoint ([1 x %0]*
getelementptr ([1 x %0]* bitcast ([3 x %0]* @abc to [1 x %0]*), i32 1) to i32),
i32 ptrtoint ([3 x %0]* @abc to i32)), i32 sub (i32 ptrtoint (%0* getelementptr
([3 x %0]* @abc, i32 0, i32 1) to i32), i32 ptrtoint ([3 x %0]* @abc to i32)))	
; <i1> [#uses=1]
...
The part to note is that all of them become [3 x %0]*, except the first
is bitcast to [1 x %0]*.  I was trying to determine the length
by doing sizeof(x)/sizeof(x[0]), as recommended in the documentation.
But, that extra bitcast breaks it, causing it to only print:
x!
Is this bitcast intentional?  If so, is there a way to determine
the length?  It seems that doing

  %abcnext = getelementptr [1 x {i32, void()*}]* @abc, i32 1
  %abcnexti = ptrtoint [1 x {i32, void()*}]* %abcnext to i32

should get the pointer to after @abc, not the pointer
to what was the end of it in just that file.
It seems like a bug.

- --
++++++++++++[->+++++++>+++++++++<<]>-.>[->+>+>+>+>+
<<<<<]>++++++++.>-------.<--.>>.---.>++.>-----.>+++
+++++[->++++<]>.<<<<<<<<.>>++.>.>.>.>>++++++++++.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkoTqD4ACgkQxzVgPqtIcftr6ACfeMrzJltwET6s+MPN48XhERaA
30cAnjRsBTK/g48+NW50AiKrLCjoTMWm
=0srC
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: a.ll
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090519/b6b6f55f/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: b.ll
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090519/b6b6f55f/attachment-0001.ksh>


More information about the llvm-dev mailing list