Re: [PATCH] D21228: Deprecated (legacy) string literal conversion to 'char *' causes strange overloading resolution

2016-07-19 Thread Alexander Makarov via cfe-commits
a.makarov added a comment.

Richard, thank you very much! =)


https://reviews.llvm.org/D21228



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21228: Deprecated (legacy) string literal conversion to 'char *' causes strange overloading resolution

2016-07-18 Thread Alexander Makarov via cfe-commits
a.makarov added a comment.

Friendly ping!


https://reviews.llvm.org/D21228



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21228: Deprecated (legacy) string literal conversion to 'char *' causes strange overloading resolution

2016-07-04 Thread Alexander Makarov via cfe-commits
a.makarov added a comment.

Ping.


http://reviews.llvm.org/D21228



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21228: Deprecated (legacy) string literal conversion to 'char *' causes strange overloading resolution

2016-06-27 Thread Alexander Makarov via cfe-commits
a.makarov added a reviewer: rnk.
a.makarov added a comment.

Reid, please, take a look.


http://reviews.llvm.org/D21228



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21228: Deprecated (legacy) string literal conversion to 'char *' causes strange overloading resolution

2016-06-20 Thread Alexander Makarov via cfe-commits
a.makarov added a comment.

Ping.


http://reviews.llvm.org/D21228



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D21228: Deprecated (legacy) string literal conversion to 'char *' causes strange overloading resolution

2016-06-10 Thread Alexander Makarov via cfe-commits
a.makarov created this revision.
a.makarov added a reviewer: rsmith.
a.makarov added a subscriber: cfe-commits.

It's a patch for PR28050. Seems like overloading resolution wipes out the first 
standard conversion sequence (before user-defined conversion) in case of 
deprecated string literal conversion.

http://reviews.llvm.org/D21228

Files:
  include/clang/Sema/Overload.h
  lib/Sema/SemaOverload.cpp
  test/SemaCXX/pr28050.cpp

Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -1199,7 +1199,6 @@
   case OR_Success:
   case OR_Deleted:
 ICS.setUserDefined();
-ICS.UserDefined.Before.setAsIdentityConversion();
 // C++ [over.ics.user]p4:
 //   A conversion of an expression of class type to the same class
 //   type is given Exact Match rank, and a conversion of an
@@ -4540,7 +4539,6 @@
   return ICS;
 }
 
-ICS.UserDefined.Before.setAsIdentityConversion();
 ICS.UserDefined.After.ReferenceBinding = true;
 ICS.UserDefined.After.IsLvalueReference = !isRValRef;
 ICS.UserDefined.After.BindsToFunctionLvalue = false;
Index: include/clang/Sema/Overload.h
===
--- include/clang/Sema/Overload.h
+++ include/clang/Sema/Overload.h
@@ -428,8 +428,11 @@
 };
 
 ImplicitConversionSequence()
-  : ConversionKind(Uninitialized), StdInitializerListElement(false)
-{}
+: ConversionKind(Uninitialized), StdInitializerListElement(false) {
+  Standard.First = ICK_Identity;
+  Standard.Second = ICK_Identity;
+  Standard.Third = ICK_Identity;
+}
 ~ImplicitConversionSequence() {
   destruct();
 }
Index: test/SemaCXX/pr28050.cpp
===
--- test/SemaCXX/pr28050.cpp
+++ test/SemaCXX/pr28050.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -std=c++11 %s -fsyntax-only
+//
+// expected-no-diagnostics
+
+class A {
+public:
+  A(char *s) {}
+  A(A &&) = delete;
+};
+
+int main() { A a("OK"); }


Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -1199,7 +1199,6 @@
   case OR_Success:
   case OR_Deleted:
 ICS.setUserDefined();
-ICS.UserDefined.Before.setAsIdentityConversion();
 // C++ [over.ics.user]p4:
 //   A conversion of an expression of class type to the same class
 //   type is given Exact Match rank, and a conversion of an
@@ -4540,7 +4539,6 @@
   return ICS;
 }
 
-ICS.UserDefined.Before.setAsIdentityConversion();
 ICS.UserDefined.After.ReferenceBinding = true;
 ICS.UserDefined.After.IsLvalueReference = !isRValRef;
 ICS.UserDefined.After.BindsToFunctionLvalue = false;
Index: include/clang/Sema/Overload.h
===
--- include/clang/Sema/Overload.h
+++ include/clang/Sema/Overload.h
@@ -428,8 +428,11 @@
 };
 
 ImplicitConversionSequence()
-  : ConversionKind(Uninitialized), StdInitializerListElement(false)
-{}
+: ConversionKind(Uninitialized), StdInitializerListElement(false) {
+  Standard.First = ICK_Identity;
+  Standard.Second = ICK_Identity;
+  Standard.Third = ICK_Identity;
+}
 ~ImplicitConversionSequence() {
   destruct();
 }
Index: test/SemaCXX/pr28050.cpp
===
--- test/SemaCXX/pr28050.cpp
+++ test/SemaCXX/pr28050.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -std=c++11 %s -fsyntax-only
+//
+// expected-no-diagnostics
+
+class A {
+public:
+  A(char *s) {}
+  A(A &&) = delete;
+};
+
+int main() { A a("OK"); }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20171: Support for MSVS default calling convention options (/Gd, /Gz, /Gv, /Gr)

2016-05-16 Thread Alexander Makarov via cfe-commits
a.makarov updated this revision to Diff 57344.
a.makarov added a comment.

I've updated the patch. Please take a look.


http://reviews.llvm.org/D20171

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Basic/LangOptions.h
  include/clang/Driver/CC1Options.td
  include/clang/Driver/CLCompatOptions.td
  lib/AST/ASTContext.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/default_calling_conv.cpp

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3954,7 +3954,7 @@
   }
 
   if (Args.hasFlag(options::OPT_mrtd, options::OPT_mno_rtd, false))
-CmdArgs.push_back("-mrtd");
+CmdArgs.push_back("-fdefault-calling-conv=stdcall");
 
   if (shouldUseFramePointer(Args, getToolChain().getTriple()))
 CmdArgs.push_back("-mdisable-fp-elim");
@@ -6140,6 +6140,15 @@
   CmdArgs.push_back("-fms-memptr-rep=virtual");
   }
 
