Author: erichkeane Date: Mon Jun 3 11:36:33 2019 New Revision: 362435 URL: http://llvm.org/viewvc/llvm-project?rev=362435&view=rev Log: Make NoThrow FunctionLike, make FunctionLike include references, fix prettyprint
__declspec(nothrow) should work on function pointers as well as function references, so this changes it to FunctionLike. Additionally, FunctionLike needed to be modified to permit function references. Finally, the TypePrinter didn't properly print the NoThrow exception specifier, so make sure we get that right as well. Modified: cfe/trunk/include/clang/AST/Type.h cfe/trunk/include/clang/Basic/Attr.td cfe/trunk/lib/AST/DeclBase.cpp cfe/trunk/lib/AST/TypePrinter.cpp cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test cfe/trunk/test/SemaCXX/nothrow-vs-exception-specs.cpp Modified: cfe/trunk/include/clang/AST/Type.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=362435&r1=362434&r2=362435&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/Type.h (original) +++ cfe/trunk/include/clang/AST/Type.h Mon Jun 3 11:36:33 2019 @@ -1962,6 +1962,7 @@ public: bool isLValueReferenceType() const; bool isRValueReferenceType() const; bool isFunctionPointerType() const; + bool isFunctionReferenceType() const; bool isMemberPointerType() const; bool isMemberFunctionPointerType() const; bool isMemberDataPointerType() const; @@ -6372,6 +6373,13 @@ inline bool Type::isFunctionPointerType( return T->getPointeeType()->isFunctionType(); else return false; +} + +inline bool Type::isFunctionReferenceType() const { + if (const auto *T = getAs<ReferenceType>()) + return T->getPointeeType()->isFunctionType(); + else + return false; } inline bool Type::isMemberPointerType() const { Modified: cfe/trunk/include/clang/Basic/Attr.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=362435&r1=362434&r2=362435&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/Attr.td (original) +++ cfe/trunk/include/clang/Basic/Attr.td Mon Jun 3 11:36:33 2019 @@ -1657,7 +1657,7 @@ def NoStackProtector : InheritableAttr { def NoThrow : InheritableAttr { let Spellings = [GCC<"nothrow">, Declspec<"nothrow">]; - let Subjects = SubjectList<[Function]>; + let Subjects = SubjectList<[FunctionLike]>; let Documentation = [NoThrowDocs]; } Modified: cfe/trunk/lib/AST/DeclBase.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=362435&r1=362434&r2=362435&view=diff ============================================================================== --- cfe/trunk/lib/AST/DeclBase.cpp (original) +++ cfe/trunk/lib/AST/DeclBase.cpp Mon Jun 3 11:36:33 2019 @@ -957,6 +957,8 @@ const FunctionType *Decl::getFunctionTyp if (Ty->isFunctionPointerType()) Ty = Ty->getAs<PointerType>()->getPointeeType(); + else if (Ty->isFunctionReferenceType()) + Ty = Ty->getAs<ReferenceType>()->getPointeeType(); else if (BlocksToo && Ty->isBlockPointerType()) Ty = Ty->getAs<BlockPointerType>()->getPointeeType(); Modified: cfe/trunk/lib/AST/TypePrinter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=362435&r1=362434&r2=362435&view=diff ============================================================================== --- cfe/trunk/lib/AST/TypePrinter.cpp (original) +++ cfe/trunk/lib/AST/TypePrinter.cpp Mon Jun 3 11:36:33 2019 @@ -734,6 +734,8 @@ FunctionProtoType::printExceptionSpecifi OS << getExceptionType(I).stream(Policy); } OS << ')'; + } else if (EST_NoThrow == getExceptionSpecType()) { + OS << " __attribute__((nothrow))"; } else if (isNoexceptExceptionSpec(getExceptionSpecType())) { OS << " noexcept"; // FIXME:Is it useful to print out the expression for a non-dependent Modified: cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test?rev=362435&r1=362434&r2=362435&view=diff ============================================================================== --- cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test (original) +++ cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test Mon Jun 3 11:36:33 2019 @@ -86,7 +86,7 @@ // CHECK-NEXT: NoSplitStack (SubjectMatchRule_function) // CHECK-NEXT: NoStackProtector (SubjectMatchRule_function) // CHECK-NEXT: NoThreadSafetyAnalysis (SubjectMatchRule_function) -// CHECK-NEXT: NoThrow (SubjectMatchRule_function) +// CHECK-NEXT: NoThrow (SubjectMatchRule_hasType_functionType) // CHECK-NEXT: NotTailCalled (SubjectMatchRule_function) // CHECK-NEXT: OSConsumed (SubjectMatchRule_variable_is_parameter) // CHECK-NEXT: OSReturnsNotRetained (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, SubjectMatchRule_variable_is_parameter) Modified: cfe/trunk/test/SemaCXX/nothrow-vs-exception-specs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nothrow-vs-exception-specs.cpp?rev=362435&r1=362434&r2=362435&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/nothrow-vs-exception-specs.cpp (original) +++ cfe/trunk/test/SemaCXX/nothrow-vs-exception-specs.cpp Mon Jun 3 11:36:33 2019 @@ -88,3 +88,17 @@ public: void foo() {} }; } + +namespace FuncPointerReferenceConverts +void FuncToBeRefed(); + +#ifndef CPP17 +// expected-error@+6{{target exception specification is not superset of source}} +// expected-error@+6{{target exception specification is not superset of source}} +#else +// expected-error@+3{{non-const lvalue reference to type 'void () __attribute__((nothrow))' cannot bind to a value of unrelated type 'void ()'}} +// expected-error@+3{{cannot initialize a variable of type 'void (*)() __attribute__((nothrow))' with an lvalue of type 'void ()': different exception specifications}} +#endif +__declspec(nothrow) void (&FuncRef)() = FuncToBeRefed; +__declspec(nothrow) void (*FuncPtr)() = FuncToBeRefed; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits