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

2016-02-10 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL260373: Fix assertion "Chunk.Kind == 
DeclaratorChunk::Function" with attributed type. (authored by dzobnin).

Changed prior to commit:
  http://reviews.llvm.org/D15373?vs=45179=47434#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D15373

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

Index: cfe/trunk/test/CodeGen/pr25786.c
===
--- cfe/trunk/test/CodeGen/pr25786.c
+++ cfe/trunk/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: cfe/trunk/test/Sema/pr25786.c
===
--- cfe/trunk/test/Sema/pr25786.c
+++ cfe/trunk/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: cfe/trunk/lib/Sema/SemaType.cpp
===
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -5370,6 +5370,7 @@
   struct FunctionTypeUnwrapper {
 enum WrapKind {
   Desugar,
+  Attributed,
   Parens,
   Pointer,
   BlockPointer,
@@ -5402,6 +5403,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) {
@@ -5450,6 +5454,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: cfe/trunk/test/CodeGen/pr25786.c
===
--- cfe/trunk/test/CodeGen/pr25786.c
+++ cfe/trunk/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: cfe/trunk/test/Sema/pr25786.c
===
--- cfe/trunk/test/Sema/pr25786.c
+++ cfe/trunk/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: cfe/trunk/lib/Sema/SemaType.cpp
===
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -5370,6 +5370,7 @@
   struct FunctionTypeUnwrapper {
 enum WrapKind {
   Desugar,
+  Attributed,
   Parens,
   Pointer,
   BlockPointer,
@@ -5402,6 +5403,9 @@
 } else if (isa(Ty)) {
   T = cast(Ty)->getPointeeType();
   Stack.push_back(Reference);
+} else if (isa(Ty)) {
+  T = 

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-02-09 Thread Reid Kleckner via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

Thanks, lgtm!


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-19 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

This looks correct to me, but my knowledge of type attributes isn't strong 
enough to officially sign off, so please wait for @rnk or @rsmith to take a 
look as well.


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.

2016-01-14 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

In http://reviews.llvm.org/D15373#315457, @a.makarov wrote:

> 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.


I tend to agree with @rnk on this -- it is a shame to lose that syntactic 
information in the AST representation (for instance, tools may wish to detect 
the presence of that attribute in the source to perform different analyses on 
the type). Even if it is semantically ignored, it is still something the user 
wrote. For instance, this means we cannot round-trip the user's source code 
through pretty printing, despite the code not being ill-formed.



Comment at: test/CodeGen/adding_defaulted_cc_attr_to_type.c:1
@@ +1,2 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -verify -emit-llvm -o - %s 
| FileCheck %s
+

Can you drop the svn props on the file? Our convention is to not rely on props, 
but instead save the file with UNIX line endings.


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 = 

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

2015-12-09 Thread Reid Kleckner via cfe-commits
rnk added a subscriber: rnk.


Comment at: include/clang/Sema/Sema.h:2938
@@ -2937,2 +2937,3 @@
   bool CheckRegparmAttr(const AttributeList , unsigned );
+  bool getCCFromAttr(const AttributeList , CallingConv );
   bool CheckCallingConvAttr(const AttributeList , CallingConv , 

Rather than adding this extra entry point, I think it would be simpler to 
extend CheckCallingConvAttr to return whatever extra info we need.

Besides, this new entry point also emits diagnostics, and it has a name that 
suggests it will not emit diagnostics.


Comment at: lib/Sema/SemaType.cpp:5866
@@ -5865,3 +5865,3 @@
   CallingConv CC;
   if (S.CheckCallingConvAttr(attr, CC))
 return true;

Right, we've already done the work that you are doing down below. We should 
just get what we needed to know out of here and pass it on.


Comment at: lib/Sema/SemaType.cpp:5925-5926
@@ +5924,4 @@
+  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)

At a high level, why would you want to not create an AttributedType here? That 
seems desirable, the user wrote the type attribute in the source, and that 
should be reflected in the AST sugar.

If adding this sugar causes assertions later, then the bug must be somewhere 
else.


Comment at: test/CodeGen/adding_defaulted_attr_to_type.c:5
@@ +4,2 @@
+
+// CHECK: @f = common global void (i32)*

You can add more tests. I noticed this crashes for me:
  void (__attribute__((regparm(2), stdcall)) foo)(int);
That seems like a good one to add.

You can also rerun the test with i686-unknown-linux-gnu and #ifdefs to see that 
we accept the convention as desired on 32-bit.




http://reviews.llvm.org/D15373



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