r366617 - Disallow most calling convention attributes on PS4

Sunil Srivastava via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 19 14:38:34 PDT 2019


Author: ssrivastava
Date: Fri Jul 19 14:38:34 2019
New Revision: 366617

URL: http://llvm.org/viewvc/llvm-project?rev=366617&view=rev
Log:
Disallow most calling convention attributes on PS4

PS4 now only allows "cdecl", and its equivalent on PS4, "sysv_abi".

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

Added:
    cfe/trunk/test/Sema/no_callconv.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/Basic/Targets/OSTargets.h
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/LambdaExpr.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=366617&r1=366616&r2=366617&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jul 19 14:38:34 2019
@@ -2966,6 +2966,7 @@ def warn_cconv_unsupported : Warning<
   "|on builtin function"
   "}1">,
   InGroup<IgnoredAttributes>;
+def error_cconv_unsupported : Error<warn_cconv_unsupported.Text>;
 def err_cconv_knr : Error<
   "function with no prototype cannot use the %0 calling convention">;
 def warn_cconv_knr : Warning<

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=366617&r1=366616&r2=366617&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Jul 19 14:38:34 2019
@@ -1268,6 +1268,7 @@ public:
     CCCR_OK,
     CCCR_Warning,
     CCCR_Ignore,
+    CCCR_Error,
   };
 
   /// Determines whether a given calling convention is valid for the

Modified: cfe/trunk/lib/Basic/Targets/OSTargets.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/OSTargets.h?rev=366617&r1=366616&r2=366617&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/OSTargets.h (original)
+++ cfe/trunk/lib/Basic/Targets/OSTargets.h Fri Jul 19 14:38:34 2019
@@ -561,6 +561,10 @@ public:
       break;
     }
   }
+  TargetInfo::CallingConvCheckResult
+  checkCallingConvention(CallingConv CC) const override {
+    return (CC == CC_C) ? TargetInfo::CCCR_OK : TargetInfo::CCCR_Error;
+  }
 };
 
 // RTEMS Target

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=366617&r1=366616&r2=366617&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Jul 19 14:38:34 2019
@@ -4668,6 +4668,11 @@ bool Sema::CheckCallingConvAttr(const Pa
     CC = CC_C;
     break;
 
+  case TargetInfo::CCCR_Error:
+    Diag(Attrs.getLoc(), diag::error_cconv_unsupported)
+        << Attrs << (int)CallingConventionIgnoredReason::ForThisTarget;
+    break;
+
   case TargetInfo::CCCR_Warning: {
     Diag(Attrs.getLoc(), diag::warn_cconv_unsupported)
         << Attrs << (int)CallingConventionIgnoredReason::ForThisTarget;

Added: cfe/trunk/test/Sema/no_callconv.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/no_callconv.cpp?rev=366617&view=auto
==============================================================================
--- cfe/trunk/test/Sema/no_callconv.cpp (added)
+++ cfe/trunk/test/Sema/no_callconv.cpp Fri Jul 19 14:38:34 2019
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 %s -triple x86_64-scei-ps4 -DPS4 -fsyntax-only -verify
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -fsyntax-only -verify
+
+#ifdef PS4
+
+// PS4 does not support these.
+void __vectorcall func_vc() {} // expected-error {{'__vectorcall' calling convention is not supported for this target}}
+void __regcall func_rc() {} // expected-error {{'__regcall' calling convention is not supported for this target}}
+void __attribute__((vectorcall)) funcA() {} // expected-error {{'vectorcall' calling convention is not supported for this target}}
+void __attribute__((regcall)) funcB() {} // expected-error {{'regcall' calling convention is not supported for this target}}
+void __attribute__((ms_abi)) funcH() {} // expected-error {{'ms_abi' calling convention is not supported for this target}}
+void __attribute__((intel_ocl_bicc)) funcJ() {} // expected-error {{'intel_ocl_bicc' calling convention is not supported for this target}}
+void __attribute__((swiftcall)) funcK() {} // expected-error {{'swiftcall' calling convention is not supported for this target}}
+void __attribute__((pascal)) funcG() {} // expected-error {{'pascal' calling convention is not supported for this target}}
+void __attribute__((preserve_most)) funcL() {} // expected-error {{'preserve_most' calling convention is not supported for this target}}
+void __attribute__((preserve_all)) funcM() {} // expected-error {{'preserve_all' calling convention is not supported for this target}}
+void __attribute__((stdcall)) funcD() {} // expected-error {{'stdcall' calling convention is not supported for this target}}
+void __attribute__((fastcall)) funcE() {} // expected-error {{'fastcall' calling convention is not supported for this target}}
+void __attribute__((thiscall)) funcF() {} // expected-error {{'thiscall' calling convention is not supported for this target}}
+#else
+
+void __vectorcall func_vc() {}
+void __regcall func_rc() {}
+void __attribute__((vectorcall)) funcA() {}
+void __attribute__((regcall)) funcB() {}
+void __attribute__((ms_abi)) funcH() {}
+void __attribute__((intel_ocl_bicc)) funcJ() {}
+void __attribute__((swiftcall)) funcK() {}
+void __attribute__((preserve_most)) funcL() {}
+void __attribute__((preserve_all)) funcM() {}
+
+// Same function with different calling conventions. Error with a note pointing to the last decl.
+void __attribute__((preserve_all)) funcR(); // expected-note {{previous declaration is here}}
+void __attribute__((preserve_most)) funcR(); // expected-error {{function declared 'preserve_most' here was previously declared 'preserve_all'}}
+
+void __attribute__((pascal)) funcG() {} // expected-warning {{'pascal' calling convention is not supported for this target}}
+
+void __attribute__((stdcall)) funcD() {} // expected-warning {{'stdcall' calling convention is not supported for this target}}
+void __attribute__((fastcall)) funcE() {} // expected-warning {{'fastcall' calling convention is not supported for this target}}
+void __attribute__((thiscall)) funcF() {} // expected-warning {{'thiscall' calling convention is not supported for this target}}
+#endif
+
+void __attribute__((sysv_abi)) funcI() {}
+void __attribute__((cdecl)) funcC() {}

Modified: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/LambdaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/LambdaExpr.cpp?rev=366617&r1=366616&r2=366617&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/LambdaExpr.cpp (original)
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTests/LambdaExpr.cpp Fri Jul 19 14:38:34 2019
@@ -86,6 +86,8 @@ TEST(RecursiveASTVisitor, VisitsLambdaEx
 }
 
 TEST(RecursiveASTVisitor, VisitsAttributedLambdaExpr) {
+  if (llvm::Triple(llvm::sys::getDefaultTargetTriple()).isPS4())
+    return; // PS4 does not support fastcall.
   LambdaExprVisitor Visitor;
   Visitor.ExpectMatch("", 1, 12);
   EXPECT_TRUE(Visitor.runOver(




More information about the cfe-commits mailing list