On Sun, Mar 6, 2011 at 9:52 PM, Jochen Wilhelmy <j.wilhelmy at arcor.de>
wrote:> I have a module containing a constant e.g.
>
> @input = global %0 zeroinitializer, align 16
>
> when I copy the global into another module I use
> newGlobal->copyAttributesFrom(global);
> but the new module now has
>
> @input = external global %0, align 16
>
> i.e. the zeroinitializer is missing. how do I set it or
> copy it from the other global?
The initializer doesn't count as an attribute, I guess.
if (global->hasInitializer())
newGlobal->setInitializer(global->getInitializer());
Note that, as I mentioned in response to your earlier question, not
all constants are safe to use in a different module. So simply copying
the initializer may be unsafe...
Note that linkage and constness don't seem to count either.
newGlobal->setConstant(global->isConstant());
newGlobal->setLinkage(global->getLinkage());
All three of these can also be passed to the constructor for
newGlobal, by the way. According to the comment on
GlobalValue::copyAttributesFrom() (as well as its GlobalVariable
override) this seems to be the defining characteristic that qualifies
them as "attributes"; it considers any property you can't pass to
the
constructor an attribute, apparently.