[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)
a-tarasyuk wrote: ping https://github.com/llvm/llvm-project/pull/96228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)
@@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s a-tarasyuk wrote: @shafik could you review the latest changes? thanks https://github.com/llvm/llvm-project/pull/96228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] use const references for function parameters in operator== and operator!= overloads in Redeclarable.h (PR #92963)
a-tarasyuk wrote: @kparzysz could you review this PR? https://github.com/llvm/llvm-project/pull/92963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] improve RewriteModernObjC code quality by using const reference for function parameters (PR #93252)
a-tarasyuk wrote: @cor3ntin could you review this pr? thanks https://github.com/llvm/llvm-project/pull/93252 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] use const references for function parameters in operator== and operator!= overloads in Redeclarable.h (PR #92963)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/92963 >From 700619984cef3c84c3f818330731f3eb70c6ae82 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 21 May 2024 22:56:06 +0300 Subject: [PATCH] [Clang][NFC] use const references for function parameters in operator== and operator!= overloads in Redeclarable.h --- clang/include/clang/AST/Redeclarable.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/AST/Redeclarable.h b/clang/include/clang/AST/Redeclarable.h index 091bb886f2d49..74ccd74ed60d6 100644 --- a/clang/include/clang/AST/Redeclarable.h +++ b/clang/include/clang/AST/Redeclarable.h @@ -281,10 +281,10 @@ class Redeclarable { return tmp; } -friend bool operator==(redecl_iterator x, redecl_iterator y) { +friend bool operator==(const redecl_iterator &x, const redecl_iterator &y) { return x.Current == y.Current; } -friend bool operator!=(redecl_iterator x, redecl_iterator y) { +friend bool operator!=(const redecl_iterator &x, const redecl_iterator &y) { return x.Current != y.Current; } }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] use const references for function parameters in operator== and operator!= overloads in Redeclarable.h (PR #92963)
https://github.com/a-tarasyuk edited https://github.com/llvm/llvm-project/pull/92963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] use const references for function parameters in operator== and operator!= overloads in Redeclarable.h (PR #92963)
a-tarasyuk wrote: @zyn0217 Thanks. I've added [NCF] to the commit/title. https://github.com/llvm/llvm-project/pull/92963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] improve RewriteModernObjC code quality by using const reference for function parameters (PR #93252)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/93252 >From 2033cc94e4b0643e15f2adb26e976feb3578d857 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 24 May 2024 01:39:35 +0300 Subject: [PATCH] [Clang][NFC] improve RewriteModernObjC code quality by using const reference for function parameters --- .../Frontend/Rewrite/RewriteModernObjC.cpp| 37 +-- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp index 6ae955a2380b7..764cdc6f07cf6 100644 --- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -465,15 +465,15 @@ namespace { std::string SynthesizeByrefCopyDestroyHelper(VarDecl *VD, int flag); std::string SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, - StringRef funcName, std::string Tag); -std::string SynthesizeBlockFunc(BlockExpr *CE, int i, - StringRef funcName, std::string Tag); -std::string SynthesizeBlockImpl(BlockExpr *CE, -std::string Tag, std::string Desc); -std::string SynthesizeBlockDescriptor(std::string DescTag, - std::string ImplTag, - int i, StringRef funcName, - unsigned hasCopy); + StringRef funcName, + const std::string &Tag); +std::string SynthesizeBlockFunc(BlockExpr *CE, int i, StringRef funcName, +const std::string &Tag); +std::string SynthesizeBlockImpl(BlockExpr *CE, const std::string &Tag, +const std::string &Desc); +std::string SynthesizeBlockDescriptor(const std::string &DescTag, + const std::string &ImplTag, int i, + StringRef funcName, unsigned hasCopy); Stmt *SynthesizeBlockCall(CallExpr *Exp, const Expr* BlockExp); void SynthesizeBlockLiterals(SourceLocation FunLocStart, StringRef FunName); @@ -4037,7 +4037,7 @@ static bool HasLocalVariableExternalStorage(ValueDecl *VD) { std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, StringRef funcName, - std::string Tag) { + const std::string &Tag) { const FunctionType *AFT = CE->getFunctionType(); QualType RT = AFT->getReturnType(); std::string StructRef = "struct " + Tag; @@ -4131,9 +4131,8 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, return S; } -std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, - StringRef funcName, - std::string Tag) { +std::string RewriteModernObjC::SynthesizeBlockHelperFuncs( +BlockExpr *CE, int i, StringRef funcName, const std::string &Tag) { std::string StructRef = "struct " + Tag; std::string S = "static void __"; @@ -4175,8 +4174,9 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, return S; } -std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, - std::string Desc) { +std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, + const std::string &Tag, + const std::string &Desc) { std::string S = "\nstruct " + Tag; std::string Constructor = " " + Tag; @@ -4290,10 +4290,9 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Ta return S; } -std::string RewriteModernObjC::SynthesizeBlockDescriptor(std::string DescTag, - std::string ImplTag, int i, - StringRef FunName, - unsigned hasCopy) { +std::string RewriteModernObjC::SynthesizeBlockDescriptor( +const std::string &DescTag, const std::string &ImplTag, int i, +StringRef FunName, unsigned hasCopy) { std::string S = "\nstatic struct " + DescTag; S += " {\n size_t reserved;\n"; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] improve RewriteModernObjC code quality by using const reference for function parameters (PR #93252)
https://github.com/a-tarasyuk edited https://github.com/llvm/llvm-project/pull/93252 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] use const references for function parameters in operator== and operator!= overloads in Redeclarable.h (PR #92963)
a-tarasyuk wrote: @zyn0217 Yes, I do. I don't have access to merge… https://github.com/llvm/llvm-project/pull/92963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][NFC] use const references for function parameters in operator== and operator!= overloads in Redeclarable.h (PR #92963)
a-tarasyuk wrote: @zyn0217 Thanks https://github.com/llvm/llvm-project/pull/92963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)
https://github.com/a-tarasyuk deleted https://github.com/llvm/llvm-project/pull/96228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)
@@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s a-tarasyuk wrote: @shafik could you review the latest changes? thanks https://github.com/llvm/llvm-project/pull/96228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)
https://github.com/a-tarasyuk deleted https://github.com/llvm/llvm-project/pull/96228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)
@@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s a-tarasyuk wrote: @shafik @zyn0217 could you review the latest changes? thanks https://github.com/llvm/llvm-project/pull/96228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/96228 >From 9e2730da07df0ee5102912490a687ba40bf06def Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 24 Jun 2024 18:55:51 +0300 Subject: [PATCH] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions --- clang/docs/ReleaseNotes.rst| 1 + clang/lib/Sema/SemaDeclCXX.cpp | 5 - .../class.compare/class.compare.default/p1.cpp | 18 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index df579ae398c5e..86bd8cf4a6210 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -934,6 +934,7 @@ Bug Fixes to C++ Support - Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a forward-declared class. (#GH93512). - Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). +- Fixed failed assertion when resolving context of defaulted comparison method outside of struct. (#GH96043). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 9b220103247dd..0ecad756d4499 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -9192,7 +9192,10 @@ ComputeDefaultedComparisonExceptionSpec(Sema &S, SourceLocation Loc, EnterExpressionEvaluationContext Context( S, Sema::ExpressionEvaluationContext::Unevaluated); -CXXRecordDecl *RD = cast(FD->getLexicalParent()); +CXXRecordDecl *RD = +cast(FD->getFriendObjectKind() == Decl::FOK_None +? FD->getDeclContext() +: FD->getLexicalDeclContext()); SourceLocation BodyLoc = FD->getEndLoc().isValid() ? FD->getEndLoc() : FD->getLocation(); StmtResult Body = diff --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp index 252860bfc4de0..ddf82f432c2ea 100644 --- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp +++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp @@ -265,3 +265,21 @@ void f2() { // access info for unnamed bit-field } } + +namespace GH96043 { +template class a {}; +template b c(a); +template class e { +public: + typedef a f; + f begin(); +}; +template constexpr bool operator==(d h, g i) { + return *c(h.begin()) == *c(i.begin()); +} +struct j { + e bar; + bool operator==(const j &) const; +}; +bool j::operator==(const j &) const = default; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/96228 >From 9e2730da07df0ee5102912490a687ba40bf06def Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 24 Jun 2024 18:55:51 +0300 Subject: [PATCH] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions --- clang/docs/ReleaseNotes.rst| 1 + clang/lib/Sema/SemaDeclCXX.cpp | 5 - .../class.compare/class.compare.default/p1.cpp | 18 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index df579ae398c5ef..86bd8cf4a6210b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -934,6 +934,7 @@ Bug Fixes to C++ Support - Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a forward-declared class. (#GH93512). - Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). +- Fixed failed assertion when resolving context of defaulted comparison method outside of struct. (#GH96043). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 9b220103247dd0..0ecad756d44999 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -9192,7 +9192,10 @@ ComputeDefaultedComparisonExceptionSpec(Sema &S, SourceLocation Loc, EnterExpressionEvaluationContext Context( S, Sema::ExpressionEvaluationContext::Unevaluated); -CXXRecordDecl *RD = cast(FD->getLexicalParent()); +CXXRecordDecl *RD = +cast(FD->getFriendObjectKind() == Decl::FOK_None +? FD->getDeclContext() +: FD->getLexicalDeclContext()); SourceLocation BodyLoc = FD->getEndLoc().isValid() ? FD->getEndLoc() : FD->getLocation(); StmtResult Body = diff --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp index 252860bfc4de07..ddf82f432c2eab 100644 --- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp +++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp @@ -265,3 +265,21 @@ void f2() { // access info for unnamed bit-field } } + +namespace GH96043 { +template class a {}; +template b c(a); +template class e { +public: + typedef a f; + f begin(); +}; +template constexpr bool operator==(d h, g i) { + return *c(h.begin()) == *c(i.begin()); +} +struct j { + e bar; + bool operator==(const j &) const; +}; +bool j::operator==(const j &) const = default; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent checking destructor reference with an invalid initializer (PR #97860)
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/97860 Fixes #97230 >From cb3c677c9eb10998ed7357cdde2722f3b3c1c847 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 6 Jul 2024 00:24:06 +0300 Subject: [PATCH] [Clang] prevent checking destructor reference with an invalid initializer --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaInit.cpp | 3 +++ clang/test/SemaCXX/destructor.cpp | 9 + 3 files changed, 13 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 36cf615a4287cc..b85490376c848f 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -963,6 +963,7 @@ Bug Fixes to C++ Support - Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205). - Fixed a bug where the first operand of binary ``operator&`` would be transformed as if it was the operand of the address of operator. (#GH97483). +- Fix a crash when checking destructor reference with an invalid initializer. (#GH97230). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 64e43ded0961ea..aa003c60b25ee7 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -1986,6 +1986,9 @@ static bool checkDestructorReference(QualType ElementType, SourceLocation Loc, return false; CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(CXXRD); + if (!Destructor) +return false; + SemaRef.CheckDestructorAccess(Loc, Destructor, SemaRef.PDiag(diag::err_access_dtor_temp) << ElementType); diff --git a/clang/test/SemaCXX/destructor.cpp b/clang/test/SemaCXX/destructor.cpp index 028bc7cc196989..dfcd1b033af5a2 100644 --- a/clang/test/SemaCXX/destructor.cpp +++ b/clang/test/SemaCXX/destructor.cpp @@ -577,4 +577,13 @@ static_assert(!__is_trivially_constructible(Foo, const Foo &), ""); static_assert(!__is_trivially_constructible(Foo, Foo &&), ""); } // namespace GH89544 +namespace GH97230 { +struct X { + ~X() = defaul; // expected-error {{initializer on function does not look like a pure-specifier}} \ + // expected-error {{use of undeclared identifier 'defaul'}} +}; +struct Y : X {} y1{ }; // expected-error {{call to implicitly-deleted default constructor of 'struct Y'}} \ + // expected-note {{default constructor of 'Y' is implicitly deleted because base class 'X' has no destructor}} +} + #endif // BE_THE_HEADER ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent checking destructor reference with an invalid initializer (PR #97860)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/97860 >From cb3c677c9eb10998ed7357cdde2722f3b3c1c847 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 6 Jul 2024 00:24:06 +0300 Subject: [PATCH] [Clang] prevent checking destructor reference with an invalid initializer --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaInit.cpp | 3 +++ clang/test/SemaCXX/destructor.cpp | 9 + 3 files changed, 13 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 36cf615a4287c..b85490376c848 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -963,6 +963,7 @@ Bug Fixes to C++ Support - Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205). - Fixed a bug where the first operand of binary ``operator&`` would be transformed as if it was the operand of the address of operator. (#GH97483). +- Fix a crash when checking destructor reference with an invalid initializer. (#GH97230). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 64e43ded0961e..aa003c60b25ee 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -1986,6 +1986,9 @@ static bool checkDestructorReference(QualType ElementType, SourceLocation Loc, return false; CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(CXXRD); + if (!Destructor) +return false; + SemaRef.CheckDestructorAccess(Loc, Destructor, SemaRef.PDiag(diag::err_access_dtor_temp) << ElementType); diff --git a/clang/test/SemaCXX/destructor.cpp b/clang/test/SemaCXX/destructor.cpp index 028bc7cc19698..dfcd1b033af5a 100644 --- a/clang/test/SemaCXX/destructor.cpp +++ b/clang/test/SemaCXX/destructor.cpp @@ -577,4 +577,13 @@ static_assert(!__is_trivially_constructible(Foo, const Foo &), ""); static_assert(!__is_trivially_constructible(Foo, Foo &&), ""); } // namespace GH89544 +namespace GH97230 { +struct X { + ~X() = defaul; // expected-error {{initializer on function does not look like a pure-specifier}} \ + // expected-error {{use of undeclared identifier 'defaul'}} +}; +struct Y : X {} y1{ }; // expected-error {{call to implicitly-deleted default constructor of 'struct Y'}} \ + // expected-note {{default constructor of 'Y' is implicitly deleted because base class 'X' has no destructor}} +} + #endif // BE_THE_HEADER ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/96228 >From 9e2730da07df0ee5102912490a687ba40bf06def Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 24 Jun 2024 18:55:51 +0300 Subject: [PATCH] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions --- clang/docs/ReleaseNotes.rst| 1 + clang/lib/Sema/SemaDeclCXX.cpp | 5 - .../class.compare/class.compare.default/p1.cpp | 18 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index df579ae398c5ef..86bd8cf4a6210b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -934,6 +934,7 @@ Bug Fixes to C++ Support - Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a forward-declared class. (#GH93512). - Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). +- Fixed failed assertion when resolving context of defaulted comparison method outside of struct. (#GH96043). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 9b220103247dd0..0ecad756d44999 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -9192,7 +9192,10 @@ ComputeDefaultedComparisonExceptionSpec(Sema &S, SourceLocation Loc, EnterExpressionEvaluationContext Context( S, Sema::ExpressionEvaluationContext::Unevaluated); -CXXRecordDecl *RD = cast(FD->getLexicalParent()); +CXXRecordDecl *RD = +cast(FD->getFriendObjectKind() == Decl::FOK_None +? FD->getDeclContext() +: FD->getLexicalDeclContext()); SourceLocation BodyLoc = FD->getEndLoc().isValid() ? FD->getEndLoc() : FD->getLocation(); StmtResult Body = diff --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp index 252860bfc4de07..ddf82f432c2eab 100644 --- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp +++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp @@ -265,3 +265,21 @@ void f2() { // access info for unnamed bit-field } } + +namespace GH96043 { +template class a {}; +template b c(a); +template class e { +public: + typedef a f; + f begin(); +}; +template constexpr bool operator==(d h, g i) { + return *c(h.begin()) == *c(i.begin()); +} +struct j { + e bar; + bool operator==(const j &) const; +}; +bool j::operator==(const j &) const = default; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent checking destructor reference with an invalid initializer (PR #97860)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/97860 >From cb3c677c9eb10998ed7357cdde2722f3b3c1c847 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 6 Jul 2024 00:24:06 +0300 Subject: [PATCH] [Clang] prevent checking destructor reference with an invalid initializer --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaInit.cpp | 3 +++ clang/test/SemaCXX/destructor.cpp | 9 + 3 files changed, 13 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 36cf615a4287c..b85490376c848 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -963,6 +963,7 @@ Bug Fixes to C++ Support - Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205). - Fixed a bug where the first operand of binary ``operator&`` would be transformed as if it was the operand of the address of operator. (#GH97483). +- Fix a crash when checking destructor reference with an invalid initializer. (#GH97230). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 64e43ded0961e..aa003c60b25ee 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -1986,6 +1986,9 @@ static bool checkDestructorReference(QualType ElementType, SourceLocation Loc, return false; CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(CXXRD); + if (!Destructor) +return false; + SemaRef.CheckDestructorAccess(Loc, Destructor, SemaRef.PDiag(diag::err_access_dtor_temp) << ElementType); diff --git a/clang/test/SemaCXX/destructor.cpp b/clang/test/SemaCXX/destructor.cpp index 028bc7cc19698..dfcd1b033af5a 100644 --- a/clang/test/SemaCXX/destructor.cpp +++ b/clang/test/SemaCXX/destructor.cpp @@ -577,4 +577,13 @@ static_assert(!__is_trivially_constructible(Foo, const Foo &), ""); static_assert(!__is_trivially_constructible(Foo, Foo &&), ""); } // namespace GH89544 +namespace GH97230 { +struct X { + ~X() = defaul; // expected-error {{initializer on function does not look like a pure-specifier}} \ + // expected-error {{use of undeclared identifier 'defaul'}} +}; +struct Y : X {} y1{ }; // expected-error {{call to implicitly-deleted default constructor of 'struct Y'}} \ + // expected-note {{default constructor of 'Y' is implicitly deleted because base class 'X' has no destructor}} +} + #endif // BE_THE_HEADER ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/96228 >From 9e2730da07df0ee5102912490a687ba40bf06def Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 24 Jun 2024 18:55:51 +0300 Subject: [PATCH] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions --- clang/docs/ReleaseNotes.rst| 1 + clang/lib/Sema/SemaDeclCXX.cpp | 5 - .../class.compare/class.compare.default/p1.cpp | 18 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index df579ae398c5e..86bd8cf4a6210 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -934,6 +934,7 @@ Bug Fixes to C++ Support - Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a forward-declared class. (#GH93512). - Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). +- Fixed failed assertion when resolving context of defaulted comparison method outside of struct. (#GH96043). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 9b220103247dd..0ecad756d4499 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -9192,7 +9192,10 @@ ComputeDefaultedComparisonExceptionSpec(Sema &S, SourceLocation Loc, EnterExpressionEvaluationContext Context( S, Sema::ExpressionEvaluationContext::Unevaluated); -CXXRecordDecl *RD = cast(FD->getLexicalParent()); +CXXRecordDecl *RD = +cast(FD->getFriendObjectKind() == Decl::FOK_None +? FD->getDeclContext() +: FD->getLexicalDeclContext()); SourceLocation BodyLoc = FD->getEndLoc().isValid() ? FD->getEndLoc() : FD->getLocation(); StmtResult Body = diff --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp index 252860bfc4de0..ddf82f432c2ea 100644 --- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp +++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp @@ -265,3 +265,21 @@ void f2() { // access info for unnamed bit-field } } + +namespace GH96043 { +template class a {}; +template b c(a); +template class e { +public: + typedef a f; + f begin(); +}; +template constexpr bool operator==(d h, g i) { + return *c(h.begin()) == *c(i.begin()); +} +struct j { + e bar; + bool operator==(const j &) const; +}; +bool j::operator==(const j &) const = default; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates (PR #107786)
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/107786 Fixes #107047 Fixes #49093 >From b50e49be3765c31b1c555384c41e1f528d529a88 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 9 Sep 2024 02:30:35 +0300 Subject: [PATCH] [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates --- clang/docs/ReleaseNotes.rst | 3 +- clang/lib/Sema/SemaTemplate.cpp | 6 .../SemaTemplate/recovery-crash-cxx20.cpp | 32 +++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaTemplate/recovery-crash-cxx20.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f7c3194c91fa31..f96045c57e7a0d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -376,8 +376,9 @@ Bug Fixes to C++ Support - Fixed a bug in the substitution of empty pack indexing types. (#GH105903) - Clang no longer tries to capture non-odr used default arguments of template parameters of generic lambdas (#GH107048) - Fixed a bug where defaulted comparison operators would remove ``const`` from base classes. (#GH102588) - - Fix a crash when using ``source_location`` in the trailing return type of a lambda expression. (#GH67134) +- Fixed an assertion failure when invoking recovery call expressions with explicit attributes + and undeclared templates. (#GH107047, #GH49093) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 513f83146fb59e..1ec6219bbd6ea8 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -4458,6 +4458,12 @@ ExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec &SS, R.getAsSingle(), TemplateArgs); } + if (TemplateArgs && R.getAsSingle()) { +if (R.getAsSingle()->getTemplateSpecializationKind() == +TemplateSpecializationKind::TSK_Undeclared) + return ExprError(); + } + // We don't want lookup warnings at this point. R.suppressDiagnostics(); diff --git a/clang/test/SemaTemplate/recovery-crash-cxx20.cpp b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp new file mode 100644 index 00..dd92ddcd36ab02 --- /dev/null +++ b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s + +namespace GH49093 { + class B { + public: +static int a() { return 0; } // expected-note {{member is declared here}} +decltype(a< 0 >(0)) test;// expected-error {{member 'a' used before its declaration}} + }; + + struct C { + static int a() { return 0; } // expected-note {{member is declared here}} + decltype(a < 0 > (0)) test; // expected-error {{member 'a' used before its declaration}} + }; + + void test_is_bool(bool t) {} + void test_is_bool(int t) {} + + int main() { +B b; +test_is_bool(b.test); + +C c; +test_is_bool(c.test); + } +} + +namespace GH107047 { + struct A { +static constexpr auto test() { return 1; } // expected-note {{member is declared here}} +static constexpr int s = test< 1 >(); // expected-error {{member 'test' used before its declaration}} + }; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates (PR #107786)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/107786 >From b50e49be3765c31b1c555384c41e1f528d529a88 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 9 Sep 2024 02:30:35 +0300 Subject: [PATCH] [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates --- clang/docs/ReleaseNotes.rst | 3 +- clang/lib/Sema/SemaTemplate.cpp | 6 .../SemaTemplate/recovery-crash-cxx20.cpp | 32 +++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaTemplate/recovery-crash-cxx20.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f7c3194c91fa31..f96045c57e7a0d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -376,8 +376,9 @@ Bug Fixes to C++ Support - Fixed a bug in the substitution of empty pack indexing types. (#GH105903) - Clang no longer tries to capture non-odr used default arguments of template parameters of generic lambdas (#GH107048) - Fixed a bug where defaulted comparison operators would remove ``const`` from base classes. (#GH102588) - - Fix a crash when using ``source_location`` in the trailing return type of a lambda expression. (#GH67134) +- Fixed an assertion failure when invoking recovery call expressions with explicit attributes + and undeclared templates. (#GH107047, #GH49093) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 513f83146fb59e..1ec6219bbd6ea8 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -4458,6 +4458,12 @@ ExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec &SS, R.getAsSingle(), TemplateArgs); } + if (TemplateArgs && R.getAsSingle()) { +if (R.getAsSingle()->getTemplateSpecializationKind() == +TemplateSpecializationKind::TSK_Undeclared) + return ExprError(); + } + // We don't want lookup warnings at this point. R.suppressDiagnostics(); diff --git a/clang/test/SemaTemplate/recovery-crash-cxx20.cpp b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp new file mode 100644 index 00..dd92ddcd36ab02 --- /dev/null +++ b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s + +namespace GH49093 { + class B { + public: +static int a() { return 0; } // expected-note {{member is declared here}} +decltype(a< 0 >(0)) test;// expected-error {{member 'a' used before its declaration}} + }; + + struct C { + static int a() { return 0; } // expected-note {{member is declared here}} + decltype(a < 0 > (0)) test; // expected-error {{member 'a' used before its declaration}} + }; + + void test_is_bool(bool t) {} + void test_is_bool(int t) {} + + int main() { +B b; +test_is_bool(b.test); + +C c; +test_is_bool(c.test); + } +} + +namespace GH107047 { + struct A { +static constexpr auto test() { return 1; } // expected-note {{member is declared here}} +static constexpr int s = test< 1 >(); // expected-error {{member 'test' used before its declaration}} + }; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/106036 >From 8314ba1abc040c5403ec16cc531c822799689598 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 10 Sep 2024 02:35:43 +0300 Subject: [PATCH] [Clang] restrict use of attribute names reserved by the C++ standard --- clang/docs/ReleaseNotes.rst | 2 ++ .../include/clang/Basic/AttributeCommonInfo.h | 2 +- clang/include/clang/Basic/CMakeLists.txt | 5 +++ clang/include/clang/Basic/DiagnosticGroups.td | 1 + .../include/clang/Basic/DiagnosticLexKinds.td | 2 ++ clang/include/clang/Sema/CMakeLists.txt | 5 --- clang/lib/Lex/PPDirectives.cpp| 19 +++- .../Preprocessor/macro-reserved-attrs.cpp | 31 +++ .../gn/secondary/clang/lib/Basic/BUILD.gn | 5 +-- .../gn/secondary/clang/lib/Sema/BUILD.gn | 2 +- .../llvm-project-overlay/clang/BUILD.bazel| 9 +++--- 11 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 clang/test/Preprocessor/macro-reserved-attrs.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 250821a9f9c45c..eecf5de3775f21 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -298,6 +298,8 @@ Improvements to Clang's diagnostics - Clang now warns for u8 character literals used in C23 with ``-Wpre-c23-compat`` instead of ``-Wpre-c++17-compat``. +- Clang now diagnoses the use of attribute names reserved by the C++ standard. (#GH92196). + Improvements to Clang's time-trace -- diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h b/clang/include/clang/Basic/AttributeCommonInfo.h index 5f024b4b5fd782..15e2685e049d9c 100644 --- a/clang/include/clang/Basic/AttributeCommonInfo.h +++ b/clang/include/clang/Basic/AttributeCommonInfo.h @@ -61,7 +61,7 @@ class AttributeCommonInfo { }; enum Kind { #define PARSED_ATTR(NAME) AT_##NAME, -#include "clang/Sema/AttrParsedAttrList.inc" +#include "clang/Basic/AttrParsedAttrList.inc" #undef PARSED_ATTR NoSemaHandlerAttribute, IgnoredAttribute, diff --git a/clang/include/clang/Basic/CMakeLists.txt b/clang/include/clang/Basic/CMakeLists.txt index f069f4fc118f27..bcc34e86385926 100644 --- a/clang/include/clang/Basic/CMakeLists.txt +++ b/clang/include/clang/Basic/CMakeLists.txt @@ -31,6 +31,11 @@ clang_tablegen(AttrList.inc -gen-clang-attr-list SOURCE Attr.td TARGET ClangAttrList) +clang_tablegen(AttrParsedAttrList.inc -gen-clang-attr-parsed-attr-list + -I ${CMAKE_CURRENT_SOURCE_DIR}/../../ + SOURCE Attr.td + TARGET ClangAttrParsedAttrList) + clang_tablegen(AttrSubMatchRulesList.inc -gen-clang-attr-subject-match-rule-list -I ${CMAKE_CURRENT_SOURCE_DIR}/../../ SOURCE Attr.td diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 116ce7a04f66f7..f04afce2da5a8c 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -751,6 +751,7 @@ def AmbiguousMacro : DiagGroup<"ambiguous-macro">; def KeywordAsMacro : DiagGroup<"keyword-macro">; def ReservedIdAsMacro : DiagGroup<"reserved-macro-identifier">; def ReservedIdAsMacroAlias : DiagGroup<"reserved-id-macro", [ReservedIdAsMacro]>; +def ReservedAttributeIdentifier : DiagGroup<"reserved-attribute-identifier">; def RestrictExpansionMacro : DiagGroup<"restrict-expansion">; def FinalMacro : DiagGroup<"final-macro">; diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index fc14bb6aa21651..7e1964b6284c83 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -407,6 +407,8 @@ def warn_pp_macro_hides_keyword : Extension< def warn_pp_macro_is_reserved_id : Warning< "macro name is a reserved identifier">, DefaultIgnore, InGroup; +def warn_pp_macro_is_reserved_attribute_id : Warning< + "%0 is a reserved attribute identifier">, InGroup; def warn_pp_objc_macro_redef_ignored : Warning< "ignoring redefinition of Objective-C qualifier macro">, InGroup>; diff --git a/clang/include/clang/Sema/CMakeLists.txt b/clang/include/clang/Sema/CMakeLists.txt index 0b0e31ece3195d..9077e22c2307cd 100644 --- a/clang/include/clang/Sema/CMakeLists.txt +++ b/clang/include/clang/Sema/CMakeLists.txt @@ -3,11 +3,6 @@ clang_tablegen(AttrTemplateInstantiate.inc -gen-clang-attr-template-instantiate SOURCE ../Basic/Attr.td TARGET ClangAttrTemplateInstantiate) -clang_tablegen(AttrParsedAttrList.inc -gen-clang-attr-parsed-attr-list - -I ${CMAKE_CURRENT_SOURCE_DIR}/../../ - SOURCE ../Basic/Attr.td - TARGET ClangAttrParsedAttrList) - clang_tablegen(AttrParsedAttrKinds.inc -gen-clang-attr-parsed-attr-kinds -I ${CMAKE_CURRENT_SOURCE_DIR}/../../ SOURCE ../Basic/Attr.td diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 4e77df9ec444
[clang] [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates (PR #107786)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/107786 >From b50e49be3765c31b1c555384c41e1f528d529a88 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 9 Sep 2024 02:30:35 +0300 Subject: [PATCH] [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates --- clang/docs/ReleaseNotes.rst | 3 +- clang/lib/Sema/SemaTemplate.cpp | 6 .../SemaTemplate/recovery-crash-cxx20.cpp | 32 +++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaTemplate/recovery-crash-cxx20.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f7c3194c91fa31..f96045c57e7a0d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -376,8 +376,9 @@ Bug Fixes to C++ Support - Fixed a bug in the substitution of empty pack indexing types. (#GH105903) - Clang no longer tries to capture non-odr used default arguments of template parameters of generic lambdas (#GH107048) - Fixed a bug where defaulted comparison operators would remove ``const`` from base classes. (#GH102588) - - Fix a crash when using ``source_location`` in the trailing return type of a lambda expression. (#GH67134) +- Fixed an assertion failure when invoking recovery call expressions with explicit attributes + and undeclared templates. (#GH107047, #GH49093) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 513f83146fb59e..1ec6219bbd6ea8 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -4458,6 +4458,12 @@ ExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec &SS, R.getAsSingle(), TemplateArgs); } + if (TemplateArgs && R.getAsSingle()) { +if (R.getAsSingle()->getTemplateSpecializationKind() == +TemplateSpecializationKind::TSK_Undeclared) + return ExprError(); + } + // We don't want lookup warnings at this point. R.suppressDiagnostics(); diff --git a/clang/test/SemaTemplate/recovery-crash-cxx20.cpp b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp new file mode 100644 index 00..dd92ddcd36ab02 --- /dev/null +++ b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s + +namespace GH49093 { + class B { + public: +static int a() { return 0; } // expected-note {{member is declared here}} +decltype(a< 0 >(0)) test;// expected-error {{member 'a' used before its declaration}} + }; + + struct C { + static int a() { return 0; } // expected-note {{member is declared here}} + decltype(a < 0 > (0)) test; // expected-error {{member 'a' used before its declaration}} + }; + + void test_is_bool(bool t) {} + void test_is_bool(int t) {} + + int main() { +B b; +test_is_bool(b.test); + +C c; +test_is_bool(c.test); + } +} + +namespace GH107047 { + struct A { +static constexpr auto test() { return 1; } // expected-note {{member is declared here}} +static constexpr int s = test< 1 >(); // expected-error {{member 'test' used before its declaration}} + }; +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates (PR #107786)
a-tarasyuk wrote: @AaronBallman could you please review this fix? thanks https://github.com/llvm/llvm-project/pull/107786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang] restrict use of attribute names reserved by the C++ standard (PR #106036)
a-tarasyuk wrote: @AaronBallman oke, thanks for the update. https://github.com/llvm/llvm-project/pull/106036 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block (PR #102864)
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/102864 Fixes #101990 >From d08d3f318ff64b1c7ff06ac3183c8b83de4021ed Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 12 Aug 2024 11:55:52 +0300 Subject: [PATCH] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Parse/ParseDeclCXX.cpp | 5 - clang/test/Parser/attr-order.cpp | 8 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6796a619ba97f8..00a663fdd23454 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -217,6 +217,7 @@ Bug Fixes to C++ Support - Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667), (#GH99877). - Fixed a bug when diagnosing ambiguous explicit specializations of constrained member functions. +- Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index aac89d910bbc83..d45a738fe4c596 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -425,7 +425,10 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) { [[fallthrough]]; default: ParsedAttributes DeclAttrs(AttrFactory); - MaybeParseCXX11Attributes(DeclAttrs); + ParsedAttributes DeclSpecAttrs(AttrFactory); + while (MaybeParseCXX11Attributes(DeclAttrs) || + MaybeParseGNUAttributes(DeclSpecAttrs)) +; ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs); continue; } diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 10bad38cac6447..369941ab24ee69 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -31,3 +31,11 @@ template template [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok + +extern "C" { + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int l(int); // ok + [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok +} + +extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok +extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block (PR #102864)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/102864 >From 08f2cc1cadfe81798ea2b07b1e601e6ea67ecf9a Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 12 Aug 2024 12:00:05 +0300 Subject: [PATCH] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Parse/ParseDeclCXX.cpp | 5 - clang/test/Parser/attr-order.cpp | 8 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6796a619ba97f8..00a663fdd23454 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -217,6 +217,7 @@ Bug Fixes to C++ Support - Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667), (#GH99877). - Fixed a bug when diagnosing ambiguous explicit specializations of constrained member functions. +- Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index aac89d910bbc83..d45a738fe4c596 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -425,7 +425,10 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) { [[fallthrough]]; default: ParsedAttributes DeclAttrs(AttrFactory); - MaybeParseCXX11Attributes(DeclAttrs); + ParsedAttributes DeclSpecAttrs(AttrFactory); + while (MaybeParseCXX11Attributes(DeclAttrs) || + MaybeParseGNUAttributes(DeclSpecAttrs)) +; ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs); continue; } diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 10bad38cac6447..369941ab24ee69 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -31,3 +31,11 @@ template template [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok + +extern "C" { + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int l(int); // ok + [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok +} + +extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok +extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block (PR #102864)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/102864 >From b0e53b1c8a687165fa28bd21200f83bf1b1a9234 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 12 Aug 2024 13:56:30 +0300 Subject: [PATCH] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Parse/ParseDeclCXX.cpp | 5 - clang/test/Parser/attr-order.cpp | 8 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6796a619ba97f8..00a663fdd23454 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -217,6 +217,7 @@ Bug Fixes to C++ Support - Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667), (#GH99877). - Fixed a bug when diagnosing ambiguous explicit specializations of constrained member functions. +- Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index aac89d910bbc83..d45a738fe4c596 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -425,7 +425,10 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) { [[fallthrough]]; default: ParsedAttributes DeclAttrs(AttrFactory); - MaybeParseCXX11Attributes(DeclAttrs); + ParsedAttributes DeclSpecAttrs(AttrFactory); + while (MaybeParseCXX11Attributes(DeclAttrs) || + MaybeParseGNUAttributes(DeclSpecAttrs)) +; ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs); continue; } diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 10bad38cac6447..369941ab24ee69 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -31,3 +31,11 @@ template template [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok + +extern "C" { + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int l(int); // ok + [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok +} + +extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok +extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block (PR #102864)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/102864 >From b0e53b1c8a687165fa28bd21200f83bf1b1a9234 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 12 Aug 2024 13:56:30 +0300 Subject: [PATCH] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Parse/ParseDeclCXX.cpp | 5 - clang/test/Parser/attr-order.cpp | 8 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6796a619ba97f8..00a663fdd23454 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -217,6 +217,7 @@ Bug Fixes to C++ Support - Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667), (#GH99877). - Fixed a bug when diagnosing ambiguous explicit specializations of constrained member functions. +- Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index aac89d910bbc83..d45a738fe4c596 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -425,7 +425,10 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) { [[fallthrough]]; default: ParsedAttributes DeclAttrs(AttrFactory); - MaybeParseCXX11Attributes(DeclAttrs); + ParsedAttributes DeclSpecAttrs(AttrFactory); + while (MaybeParseCXX11Attributes(DeclAttrs) || + MaybeParseGNUAttributes(DeclSpecAttrs)) +; ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs); continue; } diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 10bad38cac6447..369941ab24ee69 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -31,3 +31,11 @@ template template [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok + +extern "C" { + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int l(int); // ok + [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok +} + +extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok +extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block (PR #102864)
a-tarasyuk wrote: @AaronBallman could you review this PR? thanks https://github.com/llvm/llvm-project/pull/102864 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block (PR #102864)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/102864 >From b0e53b1c8a687165fa28bd21200f83bf1b1a9234 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 12 Aug 2024 13:56:30 +0300 Subject: [PATCH 1/2] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Parse/ParseDeclCXX.cpp | 5 - clang/test/Parser/attr-order.cpp | 8 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6796a619ba97f..00a663fdd2345 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -217,6 +217,7 @@ Bug Fixes to C++ Support - Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667), (#GH99877). - Fixed a bug when diagnosing ambiguous explicit specializations of constrained member functions. +- Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index aac89d910bbc8..d45a738fe4c59 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -425,7 +425,10 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) { [[fallthrough]]; default: ParsedAttributes DeclAttrs(AttrFactory); - MaybeParseCXX11Attributes(DeclAttrs); + ParsedAttributes DeclSpecAttrs(AttrFactory); + while (MaybeParseCXX11Attributes(DeclAttrs) || + MaybeParseGNUAttributes(DeclSpecAttrs)) +; ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs); continue; } diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 10bad38cac644..369941ab24ee6 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -31,3 +31,11 @@ template template [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok + +extern "C" { + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int l(int); // ok + [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok +} + +extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok +extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok >From 7adea6685eb9409866088b20b64201c376871b2a Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 13 Aug 2024 22:20:42 +0300 Subject: [PATCH 2/2] add more tests --- clang/test/Parser/attr-order.cpp | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 369941ab24ee6..21e30e5b6f9df 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -37,5 +37,10 @@ extern "C" { [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok } -extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok -extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok +extern "C" { + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n (int); // ok + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] static int o (int x) { return x; }; // ok +} + +extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int p(int); // ok +extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int q(int); // ok ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block (PR #102864)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/102864 >From b0e53b1c8a687165fa28bd21200f83bf1b1a9234 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 12 Aug 2024 13:56:30 +0300 Subject: [PATCH 1/2] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Parse/ParseDeclCXX.cpp | 5 - clang/test/Parser/attr-order.cpp | 8 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6796a619ba97f8..00a663fdd23454 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -217,6 +217,7 @@ Bug Fixes to C++ Support - Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667), (#GH99877). - Fixed a bug when diagnosing ambiguous explicit specializations of constrained member functions. +- Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index aac89d910bbc83..d45a738fe4c596 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -425,7 +425,10 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) { [[fallthrough]]; default: ParsedAttributes DeclAttrs(AttrFactory); - MaybeParseCXX11Attributes(DeclAttrs); + ParsedAttributes DeclSpecAttrs(AttrFactory); + while (MaybeParseCXX11Attributes(DeclAttrs) || + MaybeParseGNUAttributes(DeclSpecAttrs)) +; ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs); continue; } diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 10bad38cac6447..369941ab24ee69 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -31,3 +31,11 @@ template template [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok + +extern "C" { + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int l(int); // ok + [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok +} + +extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok +extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok >From 7adea6685eb9409866088b20b64201c376871b2a Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 13 Aug 2024 22:20:42 +0300 Subject: [PATCH 2/2] add more tests --- clang/test/Parser/attr-order.cpp | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 369941ab24ee69..21e30e5b6f9df1 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -37,5 +37,10 @@ extern "C" { [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok } -extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok -extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok +extern "C" { + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n (int); // ok + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] static int o (int x) { return x; }; // ok +} + +extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int p(int); // ok +extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int q(int); // ok ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent null explicit object argument from being deduced (PR #104328)
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/104328 Fixes #102025 >From 432686be091dae7ff532028fd5c41f73862e0bd5 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 15 Aug 2024 01:43:15 +0300 Subject: [PATCH] [Clang] prevent null explicit object argument from being deduced --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaTemplateDeduction.cpp | 3 ++ .../cxx2b-deduced-explicit-arg.cpp| 30 +++ 3 files changed, 34 insertions(+) create mode 100644 clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1541b0cbf4875c..7acaf4ebdf1f7d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -245,6 +245,7 @@ Bug Fixes to C++ Support specialization of a conversion function template. - Correctly diagnose attempts to use a concept name in its own definition; A concept name is introduced to its scope sooner to match the C++ standard. (#GH55875) +- Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index ec951d5ac06dbc..fc883e423f4710 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -4462,6 +4462,9 @@ TemplateDeductionResult Sema::DeduceTemplateArguments( ParamTypesForArgChecking.push_back(ParamType); if (ParamIdx == 0 && HasExplicitObject) { +if (ObjectType.isNull()) + return TemplateDeductionResult::InvalidExplicitArguments; + if (auto Result = DeduceCallArgument(ParamType, 0, /*ExplicitObjectArgument=*/true); Result != TemplateDeductionResult::Success) diff --git a/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp b/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp new file mode 100644 index 00..4880b148c53c14 --- /dev/null +++ b/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++2b -verify %s + +namespace std { +struct rv {}; + +template struct enable_if; +template struct enable_if { typedef T type; }; + +template +typename enable_if<__is_convertible(T, rv), U>::type forward(T &); +template +typename enable_if::type forward(T &); +} + +struct Foo { + template + constexpr auto operator[](this T &&self, auto... i)// expected-note {{candidate template ignored: substitution failure [with T = Foo &, i:auto = <>]: member '_evaluate' used before its declaration}} + -> decltype(_evaluate(std::forward(self), i...)) { +return self._evaluate(i...); + } + +private: + template + constexpr auto _evaluate(this T &&self, auto... i) -> decltype((i + ...)); +}; + +int main() { + Foo foo; + return foo[]; // expected-error {{no viable overloaded operator[] for type 'Foo'}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block (PR #102864)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/102864 >From b0e53b1c8a687165fa28bd21200f83bf1b1a9234 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 12 Aug 2024 13:56:30 +0300 Subject: [PATCH 1/2] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Parse/ParseDeclCXX.cpp | 5 - clang/test/Parser/attr-order.cpp | 8 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6796a619ba97f8..00a663fdd23454 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -217,6 +217,7 @@ Bug Fixes to C++ Support - Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667), (#GH99877). - Fixed a bug when diagnosing ambiguous explicit specializations of constrained member functions. +- Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index aac89d910bbc83..d45a738fe4c596 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -425,7 +425,10 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) { [[fallthrough]]; default: ParsedAttributes DeclAttrs(AttrFactory); - MaybeParseCXX11Attributes(DeclAttrs); + ParsedAttributes DeclSpecAttrs(AttrFactory); + while (MaybeParseCXX11Attributes(DeclAttrs) || + MaybeParseGNUAttributes(DeclSpecAttrs)) +; ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs); continue; } diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 10bad38cac6447..369941ab24ee69 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -31,3 +31,11 @@ template template [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok + +extern "C" { + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int l(int); // ok + [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok +} + +extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok +extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok >From 7adea6685eb9409866088b20b64201c376871b2a Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 13 Aug 2024 22:20:42 +0300 Subject: [PATCH 2/2] add more tests --- clang/test/Parser/attr-order.cpp | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 369941ab24ee69..21e30e5b6f9df1 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -37,5 +37,10 @@ extern "C" { [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok } -extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok -extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok +extern "C" { + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n (int); // ok + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] static int o (int x) { return x; }; // ok +} + +extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int p(int); // ok +extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int q(int); // ok ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent null explicit object argument from being deduced (PR #104328)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/104328 >From 432686be091dae7ff532028fd5c41f73862e0bd5 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 15 Aug 2024 01:43:15 +0300 Subject: [PATCH 1/2] [Clang] prevent null explicit object argument from being deduced --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaTemplateDeduction.cpp | 3 ++ .../cxx2b-deduced-explicit-arg.cpp| 30 +++ 3 files changed, 34 insertions(+) create mode 100644 clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1541b0cbf4875c..7acaf4ebdf1f7d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -245,6 +245,7 @@ Bug Fixes to C++ Support specialization of a conversion function template. - Correctly diagnose attempts to use a concept name in its own definition; A concept name is introduced to its scope sooner to match the C++ standard. (#GH55875) +- Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index ec951d5ac06dbc..fc883e423f4710 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -4462,6 +4462,9 @@ TemplateDeductionResult Sema::DeduceTemplateArguments( ParamTypesForArgChecking.push_back(ParamType); if (ParamIdx == 0 && HasExplicitObject) { +if (ObjectType.isNull()) + return TemplateDeductionResult::InvalidExplicitArguments; + if (auto Result = DeduceCallArgument(ParamType, 0, /*ExplicitObjectArgument=*/true); Result != TemplateDeductionResult::Success) diff --git a/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp b/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp new file mode 100644 index 00..4880b148c53c14 --- /dev/null +++ b/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++2b -verify %s + +namespace std { +struct rv {}; + +template struct enable_if; +template struct enable_if { typedef T type; }; + +template +typename enable_if<__is_convertible(T, rv), U>::type forward(T &); +template +typename enable_if::type forward(T &); +} + +struct Foo { + template + constexpr auto operator[](this T &&self, auto... i)// expected-note {{candidate template ignored: substitution failure [with T = Foo &, i:auto = <>]: member '_evaluate' used before its declaration}} + -> decltype(_evaluate(std::forward(self), i...)) { +return self._evaluate(i...); + } + +private: + template + constexpr auto _evaluate(this T &&self, auto... i) -> decltype((i + ...)); +}; + +int main() { + Foo foo; + return foo[]; // expected-error {{no viable overloaded operator[] for type 'Foo'}} +} >From 3017d5303fe1ae522cdbdf8662519ba3f5250262 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 15 Aug 2024 01:59:43 +0300 Subject: [PATCH 2/2] move test to cxx2b-deducing-this --- clang/test/SemaCXX/cxx2b-deducing-this.cpp| 19 .../cxx2b-deduced-explicit-arg.cpp| 30 --- 2 files changed, 19 insertions(+), 30 deletions(-) delete mode 100644 clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp index 45fee6514c12bc..985c0d81cc320f 100644 --- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp +++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp @@ -972,3 +972,22 @@ struct R { f(r_value_ref); // expected-error {{no matching member function for call to 'f'}} } }; + +namespace GH102025 { +struct Foo { + template + constexpr auto operator[](this T &&self, auto... i) // expected-note {{candidate template ignored: substitution failure [with T = Foo &, i:auto = <>]: member '_evaluate' used before its declaration}} + -> decltype(_evaluate(self, i...)) { +return self._evaluate(i...); + } + +private: + template + constexpr auto _evaluate(this T &&self, auto... i) -> decltype((i + ...)); +}; + +int main() { + Foo foo; + return foo[]; // expected-error {{no viable overloaded operator[] for type 'Foo'}} +} +} diff --git a/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp b/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp deleted file mode 100644 index 4880b148c53c14..00 --- a/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++2b -verify %s - -namespace std { -struct rv {}; - -template struct enable_if; -template struct enable_if { typedef T type; }; - -template -typename enable_if<__is_convertible(T, rv), U>::type forwa
[clang] [Clang] prevent null explicit object argument from being deduced (PR #104328)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/104328 >From 432686be091dae7ff532028fd5c41f73862e0bd5 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 15 Aug 2024 01:43:15 +0300 Subject: [PATCH 1/2] [Clang] prevent null explicit object argument from being deduced --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaTemplateDeduction.cpp | 3 ++ .../cxx2b-deduced-explicit-arg.cpp| 30 +++ 3 files changed, 34 insertions(+) create mode 100644 clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1541b0cbf4875c..7acaf4ebdf1f7d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -245,6 +245,7 @@ Bug Fixes to C++ Support specialization of a conversion function template. - Correctly diagnose attempts to use a concept name in its own definition; A concept name is introduced to its scope sooner to match the C++ standard. (#GH55875) +- Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index ec951d5ac06dbc..fc883e423f4710 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -4462,6 +4462,9 @@ TemplateDeductionResult Sema::DeduceTemplateArguments( ParamTypesForArgChecking.push_back(ParamType); if (ParamIdx == 0 && HasExplicitObject) { +if (ObjectType.isNull()) + return TemplateDeductionResult::InvalidExplicitArguments; + if (auto Result = DeduceCallArgument(ParamType, 0, /*ExplicitObjectArgument=*/true); Result != TemplateDeductionResult::Success) diff --git a/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp b/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp new file mode 100644 index 00..4880b148c53c14 --- /dev/null +++ b/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++2b -verify %s + +namespace std { +struct rv {}; + +template struct enable_if; +template struct enable_if { typedef T type; }; + +template +typename enable_if<__is_convertible(T, rv), U>::type forward(T &); +template +typename enable_if::type forward(T &); +} + +struct Foo { + template + constexpr auto operator[](this T &&self, auto... i)// expected-note {{candidate template ignored: substitution failure [with T = Foo &, i:auto = <>]: member '_evaluate' used before its declaration}} + -> decltype(_evaluate(std::forward(self), i...)) { +return self._evaluate(i...); + } + +private: + template + constexpr auto _evaluate(this T &&self, auto... i) -> decltype((i + ...)); +}; + +int main() { + Foo foo; + return foo[]; // expected-error {{no viable overloaded operator[] for type 'Foo'}} +} >From 3017d5303fe1ae522cdbdf8662519ba3f5250262 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 15 Aug 2024 01:59:43 +0300 Subject: [PATCH 2/2] move test to cxx2b-deducing-this --- clang/test/SemaCXX/cxx2b-deducing-this.cpp| 19 .../cxx2b-deduced-explicit-arg.cpp| 30 --- 2 files changed, 19 insertions(+), 30 deletions(-) delete mode 100644 clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp index 45fee6514c12bc..985c0d81cc320f 100644 --- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp +++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp @@ -972,3 +972,22 @@ struct R { f(r_value_ref); // expected-error {{no matching member function for call to 'f'}} } }; + +namespace GH102025 { +struct Foo { + template + constexpr auto operator[](this T &&self, auto... i) // expected-note {{candidate template ignored: substitution failure [with T = Foo &, i:auto = <>]: member '_evaluate' used before its declaration}} + -> decltype(_evaluate(self, i...)) { +return self._evaluate(i...); + } + +private: + template + constexpr auto _evaluate(this T &&self, auto... i) -> decltype((i + ...)); +}; + +int main() { + Foo foo; + return foo[]; // expected-error {{no viable overloaded operator[] for type 'Foo'}} +} +} diff --git a/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp b/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp deleted file mode 100644 index 4880b148c53c14..00 --- a/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++2b -verify %s - -namespace std { -struct rv {}; - -template struct enable_if; -template struct enable_if { typedef T type; }; - -template -typename enable_if<__is_convertible(T, rv), U>::type forwa
[clang] [Clang] prevent null explicit object argument from being deduced (PR #104328)
@@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++2b -verify %s + +namespace std { +struct rv {}; + +template struct enable_if; +template struct enable_if { typedef T type; }; + +template +typename enable_if<__is_convertible(T, rv), U>::type forward(T &); +template +typename enable_if::type forward(T &); +} a-tarasyuk wrote: @cor3ntin Thanks for the review. I’ve removed unnecessary deps and moved the test to the appropriate file. https://github.com/llvm/llvm-project/pull/104328 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block (PR #102864)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/102864 >From b0e53b1c8a687165fa28bd21200f83bf1b1a9234 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 12 Aug 2024 13:56:30 +0300 Subject: [PATCH 1/2] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Parse/ParseDeclCXX.cpp | 5 - clang/test/Parser/attr-order.cpp | 8 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6796a619ba97f8..00a663fdd23454 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -217,6 +217,7 @@ Bug Fixes to C++ Support - Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667), (#GH99877). - Fixed a bug when diagnosing ambiguous explicit specializations of constrained member functions. +- Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index aac89d910bbc83..d45a738fe4c596 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -425,7 +425,10 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) { [[fallthrough]]; default: ParsedAttributes DeclAttrs(AttrFactory); - MaybeParseCXX11Attributes(DeclAttrs); + ParsedAttributes DeclSpecAttrs(AttrFactory); + while (MaybeParseCXX11Attributes(DeclAttrs) || + MaybeParseGNUAttributes(DeclSpecAttrs)) +; ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs); continue; } diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 10bad38cac6447..369941ab24ee69 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -31,3 +31,11 @@ template template [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok + +extern "C" { + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int l(int); // ok + [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok +} + +extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok +extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok >From 7adea6685eb9409866088b20b64201c376871b2a Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 13 Aug 2024 22:20:42 +0300 Subject: [PATCH 2/2] add more tests --- clang/test/Parser/attr-order.cpp | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 369941ab24ee69..21e30e5b6f9df1 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -37,5 +37,10 @@ extern "C" { [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok } -extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok -extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok +extern "C" { + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n (int); // ok + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] static int o (int x) { return x; }; // ok +} + +extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int p(int); // ok +extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int q(int); // ok ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent null explicit object argument from being deduced (PR #104328)
@@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++2b -verify %s + +namespace std { +struct rv {}; + +template struct enable_if; +template struct enable_if { typedef T type; }; + +template +typename enable_if<__is_convertible(T, rv), U>::type forward(T &); +template +typename enable_if::type forward(T &); +} a-tarasyuk wrote: @mizvekov Thanks for the feedback. I thought it would be better/safe to explicitly exclude cases where `ObjectType` is used as `ArgType` for the first parameter when the function has `HasExplicitObject`, as this could cause crashes... https://github.com/llvm/llvm-project/blob/fa343be414f9364911b947f109f3df5539e23068/clang/lib/Sema/SemaTemplateDeduction.cpp#L4371 In other cases, `ArgType` will be based on the arg index. That’s why I added this condition before https://github.com/llvm/llvm-project/blob/fa343be414f9364911b947f109f3df5539e23068/clang/lib/Sema/SemaTemplateDeduction.cpp#L4464 Or should we completely avoid using `DeduceTemplateArguments` with an empty `ObjectType`? https://github.com/llvm/llvm-project/blob/6d9cae12bdfcaeb2be10866e20e8883242f02c6c/clang/lib/Sema/SemaOverload.cpp#L7730 I'd appreciate your perspective on that. Thanks https://github.com/llvm/llvm-project/pull/104328 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block (PR #102864)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/102864 >From b0e53b1c8a687165fa28bd21200f83bf1b1a9234 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Mon, 12 Aug 2024 13:56:30 +0300 Subject: [PATCH 1/2] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Parse/ParseDeclCXX.cpp | 5 - clang/test/Parser/attr-order.cpp | 8 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6796a619ba97f8..00a663fdd23454 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -217,6 +217,7 @@ Bug Fixes to C++ Support - Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667), (#GH99877). - Fixed a bug when diagnosing ambiguous explicit specializations of constrained member functions. +- Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index aac89d910bbc83..d45a738fe4c596 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -425,7 +425,10 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) { [[fallthrough]]; default: ParsedAttributes DeclAttrs(AttrFactory); - MaybeParseCXX11Attributes(DeclAttrs); + ParsedAttributes DeclSpecAttrs(AttrFactory); + while (MaybeParseCXX11Attributes(DeclAttrs) || + MaybeParseGNUAttributes(DeclSpecAttrs)) +; ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs); continue; } diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 10bad38cac6447..369941ab24ee69 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -31,3 +31,11 @@ template template [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok + +extern "C" { + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int l(int); // ok + [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok +} + +extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok +extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok >From 7adea6685eb9409866088b20b64201c376871b2a Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 13 Aug 2024 22:20:42 +0300 Subject: [PATCH 2/2] add more tests --- clang/test/Parser/attr-order.cpp | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/test/Parser/attr-order.cpp b/clang/test/Parser/attr-order.cpp index 369941ab24ee69..21e30e5b6f9df1 100644 --- a/clang/test/Parser/attr-order.cpp +++ b/clang/test/Parser/attr-order.cpp @@ -37,5 +37,10 @@ extern "C" { [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok } -extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok -extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok +extern "C" { + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n (int); // ok + __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] static int o (int x) { return x; }; // ok +} + +extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int p(int); // ok +extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int q(int); // ok ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block (PR #102864)
a-tarasyuk wrote: @AaronBallman Thanks for the review. I've resolved the conflicts. Could you merge it after the CI passes? Thanks https://github.com/llvm/llvm-project/pull/102864 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent null explicit object argument from being deduced (PR #104328)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/104328 >From 432686be091dae7ff532028fd5c41f73862e0bd5 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 15 Aug 2024 01:43:15 +0300 Subject: [PATCH 1/2] [Clang] prevent null explicit object argument from being deduced --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaTemplateDeduction.cpp | 3 ++ .../cxx2b-deduced-explicit-arg.cpp| 30 +++ 3 files changed, 34 insertions(+) create mode 100644 clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1541b0cbf4875c..7acaf4ebdf1f7d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -245,6 +245,7 @@ Bug Fixes to C++ Support specialization of a conversion function template. - Correctly diagnose attempts to use a concept name in its own definition; A concept name is introduced to its scope sooner to match the C++ standard. (#GH55875) +- Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index ec951d5ac06dbc..fc883e423f4710 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -4462,6 +4462,9 @@ TemplateDeductionResult Sema::DeduceTemplateArguments( ParamTypesForArgChecking.push_back(ParamType); if (ParamIdx == 0 && HasExplicitObject) { +if (ObjectType.isNull()) + return TemplateDeductionResult::InvalidExplicitArguments; + if (auto Result = DeduceCallArgument(ParamType, 0, /*ExplicitObjectArgument=*/true); Result != TemplateDeductionResult::Success) diff --git a/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp b/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp new file mode 100644 index 00..4880b148c53c14 --- /dev/null +++ b/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++2b -verify %s + +namespace std { +struct rv {}; + +template struct enable_if; +template struct enable_if { typedef T type; }; + +template +typename enable_if<__is_convertible(T, rv), U>::type forward(T &); +template +typename enable_if::type forward(T &); +} + +struct Foo { + template + constexpr auto operator[](this T &&self, auto... i)// expected-note {{candidate template ignored: substitution failure [with T = Foo &, i:auto = <>]: member '_evaluate' used before its declaration}} + -> decltype(_evaluate(std::forward(self), i...)) { +return self._evaluate(i...); + } + +private: + template + constexpr auto _evaluate(this T &&self, auto... i) -> decltype((i + ...)); +}; + +int main() { + Foo foo; + return foo[]; // expected-error {{no viable overloaded operator[] for type 'Foo'}} +} >From 3017d5303fe1ae522cdbdf8662519ba3f5250262 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 15 Aug 2024 01:59:43 +0300 Subject: [PATCH 2/2] move test to cxx2b-deducing-this --- clang/test/SemaCXX/cxx2b-deducing-this.cpp| 19 .../cxx2b-deduced-explicit-arg.cpp| 30 --- 2 files changed, 19 insertions(+), 30 deletions(-) delete mode 100644 clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp index 45fee6514c12bc..985c0d81cc320f 100644 --- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp +++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp @@ -972,3 +972,22 @@ struct R { f(r_value_ref); // expected-error {{no matching member function for call to 'f'}} } }; + +namespace GH102025 { +struct Foo { + template + constexpr auto operator[](this T &&self, auto... i) // expected-note {{candidate template ignored: substitution failure [with T = Foo &, i:auto = <>]: member '_evaluate' used before its declaration}} + -> decltype(_evaluate(self, i...)) { +return self._evaluate(i...); + } + +private: + template + constexpr auto _evaluate(this T &&self, auto... i) -> decltype((i + ...)); +}; + +int main() { + Foo foo; + return foo[]; // expected-error {{no viable overloaded operator[] for type 'Foo'}} +} +} diff --git a/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp b/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp deleted file mode 100644 index 4880b148c53c14..00 --- a/clang/test/SemaTemplate/cxx2b-deduced-explicit-arg.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++2b -verify %s - -namespace std { -struct rv {}; - -template struct enable_if; -template struct enable_if { typedef T type; }; - -template -typename enable_if<__is_convertible(T, rv), U>::type forwa
[clang] [Clang] prevent null explicit object argument from being deduced (PR #104328)
a-tarasyuk wrote: @cor3ntin Thanks for the review. I've resolved conflicts. Could you merge it after the CI passes? Thanks https://github.com/llvm/llvm-project/pull/104328 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent null explicit object argument from being deduced (PR #104328)
@@ -4462,6 +4462,9 @@ TemplateDeductionResult Sema::DeduceTemplateArguments( ParamTypesForArgChecking.push_back(ParamType); if (ParamIdx == 0 && HasExplicitObject) { +if (ObjectType.isNull()) + return TemplateDeductionResult::InvalidExplicitArguments; a-tarasyuk wrote: @mizvekov thanks for your feedback. I assumed `TemplateDeductionResult::AlreadyDiagnosed` was intended for situations where the checker has already detected errors. Is it? Should I revert these changes, or would opening a new issue/PR be better? /cc @cor3ntin https://github.com/llvm/llvm-project/pull/104328 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p3 requirements (PR #101853)
@@ -12210,7 +12220,18 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, return Redeclaration; } -void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& DS) { +void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) { + // [basic.start.main]p3 + //The main function shall not be declared with a linkage-specification. + if (FD->isExternCContext() || + (FD->isExternCXXContext() && + FD->getDeclContext()->getRedeclContext()->isTranslationUnit())) { +Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification) +<< FD->getLanguageLinkage(); +FD->setInvalidDecl(); +return; a-tarasyuk wrote: @alexfh I’ll look into it today. Thanks for bringing this additional case to my attention. https://github.com/llvm/llvm-project/pull/101853 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks (PR #104594)
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/104594 Fixes #104570 >From e1821933a1670353c396ada17b82d5bb41599c14 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 16 Aug 2024 17:21:38 +0300 Subject: [PATCH] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaDecl.cpp | 1 - .../basic/basic.start/basic.start.main/p3.cpp | 31 ++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ffdd063ec99037..1731100fdbcf87 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -264,6 +264,7 @@ Bug Fixes to C++ Support - Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter. - Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). - Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). +- Fixed a crash caused by marking the function declaration as invalid during strictness checks on ``extern`` main. (#GH104570). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d19a16cf2ba150..5bba9c1750287d 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -12233,7 +12233,6 @@ void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) { FD->getDeclContext()->getRedeclContext()->isTranslationUnit())) { Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification) << FD->getLanguageLinkage(); -FD->setInvalidDecl(); return; } diff --git a/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp b/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp index d23d00ccdeebc1..04705a6a365905 100644 --- a/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp +++ b/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp @@ -11,6 +11,8 @@ // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST11 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST12 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST13 +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST14 +// RUN: %clang_cc1 -emit-llvm-only -verify -pedantic %s -DTEST15 #if TEST1 int main; // expected-error{{main cannot be declared as a variable in the global scope}} @@ -78,12 +80,12 @@ namespace ns { extern "C" struct A { int main(); }; // ok namespace c { - extern "C" void main(); // expected-warning {{'main' should not be 'extern "C"'}} + extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} } extern "C" { namespace Z { -void main(); // expected-warning {{'main' should not be 'extern "C"'}} +int main(); // expected-warning {{'main' should not be 'extern "C"'}} } } @@ -102,11 +104,6 @@ extern "C++" { int main(); // expected-warning {{'main' should not be 'extern "C++"'}} } -extern "C" { - int main(); // expected-warning {{'main' should not be 'extern "C"'}} -} - -extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} extern "C++" int main(); // expected-warning {{'main' should not be 'extern "C++"'}} namespace ns1 { @@ -122,6 +119,26 @@ namespace ns2 { extern "C++" void main() {} // ok } +#elif TEST14 +extern "C" { + int main(); // expected-warning {{'main' should not be 'extern "C"'}} +} + +extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} + +#elif TEST15 +extern "C" __attribute__((visibility("default"))) __attribute__((weak)) +int main(); // expected-warning {{'main' should not be 'extern "C"'}} + +using uptr = unsigned long; + +extern bool f(uptr, uptr); +bool InitModuleList() { + uptr me = reinterpret_cast(InitModuleList); + uptr exe = reinterpret_cast(&main); // expected-warning {{referring to 'main' within an expression is a Clang extension}} + return f(me, exe); +} + #else #error Unknown Test #endif ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks (PR #104594)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/104594 >From 9ffe47795d3fa25d6ac020b5cebace0c2e758285 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 16 Aug 2024 17:21:38 +0300 Subject: [PATCH] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaDecl.cpp | 1 - .../basic/basic.start/basic.start.main/p3.cpp | 31 ++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ffdd063ec99037..1731100fdbcf87 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -264,6 +264,7 @@ Bug Fixes to C++ Support - Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter. - Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). - Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). +- Fixed a crash caused by marking the function declaration as invalid during strictness checks on ``extern`` main. (#GH104570). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d19a16cf2ba150..5bba9c1750287d 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -12233,7 +12233,6 @@ void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) { FD->getDeclContext()->getRedeclContext()->isTranslationUnit())) { Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification) << FD->getLanguageLinkage(); -FD->setInvalidDecl(); return; } diff --git a/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp b/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp index d23d00ccdeebc1..0d2c5fbb37afe7 100644 --- a/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp +++ b/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp @@ -11,6 +11,8 @@ // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST11 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST12 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST13 +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST14 +// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm-only -verify -pedantic %s -DTEST15 #if TEST1 int main; // expected-error{{main cannot be declared as a variable in the global scope}} @@ -78,12 +80,12 @@ namespace ns { extern "C" struct A { int main(); }; // ok namespace c { - extern "C" void main(); // expected-warning {{'main' should not be 'extern "C"'}} + extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} } extern "C" { namespace Z { -void main(); // expected-warning {{'main' should not be 'extern "C"'}} +int main(); // expected-warning {{'main' should not be 'extern "C"'}} } } @@ -102,11 +104,6 @@ extern "C++" { int main(); // expected-warning {{'main' should not be 'extern "C++"'}} } -extern "C" { - int main(); // expected-warning {{'main' should not be 'extern "C"'}} -} - -extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} extern "C++" int main(); // expected-warning {{'main' should not be 'extern "C++"'}} namespace ns1 { @@ -122,6 +119,26 @@ namespace ns2 { extern "C++" void main() {} // ok } +#elif TEST14 +extern "C" { + int main(); // expected-warning {{'main' should not be 'extern "C"'}} +} + +extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} + +#elif TEST15 +extern "C" __attribute__((visibility("default"))) __attribute__((weak)) +int main(); // expected-warning {{'main' should not be 'extern "C"'}} + +using uptr = unsigned long; + +extern bool f(uptr, uptr); +bool InitModuleList() { + uptr me = reinterpret_cast(InitModuleList); + uptr exe = reinterpret_cast(&main); // expected-warning {{referring to 'main' within an expression is a Clang extension}} + return f(me, exe); +} + #else #error Unknown Test #endif ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks (PR #104594)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/104594 >From 9ffe47795d3fa25d6ac020b5cebace0c2e758285 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 16 Aug 2024 17:21:38 +0300 Subject: [PATCH 1/2] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaDecl.cpp | 1 - .../basic/basic.start/basic.start.main/p3.cpp | 31 ++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ffdd063ec99037..1731100fdbcf87 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -264,6 +264,7 @@ Bug Fixes to C++ Support - Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter. - Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). - Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). +- Fixed a crash caused by marking the function declaration as invalid during strictness checks on ``extern`` main. (#GH104570). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d19a16cf2ba150..5bba9c1750287d 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -12233,7 +12233,6 @@ void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) { FD->getDeclContext()->getRedeclContext()->isTranslationUnit())) { Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification) << FD->getLanguageLinkage(); -FD->setInvalidDecl(); return; } diff --git a/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp b/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp index d23d00ccdeebc1..0d2c5fbb37afe7 100644 --- a/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp +++ b/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp @@ -11,6 +11,8 @@ // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST11 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST12 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST13 +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST14 +// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm-only -verify -pedantic %s -DTEST15 #if TEST1 int main; // expected-error{{main cannot be declared as a variable in the global scope}} @@ -78,12 +80,12 @@ namespace ns { extern "C" struct A { int main(); }; // ok namespace c { - extern "C" void main(); // expected-warning {{'main' should not be 'extern "C"'}} + extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} } extern "C" { namespace Z { -void main(); // expected-warning {{'main' should not be 'extern "C"'}} +int main(); // expected-warning {{'main' should not be 'extern "C"'}} } } @@ -102,11 +104,6 @@ extern "C++" { int main(); // expected-warning {{'main' should not be 'extern "C++"'}} } -extern "C" { - int main(); // expected-warning {{'main' should not be 'extern "C"'}} -} - -extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} extern "C++" int main(); // expected-warning {{'main' should not be 'extern "C++"'}} namespace ns1 { @@ -122,6 +119,26 @@ namespace ns2 { extern "C++" void main() {} // ok } +#elif TEST14 +extern "C" { + int main(); // expected-warning {{'main' should not be 'extern "C"'}} +} + +extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} + +#elif TEST15 +extern "C" __attribute__((visibility("default"))) __attribute__((weak)) +int main(); // expected-warning {{'main' should not be 'extern "C"'}} + +using uptr = unsigned long; + +extern bool f(uptr, uptr); +bool InitModuleList() { + uptr me = reinterpret_cast(InitModuleList); + uptr exe = reinterpret_cast(&main); // expected-warning {{referring to 'main' within an expression is a Clang extension}} + return f(me, exe); +} + #else #error Unknown Test #endif >From 0ea146acc97e2761b401cca5f9b664d39d2a0e9f Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 16 Aug 2024 18:08:40 +0300 Subject: [PATCH 2/2] cleanup --- clang/docs/ReleaseNotes.rst | 1 - clang/lib/Sema/SemaDecl.cpp | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1731100fdbcf87..ffdd063ec99037 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -264,7 +264,6 @@ Bug Fixes to C++ Support - Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter. - Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). - Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH1020
[clang] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks (PR #104594)
@@ -12233,7 +12233,6 @@ void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) { FD->getDeclContext()->getRedeclContext()->isTranslationUnit())) { Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification) << FD->getLanguageLinkage(); -FD->setInvalidDecl(); return; a-tarasyuk wrote: @alexfh Thanks for the review. I've removed it to proceed with other checks... https://github.com/llvm/llvm-project/pull/104594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks (PR #104594)
@@ -264,6 +264,7 @@ Bug Fixes to C++ Support - Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter. - Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). - Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). +- Fixed a crash caused by marking the function declaration as invalid during strictness checks on ``extern`` main. (#GH104570). a-tarasyuk wrote: Good question. Should this be treated as a follow-up to the main PR, or listed separately as a fix? I've removed it for now, but I can revert it if needed... https://github.com/llvm/llvm-project/pull/104594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks (PR #104594)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/104594 >From 9ffe47795d3fa25d6ac020b5cebace0c2e758285 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 16 Aug 2024 17:21:38 +0300 Subject: [PATCH 1/2] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaDecl.cpp | 1 - .../basic/basic.start/basic.start.main/p3.cpp | 31 ++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ffdd063ec99037..1731100fdbcf87 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -264,6 +264,7 @@ Bug Fixes to C++ Support - Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter. - Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). - Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). +- Fixed a crash caused by marking the function declaration as invalid during strictness checks on ``extern`` main. (#GH104570). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d19a16cf2ba150..5bba9c1750287d 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -12233,7 +12233,6 @@ void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) { FD->getDeclContext()->getRedeclContext()->isTranslationUnit())) { Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification) << FD->getLanguageLinkage(); -FD->setInvalidDecl(); return; } diff --git a/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp b/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp index d23d00ccdeebc1..0d2c5fbb37afe7 100644 --- a/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp +++ b/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp @@ -11,6 +11,8 @@ // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST11 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST12 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST13 +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST14 +// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm-only -verify -pedantic %s -DTEST15 #if TEST1 int main; // expected-error{{main cannot be declared as a variable in the global scope}} @@ -78,12 +80,12 @@ namespace ns { extern "C" struct A { int main(); }; // ok namespace c { - extern "C" void main(); // expected-warning {{'main' should not be 'extern "C"'}} + extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} } extern "C" { namespace Z { -void main(); // expected-warning {{'main' should not be 'extern "C"'}} +int main(); // expected-warning {{'main' should not be 'extern "C"'}} } } @@ -102,11 +104,6 @@ extern "C++" { int main(); // expected-warning {{'main' should not be 'extern "C++"'}} } -extern "C" { - int main(); // expected-warning {{'main' should not be 'extern "C"'}} -} - -extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} extern "C++" int main(); // expected-warning {{'main' should not be 'extern "C++"'}} namespace ns1 { @@ -122,6 +119,26 @@ namespace ns2 { extern "C++" void main() {} // ok } +#elif TEST14 +extern "C" { + int main(); // expected-warning {{'main' should not be 'extern "C"'}} +} + +extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} + +#elif TEST15 +extern "C" __attribute__((visibility("default"))) __attribute__((weak)) +int main(); // expected-warning {{'main' should not be 'extern "C"'}} + +using uptr = unsigned long; + +extern bool f(uptr, uptr); +bool InitModuleList() { + uptr me = reinterpret_cast(InitModuleList); + uptr exe = reinterpret_cast(&main); // expected-warning {{referring to 'main' within an expression is a Clang extension}} + return f(me, exe); +} + #else #error Unknown Test #endif >From 0ea146acc97e2761b401cca5f9b664d39d2a0e9f Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 16 Aug 2024 18:08:40 +0300 Subject: [PATCH 2/2] cleanup --- clang/docs/ReleaseNotes.rst | 1 - clang/lib/Sema/SemaDecl.cpp | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1731100fdbcf87..ffdd063ec99037 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -264,7 +264,6 @@ Bug Fixes to C++ Support - Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter. - Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). - Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH1020
[clang] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks (PR #104594)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/104594 >From 9ffe47795d3fa25d6ac020b5cebace0c2e758285 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 16 Aug 2024 17:21:38 +0300 Subject: [PATCH 1/3] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaDecl.cpp | 1 - .../basic/basic.start/basic.start.main/p3.cpp | 31 ++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ffdd063ec99037..1731100fdbcf87 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -264,6 +264,7 @@ Bug Fixes to C++ Support - Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter. - Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). - Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH102025). +- Fixed a crash caused by marking the function declaration as invalid during strictness checks on ``extern`` main. (#GH104570). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d19a16cf2ba150..5bba9c1750287d 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -12233,7 +12233,6 @@ void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) { FD->getDeclContext()->getRedeclContext()->isTranslationUnit())) { Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification) << FD->getLanguageLinkage(); -FD->setInvalidDecl(); return; } diff --git a/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp b/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp index d23d00ccdeebc1..0d2c5fbb37afe7 100644 --- a/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp +++ b/clang/test/CXX/basic/basic.start/basic.start.main/p3.cpp @@ -11,6 +11,8 @@ // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST11 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST12 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST13 +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -DTEST14 +// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm-only -verify -pedantic %s -DTEST15 #if TEST1 int main; // expected-error{{main cannot be declared as a variable in the global scope}} @@ -78,12 +80,12 @@ namespace ns { extern "C" struct A { int main(); }; // ok namespace c { - extern "C" void main(); // expected-warning {{'main' should not be 'extern "C"'}} + extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} } extern "C" { namespace Z { -void main(); // expected-warning {{'main' should not be 'extern "C"'}} +int main(); // expected-warning {{'main' should not be 'extern "C"'}} } } @@ -102,11 +104,6 @@ extern "C++" { int main(); // expected-warning {{'main' should not be 'extern "C++"'}} } -extern "C" { - int main(); // expected-warning {{'main' should not be 'extern "C"'}} -} - -extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} extern "C++" int main(); // expected-warning {{'main' should not be 'extern "C++"'}} namespace ns1 { @@ -122,6 +119,26 @@ namespace ns2 { extern "C++" void main() {} // ok } +#elif TEST14 +extern "C" { + int main(); // expected-warning {{'main' should not be 'extern "C"'}} +} + +extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} + +#elif TEST15 +extern "C" __attribute__((visibility("default"))) __attribute__((weak)) +int main(); // expected-warning {{'main' should not be 'extern "C"'}} + +using uptr = unsigned long; + +extern bool f(uptr, uptr); +bool InitModuleList() { + uptr me = reinterpret_cast(InitModuleList); + uptr exe = reinterpret_cast(&main); // expected-warning {{referring to 'main' within an expression is a Clang extension}} + return f(me, exe); +} + #else #error Unknown Test #endif >From 0ea146acc97e2761b401cca5f9b664d39d2a0e9f Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 16 Aug 2024 18:08:40 +0300 Subject: [PATCH 2/3] cleanup --- clang/docs/ReleaseNotes.rst | 1 - clang/lib/Sema/SemaDecl.cpp | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1731100fdbcf87..ffdd063ec99037 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -264,7 +264,6 @@ Bug Fixes to C++ Support - Properly reject defaulted copy/move assignment operators that have a non-reference explicit object parameter. - Clang now properly handles the order of attributes in `extern` blocks. (#GH101990). - Fixed an assertion failure by preventing null explicit object arguments from being deduced. (#GH1020
[clang] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks (PR #104594)
@@ -122,6 +119,26 @@ namespace ns2 { extern "C++" void main() {} // ok } +#elif TEST14 +extern "C" { + int main(); // expected-warning {{'main' should not be 'extern "C"'}} +} + +extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} + +#elif TEST15 +extern "C" __attribute__((visibility("default"))) __attribute__((weak)) a-tarasyuk wrote: I've updated test, thanks https://github.com/llvm/llvm-project/pull/104594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks (PR #104594)
a-tarasyuk wrote: @alexfh Please merge the PR as I lack the access. Thanks https://github.com/llvm/llvm-project/pull/104594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix crash by avoiding invalidation of extern main declaration during strictness checks (PR #104594)
@@ -78,12 +80,12 @@ namespace ns { extern "C" struct A { int main(); }; // ok namespace c { - extern "C" void main(); // expected-warning {{'main' should not be 'extern "C"'}} + extern "C" int main(); // expected-warning {{'main' should not be 'extern "C"'}} } extern "C" { namespace Z { -void main(); // expected-warning {{'main' should not be 'extern "C"'}} a-tarasyuk wrote: To avoid unnecessary diagnostics and only validate invalid linkage for the main function, since the main function will not be interrupted by invalid usage. Should I revert it? https://github.com/llvm/llvm-project/pull/104594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix(93512): skip alignment checks on incomplete types (PR #94542)
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/94542 Fixes #93512 >From 417093b489f17b0d22701f3c3b990388997c25a0 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 6 Jun 2024 01:55:54 +0300 Subject: [PATCH] fix(93512): skip alignment checks on incomplete types --- clang/docs/ReleaseNotes.rst| 2 ++ clang/lib/Sema/SemaStmt.cpp| 2 +- clang/test/SemaCXX/lambda-as-default-parameter.cpp | 6 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/lambda-as-default-parameter.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 39a9013c75a41..819fe1811ddaf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -840,6 +840,8 @@ Bug Fixes to C++ Support - Fix a crash caused by improper use of ``__array_extent``. (#GH80474) - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). +- Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a + forward-declared class. (#GH93512). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 57465d4a77ac2..56f69dd50f361 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) { // Variables with higher required alignment than their type's ABI // alignment cannot use NRVO. - if (!VD->hasDependentAlignment() && + if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() && Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType)) Info.S = NamedReturnInfo::MoveEligible; diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp b/clang/test/SemaCXX/lambda-as-default-parameter.cpp new file mode 100644 index 0..1f07a7f5644b7 --- /dev/null +++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +struct a; // expected-note {{forward declaration of 'a'}} \ + expected-note {{forward declaration of 'a'}} +void b(a c = [] { return c; }); // expected-error {{initialization of incomplete type 'a'}} \ + expected-error {{variable has incomplete type 'a'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix(92755): clang/include/clang/AST/Redeclarable.h: 4 * Function parameter should be passed by const reference (PR #92963)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/92963 >From f33697ce241213136a8d34c2cc32c68f8f827d6a Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 21 May 2024 22:56:06 +0300 Subject: [PATCH] fix(92755): use const references for operator== and operator!= overloads --- clang/include/clang/AST/Redeclarable.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/AST/Redeclarable.h b/clang/include/clang/AST/Redeclarable.h index 091bb886f2d49..74ccd74ed60d6 100644 --- a/clang/include/clang/AST/Redeclarable.h +++ b/clang/include/clang/AST/Redeclarable.h @@ -281,10 +281,10 @@ class Redeclarable { return tmp; } -friend bool operator==(redecl_iterator x, redecl_iterator y) { +friend bool operator==(const redecl_iterator &x, const redecl_iterator &y) { return x.Current == y.Current; } -friend bool operator!=(redecl_iterator x, redecl_iterator y) { +friend bool operator!=(const redecl_iterator &x, const redecl_iterator &y) { return x.Current != y.Current; } }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][C++23] update constexpr diagnostics for missing return statements per P2448 (PR #94123)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/94123 >From 90eeafc82ee08129c2d290e6382f42ec89680049 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sun, 2 Jun 2024 00:07:35 +0300 Subject: [PATCH 1/3] feat(92583): [C++23] update constexpr diagnostics for missing return statements per P2448 --- clang/lib/Sema/SemaDeclCXX.cpp| 34 --- .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp | 2 +- .../SemaCXX/constant-expression-cxx14.cpp | 2 +- .../constexpr-return-non-void-cxx2b.cpp | 7 4 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 631fd4e354927..d4401a427282c 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -1806,6 +1806,7 @@ static unsigned getRecordDiagFromTagKind(TagTypeKind Tag) { static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl, Stmt *Body, Sema::CheckConstexprKind Kind); +static bool CheckConstexprMissingReturn(Sema &SemaRef, const FunctionDecl *Dcl); // Check whether a function declaration satisfies the requirements of a // constexpr function definition or a constexpr constructor definition. If so, @@ -2411,20 +2412,9 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl, } } else { if (ReturnStmts.empty()) { - // C++1y doesn't require constexpr functions to contain a 'return' - // statement. We still do, unless the return type might be void, because - // otherwise if there's no return statement, the function cannot - // be used in a core constant expression. - bool OK = SemaRef.getLangOpts().CPlusPlus14 && -(Dcl->getReturnType()->isVoidType() || - Dcl->getReturnType()->isDependentType()); switch (Kind) { case Sema::CheckConstexprKind::Diagnose: -SemaRef.Diag(Dcl->getLocation(), - OK ? diag::warn_cxx11_compat_constexpr_body_no_return -: diag::err_constexpr_body_no_return) -<< Dcl->isConsteval(); -if (!OK) +if (!CheckConstexprMissingReturn(SemaRef, Dcl)) return false; break; @@ -2487,6 +2477,26 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl, return true; } +static bool CheckConstexprMissingReturn(Sema &SemaRef, +const FunctionDecl *Dcl) { + bool IsVoidOrDependentType = Dcl->getReturnType()->isVoidType() || + Dcl->getReturnType()->isDependentType(); + + if (SemaRef.getLangOpts().CPlusPlus23 && !IsVoidOrDependentType) +return true; + + // C++1y doesn't require constexpr functions to contain a 'return' + // statement. We still do, unless the return type might be void, because + // otherwise if there's no return statement, the function cannot + // be used in a core constant expression. + bool OK = SemaRef.getLangOpts().CPlusPlus14 && IsVoidOrDependentType; + SemaRef.Diag(Dcl->getLocation(), + OK ? diag::warn_cxx11_compat_constexpr_body_no_return + : diag::err_constexpr_body_no_return) + << Dcl->isConsteval(); + return OK; +} + bool Sema::CheckImmediateEscalatingFunctionDefinition( FunctionDecl *FD, const sema::FunctionScopeInfo *FSI) { if (!getLangOpts().CPlusPlus20 || !FD->isImmediateEscalating()) diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp index 4416c82522649..51990ee4341d2 100644 --- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp @@ -212,7 +212,7 @@ constexpr int ClassDecl3() { return 0; } -constexpr int NoReturn() {} // expected-error {{no return statement in constexpr function}} +constexpr int NoReturn() {} // beforecxx23-error {{no return statement in constexpr function}} constexpr int MultiReturn() { return 0; // beforecxx14-note {{return statement}} return 0; // beforecxx14-warning {{multiple return statements in constexpr function}} diff --git a/clang/test/SemaCXX/constant-expression-cxx14.cpp b/clang/test/SemaCXX/constant-expression-cxx14.cpp index 80a7a2dd31531..70ab5dcd357c1 100644 --- a/clang/test/SemaCXX/constant-expression-cxx14.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx14.cpp @@ -82,7 +82,7 @@ constexpr void k() { // If the return type is not 'void', no return statements => never a constant // expression, so still diagnose that case. -[[noreturn]] constexpr int fn() { // expected-error {{no return statement in constexpr function}} +[[noreturn]] constexpr int fn() { // cxx14_20-error {{no return statement in constexpr function}} fn(); } diff -
[clang] [Clang][C++23] update constexpr diagnostics for missing return statements per P2448 (PR #94123)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/94123 >From 90eeafc82ee08129c2d290e6382f42ec89680049 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sun, 2 Jun 2024 00:07:35 +0300 Subject: [PATCH 1/3] feat(92583): [C++23] update constexpr diagnostics for missing return statements per P2448 --- clang/lib/Sema/SemaDeclCXX.cpp| 34 --- .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp | 2 +- .../SemaCXX/constant-expression-cxx14.cpp | 2 +- .../constexpr-return-non-void-cxx2b.cpp | 7 4 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 631fd4e354927..d4401a427282c 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -1806,6 +1806,7 @@ static unsigned getRecordDiagFromTagKind(TagTypeKind Tag) { static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl, Stmt *Body, Sema::CheckConstexprKind Kind); +static bool CheckConstexprMissingReturn(Sema &SemaRef, const FunctionDecl *Dcl); // Check whether a function declaration satisfies the requirements of a // constexpr function definition or a constexpr constructor definition. If so, @@ -2411,20 +2412,9 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl, } } else { if (ReturnStmts.empty()) { - // C++1y doesn't require constexpr functions to contain a 'return' - // statement. We still do, unless the return type might be void, because - // otherwise if there's no return statement, the function cannot - // be used in a core constant expression. - bool OK = SemaRef.getLangOpts().CPlusPlus14 && -(Dcl->getReturnType()->isVoidType() || - Dcl->getReturnType()->isDependentType()); switch (Kind) { case Sema::CheckConstexprKind::Diagnose: -SemaRef.Diag(Dcl->getLocation(), - OK ? diag::warn_cxx11_compat_constexpr_body_no_return -: diag::err_constexpr_body_no_return) -<< Dcl->isConsteval(); -if (!OK) +if (!CheckConstexprMissingReturn(SemaRef, Dcl)) return false; break; @@ -2487,6 +2477,26 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl, return true; } +static bool CheckConstexprMissingReturn(Sema &SemaRef, +const FunctionDecl *Dcl) { + bool IsVoidOrDependentType = Dcl->getReturnType()->isVoidType() || + Dcl->getReturnType()->isDependentType(); + + if (SemaRef.getLangOpts().CPlusPlus23 && !IsVoidOrDependentType) +return true; + + // C++1y doesn't require constexpr functions to contain a 'return' + // statement. We still do, unless the return type might be void, because + // otherwise if there's no return statement, the function cannot + // be used in a core constant expression. + bool OK = SemaRef.getLangOpts().CPlusPlus14 && IsVoidOrDependentType; + SemaRef.Diag(Dcl->getLocation(), + OK ? diag::warn_cxx11_compat_constexpr_body_no_return + : diag::err_constexpr_body_no_return) + << Dcl->isConsteval(); + return OK; +} + bool Sema::CheckImmediateEscalatingFunctionDefinition( FunctionDecl *FD, const sema::FunctionScopeInfo *FSI) { if (!getLangOpts().CPlusPlus20 || !FD->isImmediateEscalating()) diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp index 4416c82522649..51990ee4341d2 100644 --- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp @@ -212,7 +212,7 @@ constexpr int ClassDecl3() { return 0; } -constexpr int NoReturn() {} // expected-error {{no return statement in constexpr function}} +constexpr int NoReturn() {} // beforecxx23-error {{no return statement in constexpr function}} constexpr int MultiReturn() { return 0; // beforecxx14-note {{return statement}} return 0; // beforecxx14-warning {{multiple return statements in constexpr function}} diff --git a/clang/test/SemaCXX/constant-expression-cxx14.cpp b/clang/test/SemaCXX/constant-expression-cxx14.cpp index 80a7a2dd31531..70ab5dcd357c1 100644 --- a/clang/test/SemaCXX/constant-expression-cxx14.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx14.cpp @@ -82,7 +82,7 @@ constexpr void k() { // If the return type is not 'void', no return statements => never a constant // expression, so still diagnose that case. -[[noreturn]] constexpr int fn() { // expected-error {{no return statement in constexpr function}} +[[noreturn]] constexpr int fn() { // cxx14_20-error {{no return statement in constexpr function}} fn(); } diff -
[clang] fix(93512): skip alignment checks on incomplete types (PR #94542)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/94542 >From 417093b489f17b0d22701f3c3b990388997c25a0 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 6 Jun 2024 01:55:54 +0300 Subject: [PATCH] fix(93512): skip alignment checks on incomplete types --- clang/docs/ReleaseNotes.rst| 2 ++ clang/lib/Sema/SemaStmt.cpp| 2 +- clang/test/SemaCXX/lambda-as-default-parameter.cpp | 6 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/lambda-as-default-parameter.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 39a9013c75a41..819fe1811ddaf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -840,6 +840,8 @@ Bug Fixes to C++ Support - Fix a crash caused by improper use of ``__array_extent``. (#GH80474) - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). +- Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a + forward-declared class. (#GH93512). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 57465d4a77ac2..56f69dd50f361 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) { // Variables with higher required alignment than their type's ABI // alignment cannot use NRVO. - if (!VD->hasDependentAlignment() && + if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() && Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType)) Info.S = NamedReturnInfo::MoveEligible; diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp b/clang/test/SemaCXX/lambda-as-default-parameter.cpp new file mode 100644 index 0..1f07a7f5644b7 --- /dev/null +++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +struct a; // expected-note {{forward declaration of 'a'}} \ + expected-note {{forward declaration of 'a'}} +void b(a c = [] { return c; }); // expected-error {{initialization of incomplete type 'a'}} \ + expected-error {{variable has incomplete type 'a'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix(93512): skip alignment checks on incomplete types (PR #94542)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/94542 >From 417093b489f17b0d22701f3c3b990388997c25a0 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 6 Jun 2024 01:55:54 +0300 Subject: [PATCH] fix(93512): skip alignment checks on incomplete types --- clang/docs/ReleaseNotes.rst| 2 ++ clang/lib/Sema/SemaStmt.cpp| 2 +- clang/test/SemaCXX/lambda-as-default-parameter.cpp | 6 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/lambda-as-default-parameter.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 39a9013c75a41..819fe1811ddaf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -840,6 +840,8 @@ Bug Fixes to C++ Support - Fix a crash caused by improper use of ``__array_extent``. (#GH80474) - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). +- Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a + forward-declared class. (#GH93512). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 57465d4a77ac2..56f69dd50f361 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) { // Variables with higher required alignment than their type's ABI // alignment cannot use NRVO. - if (!VD->hasDependentAlignment() && + if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() && Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType)) Info.S = NamedReturnInfo::MoveEligible; diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp b/clang/test/SemaCXX/lambda-as-default-parameter.cpp new file mode 100644 index 0..1f07a7f5644b7 --- /dev/null +++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +struct a; // expected-note {{forward declaration of 'a'}} \ + expected-note {{forward declaration of 'a'}} +void b(a c = [] { return c; }); // expected-error {{initialization of incomplete type 'a'}} \ + expected-error {{variable has incomplete type 'a'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][C++23] update constexpr diagnostics for missing return statements per P2448 (PR #94123)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/94123 >From 90eeafc82ee08129c2d290e6382f42ec89680049 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sun, 2 Jun 2024 00:07:35 +0300 Subject: [PATCH 1/3] feat(92583): [C++23] update constexpr diagnostics for missing return statements per P2448 --- clang/lib/Sema/SemaDeclCXX.cpp| 34 --- .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp | 2 +- .../SemaCXX/constant-expression-cxx14.cpp | 2 +- .../constexpr-return-non-void-cxx2b.cpp | 7 4 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 631fd4e354927..d4401a427282c 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -1806,6 +1806,7 @@ static unsigned getRecordDiagFromTagKind(TagTypeKind Tag) { static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl, Stmt *Body, Sema::CheckConstexprKind Kind); +static bool CheckConstexprMissingReturn(Sema &SemaRef, const FunctionDecl *Dcl); // Check whether a function declaration satisfies the requirements of a // constexpr function definition or a constexpr constructor definition. If so, @@ -2411,20 +2412,9 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl, } } else { if (ReturnStmts.empty()) { - // C++1y doesn't require constexpr functions to contain a 'return' - // statement. We still do, unless the return type might be void, because - // otherwise if there's no return statement, the function cannot - // be used in a core constant expression. - bool OK = SemaRef.getLangOpts().CPlusPlus14 && -(Dcl->getReturnType()->isVoidType() || - Dcl->getReturnType()->isDependentType()); switch (Kind) { case Sema::CheckConstexprKind::Diagnose: -SemaRef.Diag(Dcl->getLocation(), - OK ? diag::warn_cxx11_compat_constexpr_body_no_return -: diag::err_constexpr_body_no_return) -<< Dcl->isConsteval(); -if (!OK) +if (!CheckConstexprMissingReturn(SemaRef, Dcl)) return false; break; @@ -2487,6 +2477,26 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl, return true; } +static bool CheckConstexprMissingReturn(Sema &SemaRef, +const FunctionDecl *Dcl) { + bool IsVoidOrDependentType = Dcl->getReturnType()->isVoidType() || + Dcl->getReturnType()->isDependentType(); + + if (SemaRef.getLangOpts().CPlusPlus23 && !IsVoidOrDependentType) +return true; + + // C++1y doesn't require constexpr functions to contain a 'return' + // statement. We still do, unless the return type might be void, because + // otherwise if there's no return statement, the function cannot + // be used in a core constant expression. + bool OK = SemaRef.getLangOpts().CPlusPlus14 && IsVoidOrDependentType; + SemaRef.Diag(Dcl->getLocation(), + OK ? diag::warn_cxx11_compat_constexpr_body_no_return + : diag::err_constexpr_body_no_return) + << Dcl->isConsteval(); + return OK; +} + bool Sema::CheckImmediateEscalatingFunctionDefinition( FunctionDecl *FD, const sema::FunctionScopeInfo *FSI) { if (!getLangOpts().CPlusPlus20 || !FD->isImmediateEscalating()) diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp index 4416c82522649..51990ee4341d2 100644 --- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp @@ -212,7 +212,7 @@ constexpr int ClassDecl3() { return 0; } -constexpr int NoReturn() {} // expected-error {{no return statement in constexpr function}} +constexpr int NoReturn() {} // beforecxx23-error {{no return statement in constexpr function}} constexpr int MultiReturn() { return 0; // beforecxx14-note {{return statement}} return 0; // beforecxx14-warning {{multiple return statements in constexpr function}} diff --git a/clang/test/SemaCXX/constant-expression-cxx14.cpp b/clang/test/SemaCXX/constant-expression-cxx14.cpp index 80a7a2dd31531..70ab5dcd357c1 100644 --- a/clang/test/SemaCXX/constant-expression-cxx14.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx14.cpp @@ -82,7 +82,7 @@ constexpr void k() { // If the return type is not 'void', no return statements => never a constant // expression, so still diagnose that case. -[[noreturn]] constexpr int fn() { // expected-error {{no return statement in constexpr function}} +[[noreturn]] constexpr int fn() { // cxx14_20-error {{no return statement in constexpr function}} fn(); } diff -
[clang] [Clang][C++23] update constexpr diagnostics for missing return statements per P2448 (PR #94123)
a-tarasyuk wrote: @tbaederr Yes, I do. I don't have access to merge… https://github.com/llvm/llvm-project/pull/94123 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/95479 Fixes #95366 >From d66fdcbe0a56e17dbd25e6d2ed5bdcce1970fdea Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 01:26:34 +0300 Subject: [PATCH] fix(95366): enhance cast operation safety with LValue validation --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp| 3 +++ clang/test/Sema/integral-to-ptr.c | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 clang/test/Sema/integral-to-ptr.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8c2f737836a9d..77906360b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,6 +847,7 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). +- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7178f081d9cf3..08bee806f172f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + if (!Value.isLValue()) +return false; + // Cast is of an lvalue, no need to change value. Result.setFrom(Info.Ctx, Value); return true; diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c new file mode 100644 index 0..99f83c3e52057 --- /dev/null +++ b/clang/test/Sema/integral-to-ptr.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 + +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/95479 >From d66fdcbe0a56e17dbd25e6d2ed5bdcce1970fdea Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 01:26:34 +0300 Subject: [PATCH 1/2] fix(95366): enhance cast operation safety with LValue validation --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp| 3 +++ clang/test/Sema/integral-to-ptr.c | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 clang/test/Sema/integral-to-ptr.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8c2f737836a9d..77906360b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,6 +847,7 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). +- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7178f081d9cf3..08bee806f172f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + if (!Value.isLValue()) +return false; + // Cast is of an lvalue, no need to change value. Result.setFrom(Info.Ctx, Value); return true; diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c new file mode 100644 index 0..99f83c3e52057 --- /dev/null +++ b/clang/test/Sema/integral-to-ptr.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 + +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} >From 8ce09ce067b22346378d6f108e4fa1786bc460ef Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 08:50:03 +0300 Subject: [PATCH 2/2] update test expectations --- clang/test/Sema/integral-to-ptr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c index 99f83c3e52057..b8ab4cb79820d 100644 --- a/clang/test/Sema/integral-to-ptr.c +++ b/clang/test/Sema/integral-to-ptr.c @@ -1,3 +1,3 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 -int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/95479 >From d66fdcbe0a56e17dbd25e6d2ed5bdcce1970fdea Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 01:26:34 +0300 Subject: [PATCH 1/4] fix(95366): enhance cast operation safety with LValue validation --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp| 3 +++ clang/test/Sema/integral-to-ptr.c | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 clang/test/Sema/integral-to-ptr.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8c2f737836a9d..77906360b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,6 +847,7 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). +- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7178f081d9cf3..08bee806f172f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + if (!Value.isLValue()) +return false; + // Cast is of an lvalue, no need to change value. Result.setFrom(Info.Ctx, Value); return true; diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c new file mode 100644 index 0..99f83c3e52057 --- /dev/null +++ b/clang/test/Sema/integral-to-ptr.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 + +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} >From 8ce09ce067b22346378d6f108e4fa1786bc460ef Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 08:50:03 +0300 Subject: [PATCH 2/4] update test expectations --- clang/test/Sema/integral-to-ptr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c index 99f83c3e52057..b8ab4cb79820d 100644 --- a/clang/test/Sema/integral-to-ptr.c +++ b/clang/test/Sema/integral-to-ptr.c @@ -1,3 +1,3 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 -int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer}} >From 319b315d57487811399c113e259c0083a50ea0a9 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 17:58:47 +0300 Subject: [PATCH 3/4] add detailed comment --- clang/lib/AST/ExprConstant.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 08bee806f172f..2b7a05664114f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + // In rare instances, the value isn't an lvalue. + // For example, when the value is the difference between the addresses of two labels. + // We reject that as a constant expression because we can't compute a valid offset to convert into a pointer. if (!Value.isLValue()) return false; >From 6e5d004706826eb1c65a813d6ef9cc3de55b12ba Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 17:59:28 +0300 Subject: [PATCH 4/4] update changelog message --- clang/docs/ReleaseNotes.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 77906360b..efd17d8f9a089 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,7 +847,8 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). -- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). +- Fixed a failed assertion when attempting to convert an integer representing the difference + between the addresses of two labels (a GNU extension) to a pointer within a constant expression. (GH95366). Bug Fixes to AST Handling ^ ___ cfe-commits mailing list cfe-commi
[clang] [Clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
https://github.com/a-tarasyuk edited https://github.com/llvm/llvm-project/pull/95479 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
@@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + if (!Value.isLValue()) a-tarasyuk wrote: @AaronBallman Thanks for the feedback 👍. I've added all the requested changes. https://github.com/llvm/llvm-project/pull/95479 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/95479 >From af6ba760826467a3ce7b7a41c18f194528a1cede Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 01:26:34 +0300 Subject: [PATCH 1/4] [Clang] fix(95366): enhance cast operation safety with LValue validation --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp| 3 +++ clang/test/Sema/integral-to-ptr.c | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 clang/test/Sema/integral-to-ptr.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8c2f737836a9d..77906360b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,6 +847,7 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). +- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7178f081d9cf3..08bee806f172f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + if (!Value.isLValue()) +return false; + // Cast is of an lvalue, no need to change value. Result.setFrom(Info.Ctx, Value); return true; diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c new file mode 100644 index 0..99f83c3e52057 --- /dev/null +++ b/clang/test/Sema/integral-to-ptr.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 + +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} >From edc0f2e55883bcd47e6d6aee73730fe0bd8014c0 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 08:50:03 +0300 Subject: [PATCH 2/4] update test expectations --- clang/test/Sema/integral-to-ptr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c index 99f83c3e52057..b8ab4cb79820d 100644 --- a/clang/test/Sema/integral-to-ptr.c +++ b/clang/test/Sema/integral-to-ptr.c @@ -1,3 +1,3 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 -int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer}} >From e40d4c5da45b25775b55ebf9819992f3510b22dd Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 18:16:34 +0300 Subject: [PATCH 3/4] add detailed comment --- clang/lib/AST/ExprConstant.cpp | 4 1 file changed, 4 insertions(+) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 08bee806f172f..712c3062eb9ac 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,10 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + // In rare instances, the value isn't an lvalue. + // For example, when the value is the difference between the addresses of + // two labels. We reject that as a constant expression because we can't + // compute a valid offset to convert into a pointer. if (!Value.isLValue()) return false; >From 4b525ec660c07637edd843bc921c6bac77762d99 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 18:16:58 +0300 Subject: [PATCH 4/4] update changelog message --- clang/docs/ReleaseNotes.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 77906360b..efd17d8f9a089 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,7 +847,8 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). -- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). +- Fixed a failed assertion when attempting to convert an integer representing the difference + between the addresses of two labels (a GNU extension) to a pointer within a constant expression. (GH95366). Bug Fixes to AST Handling ^ ___ cfe-commits mail
[clang] [Clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/95479 >From af6ba760826467a3ce7b7a41c18f194528a1cede Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 01:26:34 +0300 Subject: [PATCH 1/4] [Clang] fix(95366): enhance cast operation safety with LValue validation --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp| 3 +++ clang/test/Sema/integral-to-ptr.c | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 clang/test/Sema/integral-to-ptr.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8c2f737836a9d..77906360b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,6 +847,7 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). +- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7178f081d9cf3..08bee806f172f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + if (!Value.isLValue()) +return false; + // Cast is of an lvalue, no need to change value. Result.setFrom(Info.Ctx, Value); return true; diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c new file mode 100644 index 0..99f83c3e52057 --- /dev/null +++ b/clang/test/Sema/integral-to-ptr.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 + +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} >From edc0f2e55883bcd47e6d6aee73730fe0bd8014c0 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 08:50:03 +0300 Subject: [PATCH 2/4] update test expectations --- clang/test/Sema/integral-to-ptr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c index 99f83c3e52057..b8ab4cb79820d 100644 --- a/clang/test/Sema/integral-to-ptr.c +++ b/clang/test/Sema/integral-to-ptr.c @@ -1,3 +1,3 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 -int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer}} >From e40d4c5da45b25775b55ebf9819992f3510b22dd Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 18:16:34 +0300 Subject: [PATCH 3/4] add detailed comment --- clang/lib/AST/ExprConstant.cpp | 4 1 file changed, 4 insertions(+) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 08bee806f172f..712c3062eb9ac 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,10 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + // In rare instances, the value isn't an lvalue. + // For example, when the value is the difference between the addresses of + // two labels. We reject that as a constant expression because we can't + // compute a valid offset to convert into a pointer. if (!Value.isLValue()) return false; >From 4b525ec660c07637edd843bc921c6bac77762d99 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 18:16:58 +0300 Subject: [PATCH 4/4] update changelog message --- clang/docs/ReleaseNotes.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 77906360b..efd17d8f9a089 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,7 +847,8 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). -- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). +- Fixed a failed assertion when attempting to convert an integer representing the difference + between the addresses of two labels (a GNU extension) to a pointer within a constant expression. (GH95366). Bug Fixes to AST Handling ^ ___ cfe-commits mail
[clang] fix(93512): skip alignment checks on incomplete types (PR #94542)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/94542 >From 6044e1bcef93dd3c0bb4d1095a496afd6f17677a Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 6 Jun 2024 01:55:54 +0300 Subject: [PATCH] [Clang] fix(93512): skip alignment checks on incomplete types --- clang/docs/ReleaseNotes.rst| 2 ++ clang/lib/Sema/SemaStmt.cpp| 2 +- clang/test/SemaCXX/lambda-as-default-parameter.cpp | 6 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/lambda-as-default-parameter.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 39a9013c75a41..819fe1811ddaf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -840,6 +840,8 @@ Bug Fixes to C++ Support - Fix a crash caused by improper use of ``__array_extent``. (#GH80474) - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). +- Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a + forward-declared class. (#GH93512). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 57465d4a77ac2..56f69dd50f361 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) { // Variables with higher required alignment than their type's ABI // alignment cannot use NRVO. - if (!VD->hasDependentAlignment() && + if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() && Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType)) Info.S = NamedReturnInfo::MoveEligible; diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp b/clang/test/SemaCXX/lambda-as-default-parameter.cpp new file mode 100644 index 0..1f07a7f5644b7 --- /dev/null +++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +struct a; // expected-note {{forward declaration of 'a'}} \ + expected-note {{forward declaration of 'a'}} +void b(a c = [] { return c; }); // expected-error {{initialization of incomplete type 'a'}} \ + expected-error {{variable has incomplete type 'a'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/95479 >From af6ba760826467a3ce7b7a41c18f194528a1cede Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 01:26:34 +0300 Subject: [PATCH 1/4] [Clang] fix(95366): enhance cast operation safety with LValue validation --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp| 3 +++ clang/test/Sema/integral-to-ptr.c | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 clang/test/Sema/integral-to-ptr.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8c2f737836a9d..77906360b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,6 +847,7 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). +- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7178f081d9cf3..08bee806f172f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + if (!Value.isLValue()) +return false; + // Cast is of an lvalue, no need to change value. Result.setFrom(Info.Ctx, Value); return true; diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c new file mode 100644 index 0..99f83c3e52057 --- /dev/null +++ b/clang/test/Sema/integral-to-ptr.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 + +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} >From edc0f2e55883bcd47e6d6aee73730fe0bd8014c0 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 08:50:03 +0300 Subject: [PATCH 2/4] update test expectations --- clang/test/Sema/integral-to-ptr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c index 99f83c3e52057..b8ab4cb79820d 100644 --- a/clang/test/Sema/integral-to-ptr.c +++ b/clang/test/Sema/integral-to-ptr.c @@ -1,3 +1,3 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 -int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer}} >From e40d4c5da45b25775b55ebf9819992f3510b22dd Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 18:16:34 +0300 Subject: [PATCH 3/4] add detailed comment --- clang/lib/AST/ExprConstant.cpp | 4 1 file changed, 4 insertions(+) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 08bee806f172f..712c3062eb9ac 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,10 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + // In rare instances, the value isn't an lvalue. + // For example, when the value is the difference between the addresses of + // two labels. We reject that as a constant expression because we can't + // compute a valid offset to convert into a pointer. if (!Value.isLValue()) return false; >From 4b525ec660c07637edd843bc921c6bac77762d99 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 18:16:58 +0300 Subject: [PATCH 4/4] update changelog message --- clang/docs/ReleaseNotes.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 77906360b..efd17d8f9a089 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,7 +847,8 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). -- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). +- Fixed a failed assertion when attempting to convert an integer representing the difference + between the addresses of two labels (a GNU extension) to a pointer within a constant expression. (GH95366). Bug Fixes to AST Handling ^ ___ cfe-commits mail
[clang] [clang] fix(92759): clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp: 6 * Function parameter should be passed by const reference (PR #93252)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/93252 >From 994791b862dfecf7bb370f32834645011e69137d Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 24 May 2024 01:39:35 +0300 Subject: [PATCH 1/2] fix(92759): use const references --- .../Frontend/Rewrite/RewriteModernObjC.cpp| 31 ++- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp index 6ae955a2380b7..dd8ee117f60c6 100644 --- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -465,13 +465,14 @@ namespace { std::string SynthesizeByrefCopyDestroyHelper(VarDecl *VD, int flag); std::string SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, - StringRef funcName, std::string Tag); + StringRef funcName, const std::string &Tag); std::string SynthesizeBlockFunc(BlockExpr *CE, int i, - StringRef funcName, std::string Tag); + StringRef funcName, const std::string &Tag); std::string SynthesizeBlockImpl(BlockExpr *CE, -std::string Tag, std::string Desc); -std::string SynthesizeBlockDescriptor(std::string DescTag, - std::string ImplTag, +const std::string &Tag, +const std::string &Desc); +std::string SynthesizeBlockDescriptor(const std::string &DescTag, + const std::string &ImplTag, int i, StringRef funcName, unsigned hasCopy); Stmt *SynthesizeBlockCall(CallExpr *Exp, const Expr* BlockExp); @@ -4037,7 +4038,7 @@ static bool HasLocalVariableExternalStorage(ValueDecl *VD) { std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, StringRef funcName, - std::string Tag) { + const std::string &Tag) { const FunctionType *AFT = CE->getFunctionType(); QualType RT = AFT->getReturnType(); std::string StructRef = "struct " + Tag; @@ -4132,8 +4133,8 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, } std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, - StringRef funcName, - std::string Tag) { + StringRef funcName, + const std::string &Tag) { std::string StructRef = "struct " + Tag; std::string S = "static void __"; @@ -4175,8 +4176,9 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, return S; } -std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, - std::string Desc) { +std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, + const std::string &Tag, + const std::string &Desc) { std::string S = "\nstruct " + Tag; std::string Constructor = " " + Tag; @@ -4290,10 +4292,11 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Ta return S; } -std::string RewriteModernObjC::SynthesizeBlockDescriptor(std::string DescTag, - std::string ImplTag, int i, - StringRef FunName, - unsigned hasCopy) { +std::string RewriteModernObjC::SynthesizeBlockDescriptor(const std::string &DescTag, + const std::string &ImplTag, + int i, + StringRef FunName, + unsigned hasCopy) { std::string S = "\nstatic struct " + DescTag; S += " {\n size_t reserved;\n"; >From 2e23c5b24df05e4aec6dadc2d4d7ccf21587e51d Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 24 May 2024 01:45:13 +0300 Subject: [PATCH 2/2] fix formatting --- .../Frontend/Rewrite/RewriteModernObjC.cpp| 28 --- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp index dd8ee117f60c6..764cdc6f07cf6 100644 --- a/clang/lib/Frontend/Rewrit
[clang] fix(93512): skip alignment checks on incomplete types (PR #94542)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/94542 >From da4df73607a9edefc8db721818eff50e974a0637 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 6 Jun 2024 01:55:54 +0300 Subject: [PATCH] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument --- clang/docs/ReleaseNotes.rst| 2 ++ clang/lib/Sema/SemaStmt.cpp| 2 +- clang/test/SemaCXX/lambda-as-default-parameter.cpp | 6 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/lambda-as-default-parameter.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 39a9013c75a41..819fe1811ddaf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -840,6 +840,8 @@ Bug Fixes to C++ Support - Fix a crash caused by improper use of ``__array_extent``. (#GH80474) - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). +- Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a + forward-declared class. (#GH93512). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 57465d4a77ac2..56f69dd50f361 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) { // Variables with higher required alignment than their type's ABI // alignment cannot use NRVO. - if (!VD->hasDependentAlignment() && + if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() && Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType)) Info.S = NamedReturnInfo::MoveEligible; diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp b/clang/test/SemaCXX/lambda-as-default-parameter.cpp new file mode 100644 index 0..1f07a7f5644b7 --- /dev/null +++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +struct a; // expected-note {{forward declaration of 'a'}} \ + expected-note {{forward declaration of 'a'}} +void b(a c = [] { return c; }); // expected-error {{initialization of incomplete type 'a'}} \ + expected-error {{variable has incomplete type 'a'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument (PR #94542)
https://github.com/a-tarasyuk edited https://github.com/llvm/llvm-project/pull/94542 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix(95366): enhance cast operation safety with LValue validation (PR #95479)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/95479 >From 125d9cdd617d6415ef24eb785fe22705149f2d01 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 01:26:34 +0300 Subject: [PATCH 1/4] [Clang] disallow non-lvalue values in constant expressions to prevent invalid pointer offset computation --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp| 3 +++ clang/test/Sema/integral-to-ptr.c | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 clang/test/Sema/integral-to-ptr.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8c2f737836a9d..77906360b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,6 +847,7 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). +- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7178f081d9cf3..08bee806f172f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + if (!Value.isLValue()) +return false; + // Cast is of an lvalue, no need to change value. Result.setFrom(Info.Ctx, Value); return true; diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c new file mode 100644 index 0..99f83c3e52057 --- /dev/null +++ b/clang/test/Sema/integral-to-ptr.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 + +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} >From b73cf0659a115f29c7b224a8f89ab519dac01a13 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 08:50:03 +0300 Subject: [PATCH 2/4] update test expectations --- clang/test/Sema/integral-to-ptr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c index 99f83c3e52057..b8ab4cb79820d 100644 --- a/clang/test/Sema/integral-to-ptr.c +++ b/clang/test/Sema/integral-to-ptr.c @@ -1,3 +1,3 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 -int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer}} >From 78fc56a0aab96984760a3874e06e51259b599bd5 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 18:16:34 +0300 Subject: [PATCH 3/4] add detailed comment --- clang/lib/AST/ExprConstant.cpp | 4 1 file changed, 4 insertions(+) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 08bee806f172f..712c3062eb9ac 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,10 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + // In rare instances, the value isn't an lvalue. + // For example, when the value is the difference between the addresses of + // two labels. We reject that as a constant expression because we can't + // compute a valid offset to convert into a pointer. if (!Value.isLValue()) return false; >From 7e3af56b7fbb43041f81c982cee712f516ecc6f1 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 18:16:58 +0300 Subject: [PATCH 4/4] update changelog message --- clang/docs/ReleaseNotes.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 77906360b..efd17d8f9a089 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,7 +847,8 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). -- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). +- Fixed a failed assertion when attempting to convert an integer representing the difference + between the addresses of two labels (a GNU extension) to a pointer within a constant expression. (GH95366). Bug Fixes to AST Handling ^
[clang] [Clang] disallow non-lvalue values in constant expressions to prevent invalid pointer offset computation (PR #95479)
https://github.com/a-tarasyuk edited https://github.com/llvm/llvm-project/pull/95479 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow non-lvalue values in constant expressions to prevent invalid pointer offset computation (PR #95479)
a-tarasyuk wrote: @cor3ntin I've updated the commit message/PR title. What do you think? https://github.com/llvm/llvm-project/pull/95479 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix(92759): clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp: 6 * Function parameter should be passed by const reference (PR #93252)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/93252 >From 8788c301adb367d34aafd3d472309ed061f0e658 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 24 May 2024 01:39:35 +0300 Subject: [PATCH] [Clang] improve RewriteModernObjC code quality by using const reference for function parameters --- .../Frontend/Rewrite/RewriteModernObjC.cpp| 31 ++- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp index 6ae955a2380b7..dd8ee117f60c6 100644 --- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -465,13 +465,14 @@ namespace { std::string SynthesizeByrefCopyDestroyHelper(VarDecl *VD, int flag); std::string SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, - StringRef funcName, std::string Tag); + StringRef funcName, const std::string &Tag); std::string SynthesizeBlockFunc(BlockExpr *CE, int i, - StringRef funcName, std::string Tag); + StringRef funcName, const std::string &Tag); std::string SynthesizeBlockImpl(BlockExpr *CE, -std::string Tag, std::string Desc); -std::string SynthesizeBlockDescriptor(std::string DescTag, - std::string ImplTag, +const std::string &Tag, +const std::string &Desc); +std::string SynthesizeBlockDescriptor(const std::string &DescTag, + const std::string &ImplTag, int i, StringRef funcName, unsigned hasCopy); Stmt *SynthesizeBlockCall(CallExpr *Exp, const Expr* BlockExp); @@ -4037,7 +4038,7 @@ static bool HasLocalVariableExternalStorage(ValueDecl *VD) { std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, StringRef funcName, - std::string Tag) { + const std::string &Tag) { const FunctionType *AFT = CE->getFunctionType(); QualType RT = AFT->getReturnType(); std::string StructRef = "struct " + Tag; @@ -4132,8 +4133,8 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, } std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, - StringRef funcName, - std::string Tag) { + StringRef funcName, + const std::string &Tag) { std::string StructRef = "struct " + Tag; std::string S = "static void __"; @@ -4175,8 +4176,9 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, return S; } -std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, - std::string Desc) { +std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, + const std::string &Tag, + const std::string &Desc) { std::string S = "\nstruct " + Tag; std::string Constructor = " " + Tag; @@ -4290,10 +4292,11 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Ta return S; } -std::string RewriteModernObjC::SynthesizeBlockDescriptor(std::string DescTag, - std::string ImplTag, int i, - StringRef FunName, - unsigned hasCopy) { +std::string RewriteModernObjC::SynthesizeBlockDescriptor(const std::string &DescTag, + const std::string &ImplTag, + int i, + StringRef FunName, + unsigned hasCopy) { std::string S = "\nstatic struct " + DescTag; S += " {\n size_t reserved;\n"; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] improve RewriteModernObjC code quality by using const reference for function parameters (PR #93252)
https://github.com/a-tarasyuk edited https://github.com/llvm/llvm-project/pull/93252 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix(92755): clang/include/clang/AST/Redeclarable.h: 4 * Function parameter should be passed by const reference (PR #92963)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/92963 >From c94e7cbe04c0f23094a7f2a3d2a7cbd103750301 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 21 May 2024 22:56:06 +0300 Subject: [PATCH] [Clang] use const references for function parameters in operator== and operator!= overloads in Redeclarable.h --- clang/include/clang/AST/Redeclarable.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/AST/Redeclarable.h b/clang/include/clang/AST/Redeclarable.h index 091bb886f2d49..74ccd74ed60d6 100644 --- a/clang/include/clang/AST/Redeclarable.h +++ b/clang/include/clang/AST/Redeclarable.h @@ -281,10 +281,10 @@ class Redeclarable { return tmp; } -friend bool operator==(redecl_iterator x, redecl_iterator y) { +friend bool operator==(const redecl_iterator &x, const redecl_iterator &y) { return x.Current == y.Current; } -friend bool operator!=(redecl_iterator x, redecl_iterator y) { +friend bool operator!=(const redecl_iterator &x, const redecl_iterator &y) { return x.Current != y.Current; } }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] use const references for function parameters in operator== and operator!= overloads in Redeclarable.h (PR #92963)
https://github.com/a-tarasyuk edited https://github.com/llvm/llvm-project/pull/92963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] improve RewriteModernObjC code quality by using const reference for function parameters (PR #93252)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/93252 >From d160eb6c869d41ac64ff27442d2f8d964beb3ebf Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 24 May 2024 01:39:35 +0300 Subject: [PATCH] [Clang] improve RewriteModernObjC code quality by using const reference for function parameters --- .../Frontend/Rewrite/RewriteModernObjC.cpp| 37 +-- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp index 6ae955a2380b7..764cdc6f07cf6 100644 --- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -465,15 +465,15 @@ namespace { std::string SynthesizeByrefCopyDestroyHelper(VarDecl *VD, int flag); std::string SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, - StringRef funcName, std::string Tag); -std::string SynthesizeBlockFunc(BlockExpr *CE, int i, - StringRef funcName, std::string Tag); -std::string SynthesizeBlockImpl(BlockExpr *CE, -std::string Tag, std::string Desc); -std::string SynthesizeBlockDescriptor(std::string DescTag, - std::string ImplTag, - int i, StringRef funcName, - unsigned hasCopy); + StringRef funcName, + const std::string &Tag); +std::string SynthesizeBlockFunc(BlockExpr *CE, int i, StringRef funcName, +const std::string &Tag); +std::string SynthesizeBlockImpl(BlockExpr *CE, const std::string &Tag, +const std::string &Desc); +std::string SynthesizeBlockDescriptor(const std::string &DescTag, + const std::string &ImplTag, int i, + StringRef funcName, unsigned hasCopy); Stmt *SynthesizeBlockCall(CallExpr *Exp, const Expr* BlockExp); void SynthesizeBlockLiterals(SourceLocation FunLocStart, StringRef FunName); @@ -4037,7 +4037,7 @@ static bool HasLocalVariableExternalStorage(ValueDecl *VD) { std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, StringRef funcName, - std::string Tag) { + const std::string &Tag) { const FunctionType *AFT = CE->getFunctionType(); QualType RT = AFT->getReturnType(); std::string StructRef = "struct " + Tag; @@ -4131,9 +4131,8 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, return S; } -std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, - StringRef funcName, - std::string Tag) { +std::string RewriteModernObjC::SynthesizeBlockHelperFuncs( +BlockExpr *CE, int i, StringRef funcName, const std::string &Tag) { std::string StructRef = "struct " + Tag; std::string S = "static void __"; @@ -4175,8 +4174,9 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, return S; } -std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, - std::string Desc) { +std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, + const std::string &Tag, + const std::string &Desc) { std::string S = "\nstruct " + Tag; std::string Constructor = " " + Tag; @@ -4290,10 +4290,9 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Ta return S; } -std::string RewriteModernObjC::SynthesizeBlockDescriptor(std::string DescTag, - std::string ImplTag, int i, - StringRef FunName, - unsigned hasCopy) { +std::string RewriteModernObjC::SynthesizeBlockDescriptor( +const std::string &DescTag, const std::string &ImplTag, int i, +StringRef FunName, unsigned hasCopy) { std::string S = "\nstatic struct " + DescTag; S += " {\n size_t reserved;\n"; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow non-lvalue values in constant expressions to prevent invalid pointer offset computation (PR #95479)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/95479 >From 125d9cdd617d6415ef24eb785fe22705149f2d01 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 01:26:34 +0300 Subject: [PATCH 1/5] [Clang] disallow non-lvalue values in constant expressions to prevent invalid pointer offset computation --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp| 3 +++ clang/test/Sema/integral-to-ptr.c | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 clang/test/Sema/integral-to-ptr.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8c2f737836a9d..77906360b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,6 +847,7 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). +- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7178f081d9cf3..08bee806f172f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + if (!Value.isLValue()) +return false; + // Cast is of an lvalue, no need to change value. Result.setFrom(Info.Ctx, Value); return true; diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c new file mode 100644 index 0..99f83c3e52057 --- /dev/null +++ b/clang/test/Sema/integral-to-ptr.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 + +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} >From b73cf0659a115f29c7b224a8f89ab519dac01a13 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 08:50:03 +0300 Subject: [PATCH 2/5] update test expectations --- clang/test/Sema/integral-to-ptr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c index 99f83c3e52057..b8ab4cb79820d 100644 --- a/clang/test/Sema/integral-to-ptr.c +++ b/clang/test/Sema/integral-to-ptr.c @@ -1,3 +1,3 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 -int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer}} >From 78fc56a0aab96984760a3874e06e51259b599bd5 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 18:16:34 +0300 Subject: [PATCH 3/5] add detailed comment --- clang/lib/AST/ExprConstant.cpp | 4 1 file changed, 4 insertions(+) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 08bee806f172f..712c3062eb9ac 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,10 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + // In rare instances, the value isn't an lvalue. + // For example, when the value is the difference between the addresses of + // two labels. We reject that as a constant expression because we can't + // compute a valid offset to convert into a pointer. if (!Value.isLValue()) return false; >From 7e3af56b7fbb43041f81c982cee712f516ecc6f1 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 18:16:58 +0300 Subject: [PATCH 4/5] update changelog message --- clang/docs/ReleaseNotes.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 77906360b..efd17d8f9a089 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,7 +847,8 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). -- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). +- Fixed a failed assertion when attempting to convert an integer representing the difference + between the addresses of two labels (a GNU extension) to a pointer within a constant expression. (GH95366). Bug Fixes to AST Handling ^ >From 6408619fd0b0a3f06dcd096719
[clang] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument (PR #94542)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/94542 >From da4df73607a9edefc8db721818eff50e974a0637 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 6 Jun 2024 01:55:54 +0300 Subject: [PATCH] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument --- clang/docs/ReleaseNotes.rst| 2 ++ clang/lib/Sema/SemaStmt.cpp| 2 +- clang/test/SemaCXX/lambda-as-default-parameter.cpp | 6 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/lambda-as-default-parameter.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 39a9013c75a41..819fe1811ddaf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -840,6 +840,8 @@ Bug Fixes to C++ Support - Fix a crash caused by improper use of ``__array_extent``. (#GH80474) - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). +- Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a + forward-declared class. (#GH93512). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 57465d4a77ac2..56f69dd50f361 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) { // Variables with higher required alignment than their type's ABI // alignment cannot use NRVO. - if (!VD->hasDependentAlignment() && + if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() && Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType)) Info.S = NamedReturnInfo::MoveEligible; diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp b/clang/test/SemaCXX/lambda-as-default-parameter.cpp new file mode 100644 index 0..1f07a7f5644b7 --- /dev/null +++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +struct a; // expected-note {{forward declaration of 'a'}} \ + expected-note {{forward declaration of 'a'}} +void b(a c = [] { return c; }); // expected-error {{initialization of incomplete type 'a'}} \ + expected-error {{variable has incomplete type 'a'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow non-lvalue values in constant expressions to prevent invalid pointer offset computation (PR #95479)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/95479 >From 125d9cdd617d6415ef24eb785fe22705149f2d01 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 01:26:34 +0300 Subject: [PATCH 1/5] [Clang] disallow non-lvalue values in constant expressions to prevent invalid pointer offset computation --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/AST/ExprConstant.cpp| 3 +++ clang/test/Sema/integral-to-ptr.c | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 clang/test/Sema/integral-to-ptr.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8c2f737836a9d..77906360b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,6 +847,7 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). +- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). Bug Fixes to AST Handling ^ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7178f081d9cf3..08bee806f172f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,9 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + if (!Value.isLValue()) +return false; + // Cast is of an lvalue, no need to change value. Result.setFrom(Info.Ctx, Value); return true; diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c new file mode 100644 index 0..99f83c3e52057 --- /dev/null +++ b/clang/test/Sema/integral-to-ptr.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 + +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} >From b73cf0659a115f29c7b224a8f89ab519dac01a13 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 08:50:03 +0300 Subject: [PATCH 2/5] update test expectations --- clang/test/Sema/integral-to-ptr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Sema/integral-to-ptr.c b/clang/test/Sema/integral-to-ptr.c index 99f83c3e52057..b8ab4cb79820d 100644 --- a/clang/test/Sema/integral-to-ptr.c +++ b/clang/test/Sema/integral-to-ptr.c @@ -1,3 +1,3 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only -std=c11 -int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer ('long' and 'int (*)(void)')}} +int x(void) { e: b: ; return &&e - &&b < x; } // expected-warning {{ordered comparison between pointer and integer}} >From 78fc56a0aab96984760a3874e06e51259b599bd5 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 18:16:34 +0300 Subject: [PATCH 3/5] add detailed comment --- clang/lib/AST/ExprConstant.cpp | 4 1 file changed, 4 insertions(+) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 08bee806f172f..712c3062eb9ac 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9325,6 +9325,10 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) { Result.IsNullPtr = false; return true; } else { + // In rare instances, the value isn't an lvalue. + // For example, when the value is the difference between the addresses of + // two labels. We reject that as a constant expression because we can't + // compute a valid offset to convert into a pointer. if (!Value.isLValue()) return false; >From 7e3af56b7fbb43041f81c982cee712f516ecc6f1 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 14 Jun 2024 18:16:58 +0300 Subject: [PATCH 4/5] update changelog message --- clang/docs/ReleaseNotes.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 77906360b..efd17d8f9a089 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -847,7 +847,8 @@ Bug Fixes to C++ Support - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). -- Fix an assertion failure caused by non-lvalue usage in lvalue context. (GH95366). +- Fixed a failed assertion when attempting to convert an integer representing the difference + between the addresses of two labels (a GNU extension) to a pointer within a constant expression. (GH95366). Bug Fixes to AST Handling ^ >From 6408619fd0b0a3f06dcd096719
[clang] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument (PR #94542)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/94542 >From da4df73607a9edefc8db721818eff50e974a0637 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 6 Jun 2024 01:55:54 +0300 Subject: [PATCH] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument --- clang/docs/ReleaseNotes.rst| 2 ++ clang/lib/Sema/SemaStmt.cpp| 2 +- clang/test/SemaCXX/lambda-as-default-parameter.cpp | 6 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/lambda-as-default-parameter.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 39a9013c75a41..819fe1811ddaf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -840,6 +840,8 @@ Bug Fixes to C++ Support - Fix a crash caused by improper use of ``__array_extent``. (#GH80474) - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). +- Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a + forward-declared class. (#GH93512). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 57465d4a77ac2..56f69dd50f361 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) { // Variables with higher required alignment than their type's ABI // alignment cannot use NRVO. - if (!VD->hasDependentAlignment() && + if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() && Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType)) Info.S = NamedReturnInfo::MoveEligible; diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp b/clang/test/SemaCXX/lambda-as-default-parameter.cpp new file mode 100644 index 0..1f07a7f5644b7 --- /dev/null +++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +struct a; // expected-note {{forward declaration of 'a'}} \ + expected-note {{forward declaration of 'a'}} +void b(a c = [] { return c; }); // expected-error {{initialization of incomplete type 'a'}} \ + expected-error {{variable has incomplete type 'a'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument (PR #94542)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/94542 >From da4df73607a9edefc8db721818eff50e974a0637 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 6 Jun 2024 01:55:54 +0300 Subject: [PATCH] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument --- clang/docs/ReleaseNotes.rst| 2 ++ clang/lib/Sema/SemaStmt.cpp| 2 +- clang/test/SemaCXX/lambda-as-default-parameter.cpp | 6 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/lambda-as-default-parameter.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 39a9013c75a41..819fe1811ddaf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -840,6 +840,8 @@ Bug Fixes to C++ Support - Fix a crash caused by improper use of ``__array_extent``. (#GH80474) - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). +- Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a + forward-declared class. (#GH93512). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 57465d4a77ac2..56f69dd50f361 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) { // Variables with higher required alignment than their type's ABI // alignment cannot use NRVO. - if (!VD->hasDependentAlignment() && + if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() && Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType)) Info.S = NamedReturnInfo::MoveEligible; diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp b/clang/test/SemaCXX/lambda-as-default-parameter.cpp new file mode 100644 index 0..1f07a7f5644b7 --- /dev/null +++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +struct a; // expected-note {{forward declaration of 'a'}} \ + expected-note {{forward declaration of 'a'}} +void b(a c = [] { return c; }); // expected-error {{initialization of incomplete type 'a'}} \ + expected-error {{variable has incomplete type 'a'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument (PR #94542)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/94542 >From da4df73607a9edefc8db721818eff50e974a0637 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 6 Jun 2024 01:55:54 +0300 Subject: [PATCH] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument --- clang/docs/ReleaseNotes.rst| 2 ++ clang/lib/Sema/SemaStmt.cpp| 2 +- clang/test/SemaCXX/lambda-as-default-parameter.cpp | 6 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/lambda-as-default-parameter.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 39a9013c75a41..819fe1811ddaf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -840,6 +840,8 @@ Bug Fixes to C++ Support - Fix a crash caused by improper use of ``__array_extent``. (#GH80474) - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). +- Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a + forward-declared class. (#GH93512). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 57465d4a77ac2..56f69dd50f361 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) { // Variables with higher required alignment than their type's ABI // alignment cannot use NRVO. - if (!VD->hasDependentAlignment() && + if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() && Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType)) Info.S = NamedReturnInfo::MoveEligible; diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp b/clang/test/SemaCXX/lambda-as-default-parameter.cpp new file mode 100644 index 0..1f07a7f5644b7 --- /dev/null +++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +struct a; // expected-note {{forward declaration of 'a'}} \ + expected-note {{forward declaration of 'a'}} +void b(a c = [] { return c; }); // expected-error {{initialization of incomplete type 'a'}} \ + expected-error {{variable has incomplete type 'a'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument (PR #94542)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/94542 >From da4df73607a9edefc8db721818eff50e974a0637 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 6 Jun 2024 01:55:54 +0300 Subject: [PATCH] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument --- clang/docs/ReleaseNotes.rst| 2 ++ clang/lib/Sema/SemaStmt.cpp| 2 +- clang/test/SemaCXX/lambda-as-default-parameter.cpp | 6 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/lambda-as-default-parameter.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 39a9013c75a41..819fe1811ddaf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -840,6 +840,8 @@ Bug Fixes to C++ Support - Fix a crash caused by improper use of ``__array_extent``. (#GH80474) - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). +- Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a + forward-declared class. (#GH93512). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 57465d4a77ac2..56f69dd50f361 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) { // Variables with higher required alignment than their type's ABI // alignment cannot use NRVO. - if (!VD->hasDependentAlignment() && + if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() && Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType)) Info.S = NamedReturnInfo::MoveEligible; diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp b/clang/test/SemaCXX/lambda-as-default-parameter.cpp new file mode 100644 index 0..1f07a7f5644b7 --- /dev/null +++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +struct a; // expected-note {{forward declaration of 'a'}} \ + expected-note {{forward declaration of 'a'}} +void b(a c = [] { return c; }); // expected-error {{initialization of incomplete type 'a'}} \ + expected-error {{variable has incomplete type 'a'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument (PR #94542)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/94542 >From da4df73607a9edefc8db721818eff50e974a0637 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 6 Jun 2024 01:55:54 +0300 Subject: [PATCH] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument --- clang/docs/ReleaseNotes.rst| 2 ++ clang/lib/Sema/SemaStmt.cpp| 2 +- clang/test/SemaCXX/lambda-as-default-parameter.cpp | 6 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/lambda-as-default-parameter.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 39a9013c75a41..819fe1811ddaf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -840,6 +840,8 @@ Bug Fixes to C++ Support - Fix a crash caused by improper use of ``__array_extent``. (#GH80474) - Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307), (#GH88081), (#GH89496), (#GH90669) and (#GH91633). +- Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a + forward-declared class. (#GH93512). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 57465d4a77ac2..56f69dd50f361 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3355,7 +3355,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const VarDecl *VD) { // Variables with higher required alignment than their type's ABI // alignment cannot use NRVO. - if (!VD->hasDependentAlignment() && + if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() && Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType)) Info.S = NamedReturnInfo::MoveEligible; diff --git a/clang/test/SemaCXX/lambda-as-default-parameter.cpp b/clang/test/SemaCXX/lambda-as-default-parameter.cpp new file mode 100644 index 0..1f07a7f5644b7 --- /dev/null +++ b/clang/test/SemaCXX/lambda-as-default-parameter.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +struct a; // expected-note {{forward declaration of 'a'}} \ + expected-note {{forward declaration of 'a'}} +void b(a c = [] { return c; }); // expected-error {{initialization of incomplete type 'a'}} \ + expected-error {{variable has incomplete type 'a'}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument (PR #94542)
a-tarasyuk wrote: @AaronBallman Thanks for the review. https://github.com/llvm/llvm-project/pull/94542 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] resolve record declaration of defaulted comparison method by using the first argument (PR #96228)
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/96228 Fixes #96043 >From 3345a48624a6f5795cbbdac21b5504322871ea90 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 20 Jun 2024 21:51:42 +0300 Subject: [PATCH] [Clang] resolve record declaration of defaulted comparison method by using the first argument --- clang/docs/ReleaseNotes.rst| 2 +- clang/lib/Sema/SemaDeclCXX.cpp | 12 +++- .../SemaCXX/defaulted-comparison-struct.cpp| 18 ++ 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 clang/test/SemaCXX/defaulted-comparison-struct.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index d0e5e67651364..510804efc6023 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -889,7 +889,7 @@ Bug Fixes to C++ Support between the addresses of two labels (a GNU extension) to a pointer within a constant expression. (#GH95366). - Fix immediate escalation bugs in the presence of dependent call arguments. (#GH94935) - Clang now diagnoses explicit specializations with storage class specifiers in all contexts. - +- Fixed failed assertion when resolving context of defaulted comparison method outside of struct. (#GH96043). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index d38700d56e4ff..066a89edaf6e7 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -9127,6 +9127,11 @@ void Sema::DeclareImplicitEqualityComparison(CXXRecordDecl *RD, popCodeSynthesisContext(); } +static inline CXXRecordDecl *getRecordDeclFromFirstParameter(FunctionDecl *FD) { + auto PT = FD->getParamDecl(0)->getType(); + return PT.getNonReferenceType()->getAsCXXRecordDecl(); +} + void Sema::DefineDefaultedComparison(SourceLocation UseLoc, FunctionDecl *FD, DefaultedComparisonKind DCK) { assert(FD->isDefaulted() && !FD->isDeleted() && @@ -9141,10 +9146,7 @@ void Sema::DefineDefaultedComparison(SourceLocation UseLoc, FunctionDecl *FD, { // Build and set up the function body. -// The first parameter has type maybe-ref-to maybe-const T, use that to get -// the type of the class being compared. -auto PT = FD->getParamDecl(0)->getType(); -CXXRecordDecl *RD = PT.getNonReferenceType()->getAsCXXRecordDecl(); +auto RD = getRecordDeclFromFirstParameter(FD); SourceLocation BodyLoc = FD->getEndLoc().isValid() ? FD->getEndLoc() : FD->getLocation(); StmtResult Body = @@ -9192,7 +9194,7 @@ ComputeDefaultedComparisonExceptionSpec(Sema &S, SourceLocation Loc, EnterExpressionEvaluationContext Context( S, Sema::ExpressionEvaluationContext::Unevaluated); -CXXRecordDecl *RD = cast(FD->getLexicalParent()); +auto RD = getRecordDeclFromFirstParameter(FD); SourceLocation BodyLoc = FD->getEndLoc().isValid() ? FD->getEndLoc() : FD->getLocation(); StmtResult Body = diff --git a/clang/test/SemaCXX/defaulted-comparison-struct.cpp b/clang/test/SemaCXX/defaulted-comparison-struct.cpp new file mode 100644 index 0..de4ec2852a137 --- /dev/null +++ b/clang/test/SemaCXX/defaulted-comparison-struct.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s +// expected-no-diagnostics + +template class a {}; +template b c(a); +template class e { +public: + typedef a f; + f begin(); +}; +template constexpr bool operator==(d h, g i) { + return *c(h.begin()) == *c(i.begin()); +} +struct j { + e bar; + bool operator==(const j &) const; +}; +bool j::operator==(const j &) const = default; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument (PR #94542)
a-tarasyuk wrote: @AaronBallman Thank you for your feedback. Do you think this needs to be reviewed by someone else? I can't add reviewers myself :) https://github.com/llvm/llvm-project/pull/94542 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] skip alignment checks on incomplete types to avoid an assertion failure while parsing lambda used as default argument (PR #94542)
a-tarasyuk wrote: @AaronBallman Yes, I do. I don't have access to merge… https://github.com/llvm/llvm-project/pull/94542 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] resolve record declaration of defaulted comparison method by using the first argument (PR #96228)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/96228 >From c982465dbc29958f8a8bb07149c6d50c778860c9 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 20 Jun 2024 21:51:42 +0300 Subject: [PATCH] [Clang] use parent declaration context to avoid asserting cast failure in defaulted comparison method --- clang/docs/ReleaseNotes.rst| 2 +- clang/lib/Sema/SemaDeclCXX.cpp | 2 +- .../SemaCXX/defaulted-comparison-struct.cpp| 18 ++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 clang/test/SemaCXX/defaulted-comparison-struct.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index d0e5e67651364..510804efc6023 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -889,7 +889,7 @@ Bug Fixes to C++ Support between the addresses of two labels (a GNU extension) to a pointer within a constant expression. (#GH95366). - Fix immediate escalation bugs in the presence of dependent call arguments. (#GH94935) - Clang now diagnoses explicit specializations with storage class specifiers in all contexts. - +- Fixed failed assertion when resolving context of defaulted comparison method outside of struct. (#GH96043). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index d38700d56e4ff..746a19d3e7788 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -9192,7 +9192,7 @@ ComputeDefaultedComparisonExceptionSpec(Sema &S, SourceLocation Loc, EnterExpressionEvaluationContext Context( S, Sema::ExpressionEvaluationContext::Unevaluated); -CXXRecordDecl *RD = cast(FD->getLexicalParent()); +CXXRecordDecl *RD = cast(FD->getDeclContext()); SourceLocation BodyLoc = FD->getEndLoc().isValid() ? FD->getEndLoc() : FD->getLocation(); StmtResult Body = diff --git a/clang/test/SemaCXX/defaulted-comparison-struct.cpp b/clang/test/SemaCXX/defaulted-comparison-struct.cpp new file mode 100644 index 0..de4ec2852a137 --- /dev/null +++ b/clang/test/SemaCXX/defaulted-comparison-struct.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s +// expected-no-diagnostics + +template class a {}; +template b c(a); +template class e { +public: + typedef a f; + f begin(); +}; +template constexpr bool operator==(d h, g i) { + return *c(h.begin()) == *c(i.begin()); +} +struct j { + e bar; + bool operator==(const j &) const; +}; +bool j::operator==(const j &) const = default; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] resolve record declaration of defaulted comparison method by using the first argument (PR #96228)
@@ -9192,7 +9194,7 @@ ComputeDefaultedComparisonExceptionSpec(Sema &S, SourceLocation Loc, EnterExpressionEvaluationContext Context( S, Sema::ExpressionEvaluationContext::Unevaluated); -CXXRecordDecl *RD = cast(FD->getLexicalParent()); +auto RD = getRecordDeclFromFirstParameter(FD); a-tarasyuk wrote: @zyn0217 Thanks for the feedback and for pointing out that helper. I've updated the code to use it. Previously, I used a solution similar to `DefineDefaultedComparison` to maintain a consistent approach, which might make sense at the `DefineDefaultedComparison` stage but not in `ComputeDefaultedComparisonExceptionSpec`. https://github.com/llvm/llvm-project/pull/96228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits