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

Duncan Sands baldrick at free.fr
Thu Nov 22 01:34:24 PST 2007


Author: baldrick
Date: Thu Nov 22 03:34:20 2007
New Revision: 44269

URL: http://llvm.org/viewvc/llvm-project?rev=44269&view=rev
Log:
Struct return functions cannot be const/pure because
they write the result via the sret pointer argument.

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=44269&r1=44268&r2=44269&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-types.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-types.cpp Thu Nov 22 03:34:20 2007
@@ -1019,29 +1019,35 @@
   TARGET_ADJUST_LLVM_CC(CallingConv, type);
 #endif
 
-  // Compute attributes for return type (and function attributes)
+  // Compute attributes for return type (and function attributes).
   ParamAttrsVector Attrs;
   uint16_t RAttributes = ParamAttr::None;
 
   int flags = flags_from_decl_or_type(decl ? decl : type);
 
-  // Check for 'const' function attribute
+  // Check for 'const' function attribute.
   if (flags & ECF_CONST)
-    RAttributes |= ParamAttr::Const;
+    // Since they write the return value through a pointer,
+    // 'sret' functions cannot be 'const'.
+    if (!ABIConverter.isStructReturn())
+      RAttributes |= ParamAttr::Const;
 
-  // Check for 'noreturn' function attribute
+  // Check for 'noreturn' function attribute.
   if (flags & ECF_NORETURN)
     RAttributes |= ParamAttr::NoReturn;
 
-  // Check for 'nounwind' function attribute
+  // Check for 'nounwind' function attribute.
   if (flags & ECF_NOTHROW)
     RAttributes |= ParamAttr::NoUnwind;
 
-  // Check for 'pure' function attribute
+  // Check for 'pure' function attribute.
   if (flags & ECF_PURE)
-    RAttributes |= ParamAttr::Pure;
+    // Since they write the return value through a pointer,
+    // 'sret' functions cannot be 'pure'.
+    if (!ABIConverter.isStructReturn())
+      RAttributes |= ParamAttr::Pure;
 
-  // Compute whether the result needs to be zext or sext'd
+  // Compute whether the result needs to be zext or sext'd.
   if (isa<IntegerType>(RetTy.get())) {
     tree ResultTy = TREE_TYPE(type);  
     if (TREE_INT_CST_LOW(TYPE_SIZE(ResultTy)) < INT_TYPE_SIZE) {





More information about the llvm-commits mailing list