[llvm-commits] [patch] Don't use alignment of global if global is weak in instcombine

Duncan Sands baldrick at free.fr
Mon Sep 17 10:10:36 PDT 2012


Hi Richard,

On 17/09/12 18:45, Richard Osborne wrote:
> I noticed that getPointeeAlignment() in instcombine was incorrectly using the
> alignment of a global even when the global is weak for the linker. The attached
> patch fixes this. OK to commit?

-    if (!GV->isDeclaration())
+    if (!GV->isDeclaration() && !GV->isWeakForLinker())
        return TD.getPreferredAlignment(GV);

How about
   if (GV->hasDefinitiveInitializer())
      ...
instead?

I say this because !GV->isDeclaration() is the same as GV->hasInitializer(),
and thus the difference is in the linkage types accepted:
GV->hasDefinitiveInitializer() will accept weak linkage if the ODR applies,
while your test will not.  So for my suggestion to be correct it is necessary
that the ODR implies that other (weak) instances of this global will be at
least as aligned as this instance.  Do you think this is the case?

Ciao, Duncan.



More information about the llvm-commits mailing list