]> granicus.if.org Git - clang/commitdiff
Set sext/zext on function result.
authorDaniel Dunbar <daniel@zuster.org>
Fri, 5 Sep 2008 00:57:45 +0000 (00:57 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 5 Sep 2008 00:57:45 +0000 (00:57 +0000)
 - <rdar://problem/6156739>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55815 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGen/function-attributes.c [new file with mode: 0644]

index 4c12011c4be3870bf705d54dca99e89f03eed048..373027bbff4247ab30ed11eea807159f46f6f5a9 100644 (file)
@@ -207,14 +207,21 @@ SetFunctionAttributesFromTypes(const Decl *FD,
     FuncAttrs |= llvm::ParamAttr::NoReturn;
 
   llvm::SmallVector<llvm::ParamAttrsWithIndex, 8> ParamAttrList;
-  if (FuncAttrs)
-    ParamAttrList.push_back(llvm::ParamAttrsWithIndex::get(0, FuncAttrs));
   // Note that there is parallel code in CodeGenFunction::EmitCallExpr
-  bool AggregateReturn = CodeGenFunction::hasAggregateLLVMType(ArgTypes[0]);
-  if (AggregateReturn)
+  unsigned increment = 1;
+  if (CodeGenFunction::hasAggregateLLVMType(ArgTypes[0])) {
     ParamAttrList.push_back(
         llvm::ParamAttrsWithIndex::get(1, llvm::ParamAttr::StructRet));
-  unsigned increment = AggregateReturn ? 2 : 1;
+    ++increment;
+  } else if (ArgTypes[0]->isPromotableIntegerType()) {
+    if (ArgTypes[0]->isSignedIntegerType()) {
+      FuncAttrs |= llvm::ParamAttr::SExt;
+    } else if (ArgTypes[0]->isUnsignedIntegerType()) {
+      FuncAttrs |= llvm::ParamAttr::ZExt;
+    }
+  }
+  if (FuncAttrs)
+    ParamAttrList.push_back(llvm::ParamAttrsWithIndex::get(0, FuncAttrs));
   for (llvm::SmallVector<QualType, 8>::const_iterator i = ArgTypes.begin() + 1,
          e = ArgTypes.end(); i != e; ++i, ++increment) {
     QualType ParamType = *i;
diff --git a/test/CodeGen/function-attributes.c b/test/CodeGen/function-attributes.c
new file mode 100644 (file)
index 0000000..bb482a0
--- /dev/null
@@ -0,0 +1,22 @@
+// RUN: clang -emit-llvm -o %t.clang.ll %s &&
+// RUN: %llvmgcc -c --emit-llvm -o - %s | llvm-dis -f -o %t.gcc.ll &&
+// RUN: grep "define" %t.clang.ll | sort > %t.clang.defs &&
+// RUN: grep "define" %t.gcc.ll | sort > %t.gcc.defs &&
+// RUN: diff %t.clang.defs %t.gcc.defs
+
+signed char f0(int x) { return x; }
+
+unsigned char f1(int x) { return x; }
+
+void f2(signed char x) { }
+
+void f3(unsigned char x) { }
+
+signed short f4(int x) { return x; }
+
+unsigned short f5(int x) { return x; }
+
+void f6(signed short x) { }
+
+void f7(unsigned short x) { }
+