[llvm-commits] [llvm-gcc-4.2] r46415 - /llvm-gcc-4.2/trunk/gcc/llvm-types.cpp

Duncan Sands baldrick at free.fr
Sun Jan 27 10:11:13 PST 2008


Author: baldrick
Date: Sun Jan 27 12:11:13 2008
New Revision: 46415

URL: http://llvm.org/viewvc/llvm-project?rev=46415&view=rev
Log:
Do not mark a function readnone or readonly if it has
a byval parameter.

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-types.cpp

Modified: llvm-gcc-4.2/trunk/gcc/llvm-types.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-types.cpp?rev=46415&r1=46414&r2=46415&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-types.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-types.cpp Sun Jan 27 12:11:13 2008
@@ -1219,14 +1219,19 @@
       DeclArgs = TREE_CHAIN(DeclArgs);
   }
   
-  // If we see a byval argument and if the function is 'readnone' we have to
-  // demote the function to being 'readonly' instead.  Not doing so would allow
-  // optimizers to delete stores into the argument that is passed into the
-  // function.
-  if (HasByVal && Attrs[0].index == 0 &&
-      (Attrs[0].attrs & ParamAttr::ReadNone)) {
-    Attrs[0].attrs &= ~ParamAttr::ReadNone;
-    Attrs[0].attrs |= ParamAttr::ReadOnly;
+  // If there is a byval argument then it is not safe to mark the function
+  // 'readnone' or 'readonly': gcc permits a 'const' or 'pure' function to
+  // write to struct arguments passed by value, but in LLVM this becomes a
+  // write through the byval pointer argument, which LLVM does not allow for
+  // readonly/readnone functions.
+  if (HasByVal && Attrs[0].index == 0) {
+    uint16_t &RAttrs = Attrs[0].attrs;
+    RAttrs &= ~(ParamAttr::ReadNone | ParamAttr::ReadOnly);
+    if (RAttrs == ParamAttr::None) {
+      for (unsigned i = 1, e = Attrs.size(); i < e ; ++i)
+        Attrs[i-1] = Attrs[i];
+      Attrs.pop_back();
+    }
   }
 
   // If the argument list ends with a void type node, it isn't vararg.





More information about the llvm-commits mailing list