]> granicus.if.org Git - clang/commitdiff
Give builtins and alloc/dealloc operators the default calling convention.
authorErich Keane <erich.keane@intel.com>
Mon, 4 Mar 2019 14:54:52 +0000 (14:54 +0000)
committerErich Keane <erich.keane@intel.com>
Mon, 4 Mar 2019 14:54:52 +0000 (14:54 +0000)
On SPIR targets, the default calling convention is SpirFunction.
However, operator new/delete and builtins were being created with CC_C.
The result is indirect references to new/delete (or builtins that are permitted
to be called indirectly have a mismatched type, as well as questionable codegen
in some cases.

This patch sets both to the default calling convention, so that it
properly matches the calling convention of the target.

Differential Revision: https://reviews.llvm.org/D58844

Change-Id: I52065bb00bc2655945caea8f29c409ba1e0ac24a

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

lib/AST/ASTContext.cpp
lib/Sema/SemaExprCXX.cpp
test/CodeGenCXX/builtin-calling-conv.cpp [new file with mode: 0644]

index aa4bd4139c0e754d3620e50bbeca0d6c9943e482..41efa951cb4d509af9cccfddbfb56f164019de16 100644 (file)
@@ -9565,10 +9565,12 @@ QualType ASTContext::GetBuiltinType(unsigned Id,
   assert((TypeStr[0] != '.' || TypeStr[1] == 0) &&
          "'.' should only occur at end of builtin type list!");
 
-  FunctionType::ExtInfo EI(CC_C);
+  bool Variadic = (TypeStr[0] == '.');
+
+  FunctionType::ExtInfo EI(
+      getDefaultCallingConvention(Variadic, /*IsCXXMethod=*/false));
   if (BuiltinInfo.isNoReturn(Id)) EI = EI.withNoReturn(true);
 
-  bool Variadic = (TypeStr[0] == '.');
 
   // We really shouldn't be making a no-proto type here.
   if (ArgTypes.empty() && Variadic && !getLangOpts().CPlusPlus)
index 512e256d45805e329451aa4c638c36636b953982..6e66b5e7020a28e5916541fdb244182a5da0f32b 100644 (file)
@@ -2795,7 +2795,8 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name,
     }
   }
 
-  FunctionProtoType::ExtProtoInfo EPI;
+  FunctionProtoType::ExtProtoInfo EPI(Context.getDefaultCallingConvention(
+      /*IsVariadic=*/false, /*IsCXXMethod=*/false));
 
   QualType BadAllocType;
   bool HasBadAllocExceptionSpec
diff --git a/test/CodeGenCXX/builtin-calling-conv.cpp b/test/CodeGenCXX/builtin-calling-conv.cpp
new file mode 100644 (file)
index 0000000..6fdeca0
--- /dev/null
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple x86_64-linux-pc -DREDECL -emit-llvm %s -o - | FileCheck %s -check-prefix LINUX
+// RUN: %clang_cc1 -triple spir-unknown-unknown -DREDECL -DSPIR -emit-llvm %s -o - | FileCheck %s -check-prefix SPIR
+// RUN: %clang_cc1 -triple x86_64-linux-pc -emit-llvm %s -o - | FileCheck %s -check-prefix LINUX
+// RUN: %clang_cc1 -triple spir-unknown-unknown -DSPIR -emit-llvm %s -o - | FileCheck %s -check-prefix SPIR
+
+#ifdef REDECL
+namespace std {
+#ifdef SPIR
+using size_t = unsigned int;
+#else
+using size_t = unsigned long;
+#endif // SPIR
+} // namespace std
+
+float __builtin_atan2f(float, float);
+void *operator new(std::size_t);
+#endif // REDECL
+
+void foo();
+
+void user() {
+  int i;
+  ::operator new(5);
+  (void)__builtin_atan2f(1.1, 2.2);
+  foo();
+}
+
+// LINUX: define void @_Z4userv()
+// LINUX: call i8* @_Znwm
+// LINUX: call float @atan2f
+// LINUX: call void @_Z3foov
+// LINUX: declare noalias i8* @_Znwm(i64)
+// LINUX: declare float @atan2f(float, float)
+// LINUX: declare void @_Z3foov()
+
+// SPIR: define spir_func void @_Z4userv()
+// SPIR: call spir_func i8* @_Znwj
+// SPIR: call spir_func float @atan2f
+// SPIR: call spir_func void @_Z3foov
+// SPIR: declare spir_func noalias i8* @_Znwj(i32)
+// SPIR: declare spir_func float @atan2f(float, float)
+// SPIR: declare spir_func void @_Z3foov()