+  if (Args.getLastArg(options::OPT__SLASH_Gd))
+ CmdArgs.push_back("-fdefault-calling-conv=cdecl");
+  else if (Args.getLastArg(options::OPT__SLASH_Gr))
+ CmdArgs.push_back("-fdefault-calling-conv=fastcall");
+  else if (Args.getLastArg(options::OPT__SLASH_Gz))
+ CmdArgs.push_back("-fdefault-calling-conv=stdcall");
+  else if (Args.getLastArg(options::OPT__SLASH_Gv))
+ CmdArgs.push_back("-fdefault-calling-conv=vectorcall");
+
   if (Arg *A = Args.getLastArg(options::OPT_vtordisp_mode_EQ))
 A->render(Args, CmdArgs);
 
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8605,8 +8605,25 @@
   if (IsCXXMethod)
 return ABI->getDefaultMethodCallConv(IsVariadic);
 
-  if (LangOpts.MRTD && !IsVariadic) return CC_X86StdCall;
-
+  switch (LangOpts.getDefaultCallingConv()) {
+  case LangOptions::DCC_None:
+break;
+  case LangOptions::DCC_CDecl:
+return CC_C;
+  case LangOptions::DCC_FastCall:
+if (getTargetInfo().hasFeature("sse2"))
+  return CC_X86FastCall;
+break;
+  case LangOptions::DCC_StdCall:
+if (!IsVariadic)
+  return CC_X86StdCall;
+break;
+  case LangOptions::DCC_VectorCall:
+// __vectorcall cannot be applied to variadic functions.
+if (!IsVariadic)
+  return CC_X86VectorCall;
+break;
+  }
   return Target->getDefaultCallingConv(TargetInfo::CCMT_Unknown);
 }
 
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3895,11 +3895,12 @@
 
 // This convention is not valid for the target. Use the default function or
 // method calling convention.
-TargetInfo::CallingConvMethodType MT = TargetInfo::CCMT_Unknown;
-if (FD)
-  MT = FD->isCXXInstanceMember() ? TargetInfo::CCMT_Member : 
-TargetInfo::CCMT_NonMember;
-CC = TI.getDefaultCallingConv(MT);
+bool IsCXXMethod = false, IsVariadic = false;
+if (FD) {
+  IsCXXMethod = FD->isCXXInstanceMember();
+  IsVariadic = FD->isVariadic();
+}
+CC = Context.getDefaultCallingConvention(IsVariadic, IsCXXMethod);
   }
 
   attr.setProcessingCache((unsigned) CC);
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1772,7 +1772,6 @@
   Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align);
   Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant);
   Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math);
-  Opts.MRTD = Args.hasArg(OPT_mrtd);
   Opts.HexagonQdsp6Compat = Args.hasArg(OPT_mqdsp6_compat);
   Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map);
   Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype);
@@ -1849,6 +1848,49 @@
 Opts.setMSPointerToMemberRepresentationMethod(InheritanceModel);
   }
 
+  // Check for MS default calling conventions being specified.
+  if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
+LangOptions::DefaultCallingConvention DefaultCC =
+llvm::StringSwitch(
+A->getValue())
+.Case("cdecl", LangOptions::DCC_CDecl)
+.Case("fastcall", LangOptions::DCC_FastCall)
+.Case("stdcall", LangOptions::DCC_StdCall)
+.Case("vectorcall", LangOptions::DCC_VectorCall)
+.Default(LangOptions::DCC_None);
+if (DefaultCC == LangOptions::DCC_None)
+  Diags.Report(diag::err_drv_invalid_value)
+  << "-fdefault-calling-conv=" << A->getValue();
+
+llvm::Triple T(TargetOpts.Triple);
+llvm::Triple::ArchType Arch = T.getArch();
+bool emitError = (DefaultCC == LangOptions::DCC_FastCall ||
+  DefaultCC == LangOptions::DCC_StdCall) &&
+ Arch != llvm::Triple::x86;
+

Re: [PATCH] D20171: Support for MSVS default calling convention options (/Gd, /Gz, /Gv, /Gr)

2016-05-12 Thread Alexander Makarov via cfe-commits
a.makarov updated this revision to Diff 57071.
a.makarov added a comment.

Renamed option 'DefaultMSCallingConv' into 'DefaultCallingConv' and enum 
'DefaultMSCallingConvention' into 'DefaultCallingConvention'.


http://reviews.llvm.org/D20171

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Basic/LangOptions.h
  include/clang/Driver/CC1Options.td
  include/clang/Driver/CLCompatOptions.td
  include/clang/Driver/Options.td
  lib/AST/ASTContext.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/default_calling_conv.cpp

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6140,6 +6140,15 @@
   CmdArgs.push_back("-fms-memptr-rep=virtual");
   }
 
+  if (Args.getLastArg(options::OPT__SLASH_Gd))
+ CmdArgs.push_back("-fdefault-calling-conv=cdecl");
+  else if (Args.getLastArg(options::OPT__SLASH_Gr))
+ CmdArgs.push_back("-fdefault-calling-conv=fastcall");
+  else if (Args.getLastArg(options::OPT__SLASH_Gz))
+ CmdArgs.push_back("-fdefault-calling-conv=stdcall");
+  else if (Args.getLastArg(options::OPT__SLASH_Gv))
+ CmdArgs.push_back("-fdefault-calling-conv=vectorcall");
+
   if (Arg *A = Args.getLastArg(options::OPT_vtordisp_mode_EQ))
 A->render(Args, CmdArgs);
 
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8605,8 +8605,25 @@
   if (IsCXXMethod)
 return ABI->getDefaultMethodCallConv(IsVariadic);
 
-  if (LangOpts.MRTD && !IsVariadic) return CC_X86StdCall;
-
+  switch (LangOpts.getDefaultCallingConv()) {
+  case LangOptions::DCC_None:
+break;
+  case LangOptions::DCC_CDecl:
+return CC_C;
+  case LangOptions::DCC_FastCall:
+if (getTargetInfo().hasFeature("sse2"))
+  return CC_X86FastCall;
+break;
+  case LangOptions::DCC_StdCall:
+if (!IsVariadic)
+  return CC_X86StdCall;
+break;
+  case LangOptions::DCC_VectorCall:
+// __vectorcall cannot be applied to variadic functions.
+if (!IsVariadic)
+  return CC_X86VectorCall;
+break;
+  }
   return Target->getDefaultCallingConv(TargetInfo::CCMT_Unknown);
 }
 
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3895,11 +3895,12 @@
 
 // This convention is not valid for the target. Use the default function or
 // method calling convention.
