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

Chris Lattner sabre at nondot.org
Fri Jan 25 14:37:31 PST 2008


Author: lattner
Date: Fri Jan 25 16:37:31 2008
New Revision: 46373

URL: http://llvm.org/viewvc/llvm-project?rev=46373&view=rev
Log:
If a function takes a byval parameter, it can't be readnone, we 
have to mark it readonly instead.  This fixes
test/CFrontend/2008-01-25-ByValReadNone.c


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=46373&r1=46372&r2=46373&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-types.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-types.cpp Fri Jan 25 16:37:31 2008
@@ -1123,18 +1123,17 @@
   // accepts it).  But llvm IR does not allow both, so
   // set only ReadNone.
   if (flags & ECF_CONST)
-    // Since they write the return value through a pointer,
-    // 'sret' functions cannot be 'readnone'.
-    if (!ABIConverter.isStructReturn())
-      RAttributes |= ParamAttr::ReadNone;
+    RAttributes |= ParamAttr::ReadNone;
 
   // Check for 'readonly' function attribute.
   if (flags & ECF_PURE && !(flags & ECF_CONST))
-    // Since they write the return value through a pointer,
-    // 'sret' functions cannot be 'readonly'.
-    if (!ABIConverter.isStructReturn())
-      RAttributes |= ParamAttr::ReadOnly;
+    RAttributes |= ParamAttr::ReadOnly;
 
+  // Since they write the return value through a pointer,
+  // 'sret' functions cannot be 'readnone' or 'readonly'.
+  if (ABIConverter.isStructReturn())
+    RAttributes &= ~(ParamAttr::ReadNone|ParamAttr::ReadOnly);
+  
   // Compute whether the result needs to be zext or sext'd.
   RAttributes |= HandleArgumentExtension(TREE_TYPE(type));
 
@@ -1162,6 +1161,9 @@
   LLVM_TARGET_INIT_REGPARM(local_regparam, type);
 #endif // LLVM_TARGET_ENABLE_REGPARM
   
+  // Keep track of whether we see a byval argument.
+  bool HasByVal = false;
+  
   // Check if we have a corresponding decl to inspect.
   tree DeclArgs = (decl) ? DECL_ARGUMENTS(decl) : NULL;
   // Loop over all of the arguments, adding them as we go.
@@ -1208,13 +1210,25 @@
                                     local_regparam);
 #endif // LLVM_TARGET_ENABLE_REGPARM
     
-    if (Attributes != ParamAttr::None)
+    if (Attributes != ParamAttr::None) {
+      HasByVal |= Attributes & ParamAttr::ByVal;
       Attrs.push_back(ParamAttrsWithIndex::get(ArgTypes.size(), Attributes));
+    }
       
     if (DeclArgs)
       DeclArgs = TREE_CHAIN(DeclArgs);
   }
   
+  // If we see a byval argument and if the function is 'readonly' 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 the argument list ends with a void type node, it isn't vararg.
   isVarArg = (Args == 0);
   assert(RetTy && "Return type not specified!");





More information about the llvm-commits mailing list