[patch] Don't rauw an alias in llvm.used (v2)

Rafael EspĂ­ndola rafael.espindola at gmail.com
Mon Apr 22 14:09:56 PDT 2013


Clang has recently started producing internal but llvm.used aliases as
a backward compatibility hack for static functions declared in an
extern C context.

This found an interesting bug in GlobalOpt: It would replace the alias
with the function in the initialization of llvm.used, allowing llvm to
drop the alias.

One option would be to just not call replaceAllUsesWith if the alias
is in llvm.used. We would lose some optimizations and I am afraid of
making it possible for users to add __attribute__((used)) to get this
side effect. What we should do is replace all other users.

I ended implementing two options. The first one (add-back.patch)
looked the simplest at first: Just call replaceAllUsesWith and patch
llvm.used back to its previous state. The main problem in here is
detecting if any other changes were made. We have to walk the
constant's uses to find out.

Since we ale walking the uses anyway, another option (cow.patch) is to
duplicate a bit of the copy on write logic in replaceAllUsesWith to
special case use chains that end up in llvm.used. In the end I think I
like this one a bit more. What do you think?

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: add-back.patch
Type: application/octet-stream
Size: 7892 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130422/5ced3633/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cow.patch
Type: application/octet-stream
Size: 5571 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130422/5ced3633/attachment-0001.obj>


More information about the llvm-commits mailing list