-TargetInfo::CallingConvMethodType MT = TargetInfo::CCMT_Unknown;
-if (FD)
-  MT = FD->isCXXInstanceMember() ? TargetInfo::CCMT_Member : 
-TargetInfo::CCMT_NonMember;
-CC = TI.getDefaultCallingConv(MT);
+bool isCXXMethod = false, isVariadic = false;
+if (FD) {
+  isCXXMethod = FD->isCXXInstanceMember();
+  isVariadic = FD->isVariadic();
+}
+CC = Context.getDefaultCallingConvention(isVariadic, isCXXMethod);
   }
 
   attr.setProcessingCache((unsigned) CC);
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1772,7 +1772,6 @@
   Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align);
   Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant);
   Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math);
-  Opts.MRTD = Args.hasArg(OPT_mrtd);
   Opts.HexagonQdsp6Compat = Args.hasArg(OPT_mqdsp6_compat);
   Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map);
   Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype);
@@ -1849,6 +1848,34 @@
 Opts.setMSPointerToMemberRepresentationMethod(InheritanceModel);
   }
 
+  // Check for MS default calling conventions being specified.
+  if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
+LangOptions::DefaultCallingConvention DefaultCC =
+llvm::StringSwitch(
+A->getValue())
+.Case("cdecl", LangOptions::DCC_CDecl)
+.Case("fastcall", LangOptions::DCC_FastCall)
+.Case("stdcall", LangOptions::DCC_StdCall)
+.Case("vectorcall", LangOptions::DCC_VectorCall)
+.Default(LangOptions::DCC_None);
+if (DefaultCC == LangOptions::DCC_None)
+  Diags.Report(diag::err_drv_invalid_value)
+  << "-fdefault-calling-conv=" << A->getValue();
+
+llvm::Triple T(TargetOpts.Triple);
+llvm::Triple::ArchType Arch = T.getArch();
+bool emitError = (DefaultCC == LangOptions::DCC_FastCall ||
+  DefaultCC == LangOptions::DCC_StdCall) &&
+ Arch != llvm::Triple::x86;
+emitError |= DefaultCC == LangOptions::DCC_VectorCall &&
+ !(Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64);
+if (emitError)
+  

Re: [PATCH] D20171: Support for MSVS default calling convention options (/Gd, /Gz, /Gv, /Gr)

2016-05-12 Thread Alexander Makarov via cfe-commits
a.makarov updated this revision to Diff 57062.
a.makarov added a comment.

Thanks for the review! I've updated the patch, please take a look.
Modifications:

- the dependency from MS compatibility mode is removed;
- the option is renamed into '-fdefault-calling-conv' (since it's not in MS 
compatibility mode);
- the '-mrtd' option is now an alias for '-fdefault-calling-conv=stdcall';
- 'stdcall' is now ignored for variadic functions;
- since 'vectorcall' requires SSE2 or higher 
(https://msdn.microsoft.com/en-us/library/dn375768.aspx) the necessary check is 
added


http://reviews.llvm.org/D20171

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Basic/LangOptions.h
  include/clang/Driver/CC1Options.td
  include/clang/Driver/CLCompatOptions.td
  include/clang/Driver/Options.td
  lib/AST/ASTContext.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/default_calling_conv.cpp

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6140,6 +6140,15 @@
   CmdArgs.push_back("-fms-memptr-rep=virtual");
   }
 
+  if (Args.getLastArg(options::OPT__SLASH_Gd))
+ CmdArgs.push_back("-fdefault-calling-conv=cdecl");
+  else if (Args.getLastArg(options::OPT__SLASH_Gr))
+ CmdArgs.push_back("-fdefault-calling-conv=fastcall");
+  else if (Args.getLastArg(options::OPT__SLASH_Gz))
+ CmdArgs.push_back("-fdefault-calling-conv=stdcall");
+  else if (Args.getLastArg(options::OPT__SLASH_Gv))
+ CmdArgs.push_back("-fdefault-calling-conv=vectorcall");
+
   if (Arg *A = Args.getLastArg(options::OPT_vtordisp_mode_EQ))
 A->render(Args, CmdArgs);
 
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8605,8 +8605,25 @@
   if (IsCXXMethod)
 return ABI->getDefaultMethodCallConv(IsVariadic);
 
-  if (LangOpts.MRTD && !IsVariadic) return CC_X86StdCall;
-
+  switch (LangOpts.getDefaultMSCallingConv()) {
+  case LangOptions::DCC_None:
+break;
+  case LangOptions::DCC_CDecl:
+return CC_C;
+  case LangOptions::DCC_FastCall:
+if (getTargetInfo().hasFeature("sse2"))
+  return CC_X86FastCall;
+break;
+  case LangOptions::DCC_StdCall:
+if (!IsVariadic)
+  return CC_X86StdCall;
+break;
+  case LangOptions::DCC_VectorCall:
+// __vectorcall cannot be applied to variadic functions.
+if (!IsVariadic)
+  return CC_X86VectorCall;
+break;
+  }
   return Target->getDefaultCallingConv(TargetInfo::CCMT_Unknown);
 }
 
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3895,11 +3895,12 @@
 
 // This convention is not valid for the target. Use the default function or
 // method calling convention.
-TargetInfo::CallingConvMethodType MT = TargetInfo::CCMT_Unknown;
-if (FD)
-  MT = FD->isCXXInstanceMember() ? TargetInfo::CCMT_Member : 
-TargetInfo::CCMT_NonMember;
-CC = TI.getDefaultCallingConv(MT);
+bool isCXXMethod = false, isVariadic = false;
+if (FD) {
+  isCXXMethod = FD->isCXXInstanceMember();
+  isVariadic = FD->isVariadic();
+}
+CC = Context.getDefaultCallingConvention(isVariadic, isCXXMethod);
   }
 
   attr.setProcessingCache((unsigned) CC);
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1772,7 +1772,6 @@
   Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align);
   Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant);
   Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math);
-  Opts.MRTD = Args.hasArg(OPT_mrtd);
   Opts.HexagonQdsp6Compat = Args.hasArg(OPT_mqdsp6_compat);
   Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map);
   Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype);
@@ -1849,6 +1848,34 @@
 Opts.setMSPointerToMemberRepresentationMethod(InheritanceModel);
   }
 
+  // Check for MS default calling conventions being specified.
+  if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
+LangOptions::DefaultMSCallingConvention DefaultCC =
+llvm::StringSwitch(
+A->getValue())
+.Case("cdecl", LangOptions::DCC_CDecl)
+.Case("fastcall", LangOptions::DCC_FastCall)
+.Case("stdcall", LangOptions::DCC_StdCall)
+.Case("vectorcall", LangOptions::DCC_VectorCall)
+.Default(LangOptions::DCC_None);
+if (DefaultCC == LangOptions::DCC_None)
+  Diags.Report(diag::err_drv_invalid_value)
+  << "-fdefault-calling-conv=" << A->getValue();
+
+llvm::Triple T(TargetOpts.Triple);
+llvm::Triple::ArchType Arch = 

