[PATCH] D17037: [MemoryBuiltins] Fix an issue with hasNoAliasAttr

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 9 11:55:36 PST 2016


sanjoy created this revision.
sanjoy added reviewers: chandlerc, reames.
sanjoy added a subscriber: llvm-commits.
Herald added a subscriber: mcrosier.

`hasNoAliasAttr` is buggy: it checks to see if the called function has
a `noalias` attribute, which is incorrect since functions are not even
allowed to have the `noalias` attribute.  The comment on its only
caller, `llvm::isNoAliasFn`, makes it pretty clear that the intention
to do the `noalias` check on the return value, and not the callee.

Unfortunately I couldn't find a way to test this upstream -- fixing
this does not change the observable behavior of any of the passes that
use this.  This is not very surprising, since `noalias` does not tell
anything about the contents of the allocated memory (so, e.g., you
still cannot fold loads).  I'll be happy to be proven wrong though.

http://reviews.llvm.org/D17037

Files:
  lib/Analysis/MemoryBuiltins.cpp

Index: lib/Analysis/MemoryBuiltins.cpp
===================================================================
--- lib/Analysis/MemoryBuiltins.cpp
+++ lib/Analysis/MemoryBuiltins.cpp
@@ -144,7 +144,7 @@
 
 static bool hasNoAliasAttr(const Value *V, bool LookThroughBitCast) {
   ImmutableCallSite CS(LookThroughBitCast ? V->stripPointerCasts() : V);
-  return CS && CS.hasFnAttr(Attribute::NoAlias);
+  return CS && CS.paramHasAttr(AttributeSet::ReturnIndex, Attribute::NoAlias);
 }
 
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17037.47349.patch
Type: text/x-patch
Size: 483 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160209/7f9f4a95/attachment.bin>


More information about the llvm-commits mailing list