Re: [PATCH] D20171: Support for MSVS default calling convention options (/Gd, /Gz, /Gv, /Gr)

2016-05-12 Thread Alexander Makarov via cfe-commits
a.makarov added inline comments.


Comment at: lib/AST/ASTContext.cpp:8616-8619
@@ +8615,6 @@
+  return CC_C;
+case LangOptions::DCC_FastCall:
+  return CC_X86FastCall;
+case LangOptions::DCC_StdCall:
+  return CC_X86StdCall;
+case LangOptions::DCC_VectorCall:

rnk wrote:
> Neither fastcall nor stdcall can be applied to variadic functions.
As I've got from MSDN, **vectorcall** and stdcall cannot be applied to vararg 
functions. Are you sure about fastcall?)


http://reviews.llvm.org/D20171



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20171: Support for MSVS default calling convention options (/Gd, /Gz, /Gv, /Gr)

2016-05-12 Thread Alexander Makarov via cfe-commits
a.makarov added inline comments.


Comment at: lib/AST/ASTContext.cpp:8604-8606
@@ -8603,5 +8603,5 @@
 bool IsCXXMethod) const {
   // Pass through to the C++ ABI object
   if (IsCXXMethod)
 return ABI->getDefaultMethodCallConv(IsVariadic);
 

majnemer wrote:
> rnk wrote:
> > majnemer wrote:
> > > Do these flags not have an effect on methods?
> > Nope:
> > https://msdn.microsoft.com/en-us/library/46t77ak2.aspx
> > "for all functions except C++ member functions..."
> Yeah, that's what the documentation says.  But do they really have no effect? 
> :)
Yes, I've checked. Member functions are not affected =)


http://reviews.llvm.org/D20171



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20171: Support for MSVS default calling convention options (/Gd, /Gz, /Gv, /Gr)

2016-05-11 Thread Alexander Makarov via cfe-commits
a.makarov created this revision.
a.makarov added a reviewer: rnk.
a.makarov added a subscriber: cfe-commits.

Patch for bug #27711

http://reviews.llvm.org/D20171

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Basic/LangOptions.h
  include/clang/Driver/CC1Options.td
  include/clang/Driver/CLCompatOptions.td
  lib/AST/ASTContext.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/default_calling_conv.cpp

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6140,6 +6140,15 @@
   CmdArgs.push_back("-fms-memptr-rep=virtual");
   }
 
+  if (Args.getLastArg(options::OPT__SLASH_Gd))
+ CmdArgs.push_back("-fms-default-calling-conv=cdecl");
+  else if (Args.getLastArg(options::OPT__SLASH_Gr))
+ CmdArgs.push_back("-fms-default-calling-conv=fastcall");
+  else if (Args.getLastArg(options::OPT__SLASH_Gz))
+ CmdArgs.push_back("-fms-default-calling-conv=stdcall");
+  else if (Args.getLastArg(options::OPT__SLASH_Gv))
+ CmdArgs.push_back("-fms-default-calling-conv=vectorcall");
+
   if (Arg *A = Args.getLastArg(options::OPT_vtordisp_mode_EQ))
 A->render(Args, CmdArgs);
 
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8607,7 +8607,25 @@
 
   if (LangOpts.MRTD && !IsVariadic) return CC_X86StdCall;
 
-  return Target->getDefaultCallingConv(TargetInfo::CCMT_Unknown);
+  if (LangOpts.MSVCCompat) {
+switch (LangOpts.getDefaultMSCallingConv()) {
+case LangOptions::DCC_None:
+  return Target->getDefaultCallingConv(TargetInfo::CCMT_Unknown);
+case LangOptions::DCC_CDecl:
+  return CC_C;
+case LangOptions::DCC_FastCall:
+  return CC_X86FastCall;
+case LangOptions::DCC_StdCall:
+  return CC_X86StdCall;
+case LangOptions::DCC_VectorCall:
+  // __vectorcall cannot be applied to variadic functions.
+  if (!IsVariadic)
+return CC_X86VectorCall;
+  else
+return Target->getDefaultCallingConv(TargetInfo::CCMT_Unknown);
+}
+  } else
+return Target->getDefaultCallingConv(TargetInfo::CCMT_Unknown);
 }
 
 bool ASTContext::isNearlyEmpty(const CXXRecordDecl *RD) const {
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3895,11 +3895,12 @@
 
 // This convention is not valid for the target. Use the default function or
 // method calling convention.
-TargetInfo::CallingConvMethodType MT = TargetInfo::CCMT_Unknown;
-if (FD)
-  MT = FD->isCXXInstanceMember() ? TargetInfo::CCMT_Member : 
-TargetInfo::CCMT_NonMember;
-CC = TI.getDefaultCallingConv(MT);
+bool isCXXMethod = false, isVariadic = false;
+if (FD) {
+  isCXXMethod = FD->isCXXInstanceMember();
+  isVariadic = FD->isVariadic();
+}
+CC = Context.getDefaultCallingConvention(isVariadic, isCXXMethod);
   }
 
   attr.setProcessingCache((unsigned) CC);
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1849,6 +1849,34 @@
 Opts.setMSPointerToMemberRepresentationMethod(InheritanceModel);
   }
 
+  // Check for MS default calling conventions being specified.
+  if (Arg *A = Args.getLastArg(OPT_fms_ms_default_calling_conv_EQ)) {
+LangOptions::DefaultMSCallingConvention DefaultCC =
+llvm::StringSwitch(
+A->getValue())
+.Case("cdecl", LangOptions::DCC_CDecl)
+.Case("fastcall", LangOptions::DCC_FastCall)
+.Case("stdcall", LangOptions::DCC_StdCall)
+.Case("vectorcall", LangOptions::DCC_VectorCall)
+.Default(LangOptions::DCC_None);
+if (DefaultCC == LangOptions::DCC_None)
+  Diags.Report(diag::err_drv_invalid_value)
+  << "-fms-default-calling-conv" << A->getValue();
+
+llvm::Triple T(TargetOpts.Triple);
+llvm::Triple::ArchType Arch = T.getArch();
+bool emitError = (DefaultCC == LangOptions::DCC_FastCall ||
+  DefaultCC == LangOptions::DCC_StdCall) &&
+ Arch != llvm::Triple::x86;
+emitError |= DefaultCC == LangOptions::DCC_VectorCall &&
+ !(Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64);
+if (emitError)
+  Diags.Report(diag::err_drv_argument_not_allowed_with)
+  << A->getSpelling() << T.getTriple();
+else
+  Opts.setDefaultMSCallingConv(DefaultCC);
+  }
+
   // Check if -fopenmp is specified.
   Opts.OpenMP = Args.hasArg(options::OPT_fopenmp);
   Opts.OpenMPUseTLS =
Index: include/clang/Driver/CC1Options.td
===
--- 

Re: [PATCH] D15373: Fix for bug 25786 - Assertion "Chunk.Kind == DeclaratorChunk::Function" failed with regparm attribute.

2016-02-09 Thread Alexander Makarov via cfe-commits
a.makarov added a comment.

Richard, Reid, please take a look.


http://reviews.llvm.org/D15373



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15373: Fix for bug 25786 - Assertion "Chunk.Kind == DeclaratorChunk::Function" failed with regparm attribute.

2016-01-26 Thread Alexander Makarov via cfe-commits
a.makarov added a comment.

Ping


http://reviews.llvm.org/D15373



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15373: Fix for bug 25786 - Assertion "Chunk.Kind == DeclaratorChunk::Function" failed with regparm attribute.

2016-01-18 Thread Alexander Makarov via cfe-commits
a.makarov updated this revision to Diff 45179.
a.makarov added a comment.

Oops, forgot to drop svn properties. Done. Sorry for noise.


http://reviews.llvm.org/D15373

Files:
  lib/Sema/SemaType.cpp
  test/CodeGen/pr25786.c
  test/Sema/pr25786.c

Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -5369,6 +5369,7 @@
   struct FunctionTypeUnwrapper {
 enum WrapKind {
   Desugar,
+  Attributed,
   Parens,
   Pointer,
   BlockPointer,
@@ -5401,6 +5402,9 @@
 } else if (isa(Ty)) {
   T = cast(Ty)->getPointeeType();
   Stack.push_back(Reference);
+} else if (isa(Ty)) {
+  T = cast(Ty)->getEquivalentType();
+  Stack.push_back(Attributed);
 } else {
   const Type *DTy = Ty->getUnqualifiedDesugaredType();
   if (Ty == DTy) {
@@ -5449,6 +5453,9 @@
 // information.
 return wrap(C, Old->getUnqualifiedDesugaredType(), I);
 
+  case Attributed:
+return wrap(C, cast(Old)->getEquivalentType(), I);
+
   case Parens: {
 QualType New = wrap(C, cast(Old)->getInnerType(), I);
 return C.getParenType(New);
Index: test/CodeGen/pr25786.c
===
--- test/CodeGen/pr25786.c
+++ test/CodeGen/pr25786.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -emit-llvm -o - %s | 
FileCheck %s --check-prefix=CHECK-OK
+
+void (__attribute__((regparm(3), stdcall)) *pf) ();
+void (__attribute__((regparm(2), stdcall)) foo)(int a) {
+}
+// CHECK: @pf = common global void (...)* null
+// CHECK: define void @foo(i32 %a)
+
+// CHECK-OK: @pf = common global void (...)* null
+// CHECK-OK: define x86_stdcallcc void @foo(i32 inreg %a)
Index: test/Sema/pr25786.c
===
--- test/Sema/pr25786.c
+++ test/Sema/pr25786.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -DTEST -fsyntax-only 
-verify %s
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fsyntax-only -verify %s
+
+#if TEST
+void (__attribute__((regparm(3), stdcall)) *pf) (); //expected-warning 
{{calling convention 'stdcall' ignored for this target}}
+void (__attribute__((regparm(2), stdcall)) foo)(int a) { //expected-warning 
{{calling convention 'stdcall' ignored for this target}}
+}
+#else
+//expected-no-diagnostics
+void (__attribute__((regparm(3), stdcall)) *pf) ();
+void (__attribute__((regparm(2), stdcall)) foo)(int a) {}
+#endif


Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -5369,6 +5369,7 @@
   struct FunctionTypeUnwrapper {
 enum WrapKind {
   Desugar,
+  Attributed,
   Parens,
   Pointer,
   BlockPointer,
@@ -5401,6 +5402,9 @@
 } else if (isa(Ty)) {
   T = cast(Ty)->getPointeeType();
   Stack.push_back(Reference);
+} else if (isa(Ty)) {
+  T = cast(Ty)->getEquivalentType();
+  Stack.push_back(Attributed);
 } else {
   const Type *DTy = Ty->getUnqualifiedDesugaredType();
   if (Ty == DTy) {
@@ -5449,6 +5453,9 @@
 // information.
 return wrap(C, Old->getUnqualifiedDesugaredType(), I);
 
+  case Attributed:
+return wrap(C, cast(Old)->getEquivalentType(), I);
+
   case Parens: {
 QualType New = wrap(C, cast(Old)->getInnerType(), I);
 return C.getParenType(New);
Index: test/CodeGen/pr25786.c
===
--- test/CodeGen/pr25786.c
+++ test/CodeGen/pr25786.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-OK
+
+void (__attribute__((regparm(3), stdcall)) *pf) ();
+void (__attribute__((regparm(2), stdcall)) foo)(int a) {
+}
+// CHECK: @pf = common global void (...)* null
+// CHECK: define void @foo(i32 %a)
+
+// CHECK-OK: @pf = common global void (...)* null
+// CHECK-OK: define x86_stdcallcc void @foo(i32 inreg %a)
Index: test/Sema/pr25786.c
===
--- test/Sema/pr25786.c
+++ test/Sema/pr25786.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -DTEST -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fsyntax-only -verify %s
+
+#if TEST
+void (__attribute__((regparm(3), stdcall)) *pf) (); //expected-warning {{calling convention 'stdcall' ignored for this target}}
+void (__attribute__((regparm(2), stdcall)) foo)(int a) { //expected-warning {{calling convention 'stdcall' ignored for this target}}
+}
+#else
+//expected-no-diagnostics
+void 

Re: [PATCH] D15373: Fix for bug 25786 - Assertion "Chunk.Kind == DeclaratorChunk::Function" failed with regparm attribute.

2016-01-18 Thread Alexander Makarov via cfe-commits
a.makarov updated this revision to Diff 45178.
a.makarov added a comment.

I've updated the patch. Now, I've updated the function unwrapping mechanism to 
work properly with AttributedType.
Please, re-review the patch.


http://reviews.llvm.org/D15373

Files:
  lib/Sema/SemaType.cpp
  test/CodeGen/pr25786.c
  test/Sema/pr25786.c

Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -5369,6 +5369,7 @@
   struct FunctionTypeUnwrapper {
 enum WrapKind {
   Desugar,
+  Attributed,
   Parens,
   Pointer,
   BlockPointer,
@@ -5401,6 +5402,9 @@
 } else if (isa(Ty)) {
   T = cast(Ty)->getPointeeType();
   Stack.push_back(Reference);
+} else if (isa(Ty)) {
+  T = cast(Ty)->getEquivalentType();
+  Stack.push_back(Attributed);
 } else {
   const Type *DTy = Ty->getUnqualifiedDesugaredType();
   if (Ty == DTy) {
@@ -5449,6 +5453,9 @@
 // information.
 return wrap(C, Old->getUnqualifiedDesugaredType(), I);
 
+  case Attributed:
+return wrap(C, cast(Old)->getEquivalentType(), I);
+
   case Parens: {
 QualType New = wrap(C, cast(Old)->getInnerType(), I);
 return C.getParenType(New);
Index: test/CodeGen/pr25786.c
===
--- test/CodeGen/pr25786.c
+++ test/CodeGen/pr25786.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -emit-llvm -o - %s | 
FileCheck %s --check-prefix=CHECK-OK
+
+void (__attribute__((regparm(3), stdcall)) *pf) ();
+void (__attribute__((regparm(2), stdcall)) foo)(int a) {
+}
+// CHECK: @pf = common global void (...)* null
+// CHECK: define void @foo(i32 %a)
+
+// CHECK-OK: @pf = common global void (...)* null
+// CHECK-OK: define x86_stdcallcc void @foo(i32 inreg %a)
Index: test/Sema/pr25786.c
===
--- test/Sema/pr25786.c
+++ test/Sema/pr25786.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -DTEST -fsyntax-only 
-verify %s
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fsyntax-only -verify %s
+
+#if TEST
+void (__attribute__((regparm(3), stdcall)) *pf) (); //expected-warning 
{{calling convention 'stdcall' ignored for this target}}
+void (__attribute__((regparm(2), stdcall)) foo)(int a) { //expected-warning 
{{calling convention 'stdcall' ignored for this target}}
+}
+#else
+//expected-no-diagnostics
+void (__attribute__((regparm(3), stdcall)) *pf) ();
+void (__attribute__((regparm(2), stdcall)) foo)(int a) {}
+#endif


Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -5369,6 +5369,7 @@
   struct FunctionTypeUnwrapper {
 enum WrapKind {
   Desugar,
+  Attributed,
   Parens,
   Pointer,
   BlockPointer,
@@ -5401,6 +5402,9 @@
 } else if (isa(Ty)) {
   T = cast(Ty)->getPointeeType();
   Stack.push_back(Reference);
+} else if (isa(Ty)) {
+  T = cast(Ty)->getEquivalentType();
+  Stack.push_back(Attributed);
 } else {
   const Type *DTy = Ty->getUnqualifiedDesugaredType();
   if (Ty == DTy) {
@@ -5449,6 +5453,9 @@
 // information.
 return wrap(C, Old->getUnqualifiedDesugaredType(), I);
 
+  case Attributed:
+return wrap(C, cast(Old)->getEquivalentType(), I);
+
   case Parens: {
 QualType New = wrap(C, cast(Old)->getInnerType(), I);
 return C.getParenType(New);
Index: test/CodeGen/pr25786.c
===
--- test/CodeGen/pr25786.c
+++ test/CodeGen/pr25786.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-OK
+
+void (__attribute__((regparm(3), stdcall)) *pf) ();
+void (__attribute__((regparm(2), stdcall)) foo)(int a) {
+}
+// CHECK: @pf = common global void (...)* null
+// CHECK: define void @foo(i32 %a)
+
+// CHECK-OK: @pf = common global void (...)* null
+// CHECK-OK: define x86_stdcallcc void @foo(i32 inreg %a)
Index: test/Sema/pr25786.c
===
--- test/Sema/pr25786.c
+++ test/Sema/pr25786.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -DTEST -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fsyntax-only -verify %s
+
+#if TEST
+void (__attribute__((regparm(3), stdcall)) *pf) (); //expected-warning {{calling convention 'stdcall' ignored for this target}}
+void (__attribute__((regparm(2), stdcall)) foo)(int a) { //expected-warning {{calling convention 

Re: [PATCH] D15373: Fix for bug 25786 - Assertion "Chunk.Kind == DeclaratorChunk::Function" failed with regparm attribute.

2016-01-15 Thread Alexander Makarov via cfe-commits
a.makarov added a comment.

Thanks for review! I've understood your idea, I'm working on updating the patch.


http://reviews.llvm.org/D15373



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15373: Fix for bug 25786 - Assertion "Chunk.Kind == DeclaratorChunk::Function" failed with regparm attribute.

2016-01-14 Thread Alexander Makarov via cfe-commits
a.makarov added a comment.

Ping


http://reviews.llvm.org/D15373



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15373: Fix for bug 25786 - Assertion "Chunk.Kind == DeclaratorChunk::Function" failed with regparm attribute.

2015-12-22 Thread Alexander Makarov via cfe-commits
a.makarov updated this revision to Diff 43442.
a.makarov added a comment.

Actual updated patch. Sorry for noise.


http://reviews.llvm.org/D15373

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/adding_defaulted_cc_attr_to_type.c
  test/Sema/callingconv.c

Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -5856,7 +5856,8 @@
 
   // Otherwise, a calling convention.
   CallingConv CC;
-  if (S.CheckCallingConvAttr(attr, CC))
+  bool isDefaulted = false;
+  if (S.CheckCallingConvAttr(attr, CC, /*FD*/nullptr, ))
 return true;
 
   const FunctionType *fn = unwrapped.get();
@@ -5906,7 +5907,11 @@
   FunctionType::ExtInfo EI = unwrapped.get()->getExtInfo().withCallingConv(CC);
   QualType Equivalent =
   unwrapped.wrap(S, S.Context.adjustFunctionType(unwrapped.get(), EI));
-  type = S.Context.getAttributedType(CCAttrKind, type, Equivalent);
+  // If calling convention was defaulted, we should not create attributed type
+  // with this attribute.
+  if (!isDefaulted)
+type = S.Context.getAttributedType(CCAttrKind, type, Equivalent);
+
   return true;
 }
 
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3701,8 +3701,8 @@
   }
 }
 
-bool Sema::CheckCallingConvAttr(const AttributeList , CallingConv , 
-const FunctionDecl *FD) {
+bool Sema::CheckCallingConvAttr(const AttributeList , CallingConv ,
+const FunctionDecl *FD, bool *Defaulted) {
   if (attr.isInvalid())
 return true;
 
@@ -3750,11 +3750,16 @@
   default: llvm_unreachable("unexpected attribute kind");
   }
 
+  if (Defaulted)
+*Defaulted = false;
   const TargetInfo  = Context.getTargetInfo();
   TargetInfo::CallingConvCheckResult A = TI.checkCallingConvention(CC);
   if (A != TargetInfo::CCCR_OK) {
-if (A == TargetInfo::CCCR_Warning)
+if (A == TargetInfo::CCCR_Warning) {
   Diag(attr.getLoc(), diag::warn_cconv_ignored) << attr.getName();
+  if (Defaulted)
+*Defaulted = true;
+}
 
 // This convention is not valid for the target. Use the default function or
 // method calling convention.
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -2937,8 +2937,9 @@
   bool isValidPointerAttrType(QualType T, bool RefOkay = false);
 
   bool CheckRegparmAttr(const AttributeList , unsigned );
-  bool CheckCallingConvAttr(const AttributeList , CallingConv , 
-const FunctionDecl *FD = nullptr);
+  bool CheckCallingConvAttr(const AttributeList , CallingConv ,
+const FunctionDecl *FD = nullptr,
+bool *Defaulted = nullptr);
   bool CheckNoReturnAttr(const AttributeList );
   bool checkStringLiteralArgumentAttr(const AttributeList ,
   unsigned ArgNum, StringRef ,
Index: test/CodeGen/adding_defaulted_cc_attr_to_type.c
===
--- test/CodeGen/adding_defaulted_cc_attr_to_type.c
+++ test/CodeGen/adding_defaulted_cc_attr_to_type.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -verify -emit-llvm -o - %s | FileCheck %s
+
+void (__attribute__ ((regparm (3), stdcall )) *f) (int); // expected-warning {{calling convention 'stdcall' ignored for this target}}
+
+// CHECK: @f = common global void (i32)*
+
+void (__attribute__((regparm(2), stdcall)) foo) () { // expected-warning {{calling convention 'stdcall' ignored for this target}}
+}
+
+// CHECK: define void @foo(){{.*}}
Index: test/Sema/callingconv.c
===
--- test/Sema/callingconv.c
+++ test/Sema/callingconv.c
@@ -66,3 +66,6 @@
 void __attribute__((stdcall)) typedef_fun(int x) { } // expected-error {{function declared 'stdcall' here was previously declared without calling convention}}
 
 struct type_test {} __attribute__((stdcall));  // expected-warning {{'stdcall' attribute only applies to functions and methods}}
+
+
+void (__attribute__ ((regparm (3), stdcall("abacaba") )) *test_ignored) (int); // expected-error {{'stdcall' attribute takes no arguments}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15373: Fix for bug 25786 - Assertion "Chunk.Kind == DeclaratorChunk::Function" failed with regparm attribute.

2015-12-22 Thread Alexander Makarov via cfe-commits
a.makarov updated this revision to Diff 43440.
a.makarov added a comment.

I've updated the patch. Please, re-review it again.
About creating attributed type - I think we shouldn't create it if we ignored 
specified CC attribute. Ignoring specified CC attribute (and emitting the 
warning, of course) leads to substituting it by default; calling convention, 
substituted by default, is the same situation like there is no CC attribute 
specified for chosen function. Thus, from this point of view, we should not 
create AttributedType.


http://reviews.llvm.org/D15373

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/adding_defaulted_attr_to_type.c
  test/Sema/callingconv.c

Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -5913,7 +5913,19 @@
   FunctionType::ExtInfo EI = unwrapped.get()->getExtInfo().withCallingConv(CC);
   QualType Equivalent =
   unwrapped.wrap(S, S.Context.adjustFunctionType(unwrapped.get(), EI));
-  type = S.Context.getAttributedType(CCAttrKind, type, Equivalent);
+
+  // We should add attribute specifier to type only if we didn't subsitute
+  // 'default' calling convention instead of the one provided by the attribute.
+  CallingConv RawCC;
+  bool RecognizedAttr = S.getCCFromAttr(attr, RawCC);
+  assert(!RecognizedAttr &&
+ "Somehow ill-formed calling convention attribute reached here!");
+  TargetInfo::CallingConvCheckResult CCResult =
+  S.Context.getTargetInfo().checkCallingConvention(RawCC);
+  // If calling convention is available (CCCR_OK) or default (CCCR_Ignored), add
+  // it to type.
+  if (CCResult != TargetInfo::CCCR_Warning)
+type = S.Context.getAttributedType(CCAttrKind, type, Equivalent);
   return true;
 }
 
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3701,8 +3701,11 @@
   }
 }
 
-bool Sema::CheckCallingConvAttr(const AttributeList , CallingConv , 
-const FunctionDecl *FD) {
+/// This function simply dispatches passed attribute to corresponding
+/// calling convention.
+/// If attribute is ill-formed, it returns 'true' and makes marks attribute as
+/// invalid.
+bool Sema::getCCFromAttr(const AttributeList , CallingConv ) {
   if (attr.isInvalid())
 return true;
 
@@ -3714,19 +3717,31 @@
 
   // TODO: diagnose uses of these conventions on the wrong target.
   switch (attr.getKind()) {
-  case AttributeList::AT_CDecl: CC = CC_C; break;
-  case AttributeList::AT_FastCall: CC = CC_X86FastCall; break;
-  case AttributeList::AT_StdCall: CC = CC_X86StdCall; break;
-  case AttributeList::AT_ThisCall: CC = CC_X86ThisCall; break;
-  case AttributeList::AT_Pascal: CC = CC_X86Pascal; break;
-  case AttributeList::AT_VectorCall: CC = CC_X86VectorCall; break;
+  case AttributeList::AT_CDecl:
+CC = CC_C;
+break;
+  case AttributeList::AT_FastCall:
+CC = CC_X86FastCall;
+break;
+  case AttributeList::AT_StdCall:
+CC = CC_X86StdCall;
+break;
+  case AttributeList::AT_ThisCall:
+CC = CC_X86ThisCall;
+break;
+  case AttributeList::AT_Pascal:
+CC = CC_X86Pascal;
+break;
+  case AttributeList::AT_VectorCall:
+CC = CC_X86VectorCall;
+break;
   case AttributeList::AT_MSABI:
-CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_C :
- CC_X86_64Win64;
+CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_C
+   : CC_X86_64Win64;
 break;
   case AttributeList::AT_SysVABI:
-CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_X86_64SysV :
- CC_C;
+CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_X86_64SysV
+   : CC_C;
 break;
   case AttributeList::AT_Pcs: {
 StringRef StrRef;
@@ -3741,13 +3756,27 @@
   CC = CC_AAPCS_VFP;
   break;
 }
-
 attr.setInvalid();
 Diag(attr.getLoc(), diag::err_invalid_pcs);
 return true;
   }
-  case AttributeList::AT_IntelOclBicc: CC = CC_IntelOclBicc; break;
-  default: llvm_unreachable("unexpected attribute kind");
+  case AttributeList::AT_IntelOclBicc:
+CC = CC_IntelOclBicc;
+break;
+  default:
+llvm_unreachable("unexpected attribute kind");
+  }
+  return false;
+}
+
+bool Sema::CheckCallingConvAttr(const AttributeList , CallingConv , 
+const FunctionDecl *FD) {
+  if (attr.isInvalid())
+return true;
+
+  if (getCCFromAttr(attr, CC)) {
+assert(attr.isInvalid() && "Error occured but attribute is not invalid!");
+return true;
   }
 
   const TargetInfo  = Context.getTargetInfo();
Index: include/clang/Sema/Sema.h

[PATCH] D15373: Fix for bug 25786 - Assertion "Chunk.Kind == DeclaratorChunk::Function" failed with regparm attribute.

2015-12-09 Thread Alexander Makarov via cfe-commits
a.makarov created this revision.
a.makarov added reviewers: aaron.ballman, rsmith.
a.makarov added a subscriber: cfe-commits.
Herald added subscribers: rengolin, aemerson.

This patch is to avoid attaching the calling convention attribute to the result 
type if this attribute was ignored and calling convention was substituted by 
default.

http://reviews.llvm.org/D15373

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/adding_defaulted_attr_to_type.c
  test/Sema/callingconv.c

Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -5913,7 +5913,19 @@
   FunctionType::ExtInfo EI = unwrapped.get()->getExtInfo().withCallingConv(CC);
   QualType Equivalent =
   unwrapped.wrap(S, S.Context.adjustFunctionType(unwrapped.get(), EI));
-  type = S.Context.getAttributedType(CCAttrKind, type, Equivalent);
+
+  // We should add attribute specifier to type only if we didn't subsitute
+  // 'default' calling convention instead of the one provided by the attribute.
+  CallingConv RawCC;
+  bool RecognizedAttr = S.getCCFromAttr(attr, RawCC);
+  assert(!RecognizedAttr &&
+ "Somehow ill-formed calling convention attribute reached here!");
+  TargetInfo::CallingConvCheckResult CCResult =
+  S.Context.getTargetInfo().checkCallingConvention(RawCC);
+  // If calling convention is available (CCCR_OK) or default (CCCR_Ignored), add
+  // it to type.
+  if (CCResult != TargetInfo::CCCR_Warning)
+type = S.Context.getAttributedType(CCAttrKind, type, Equivalent);
   return true;
 }
 
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3701,8 +3701,11 @@
   }
 }
 
-bool Sema::CheckCallingConvAttr(const AttributeList , CallingConv , 
-const FunctionDecl *FD) {
+/// This function simply dispatches passed attribute to corresponding
+/// calling convention.
+/// If attribute is ill-formed, it returns 'true' and makes marks attribute as
+/// invalid.
+bool Sema::getCCFromAttr(const AttributeList , CallingConv ) {
   if (attr.isInvalid())
 return true;
 
@@ -3714,19 +3717,31 @@
 
   // TODO: diagnose uses of these conventions on the wrong target.
   switch (attr.getKind()) {
-  case AttributeList::AT_CDecl: CC = CC_C; break;
-  case AttributeList::AT_FastCall: CC = CC_X86FastCall; break;
-  case AttributeList::AT_StdCall: CC = CC_X86StdCall; break;
-  case AttributeList::AT_ThisCall: CC = CC_X86ThisCall; break;
-  case AttributeList::AT_Pascal: CC = CC_X86Pascal; break;
-  case AttributeList::AT_VectorCall: CC = CC_X86VectorCall; break;
+  case AttributeList::AT_CDecl:
+CC = CC_C;
+break;
+  case AttributeList::AT_FastCall:
+CC = CC_X86FastCall;
+break;
+  case AttributeList::AT_StdCall:
+CC = CC_X86StdCall;
+break;
+  case AttributeList::AT_ThisCall:
+CC = CC_X86ThisCall;
+break;
+  case AttributeList::AT_Pascal:
+CC = CC_X86Pascal;
+break;
+  case AttributeList::AT_VectorCall:
+CC = CC_X86VectorCall;
+break;
   case AttributeList::AT_MSABI:
-CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_C :
- CC_X86_64Win64;
+CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_C
+   : CC_X86_64Win64;
 break;
   case AttributeList::AT_SysVABI:
-CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_X86_64SysV :
- CC_C;
+CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_X86_64SysV
+   : CC_C;
 break;
   case AttributeList::AT_Pcs: {
 StringRef StrRef;
@@ -3741,13 +3756,27 @@
   CC = CC_AAPCS_VFP;
   break;
 }
-
 attr.setInvalid();
 Diag(attr.getLoc(), diag::err_invalid_pcs);
 return true;
   }
-  case AttributeList::AT_IntelOclBicc: CC = CC_IntelOclBicc; break;
-  default: llvm_unreachable("unexpected attribute kind");
+  case AttributeList::AT_IntelOclBicc:
+CC = CC_IntelOclBicc;
+break;
+  default:
+llvm_unreachable("unexpected attribute kind");
+  }
+  return false;
+}
+
+bool Sema::CheckCallingConvAttr(const AttributeList , CallingConv , 
+const FunctionDecl *FD) {
+  if (attr.isInvalid())
+return true;
+
+  if (getCCFromAttr(attr, CC)) {
+assert(attr.isInvalid() && "Error occured but attribute is not invalid!");
+return true;
   }
 
   const TargetInfo  = Context.getTargetInfo();
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -2935,6 +2935,7 @@
   bool isValidPointerAttrType(QualType T, bool RefOkay =