cor3ntin updated this revision to Diff 553381. cor3ntin added a comment. Address comments
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D158733/new/ https://reviews.llvm.org/D158733 Files: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaExpr.cpp clang/test/SemaCXX/cxx2a-consteval.cpp Index: clang/test/SemaCXX/cxx2a-consteval.cpp =================================================================== --- clang/test/SemaCXX/cxx2a-consteval.cpp +++ clang/test/SemaCXX/cxx2a-consteval.cpp @@ -1103,3 +1103,27 @@ // expected-note {{read of non-const variable 'bad' is not allowed in a constant expression}} } } + +namespace GH64949 { +struct f { + int g; // expected-note 2{{subobject declared here}} + constexpr ~f() {} +}; +class h { + +public: + consteval h(char *) {} + consteval operator int() const { return 1; } + f i; +}; + +void test() { (int)h{nullptr}; } +// expected-error@-1 {{call to consteval function 'GH64949::h::h' is not a constant expression}} +// expected-note@-2 {{subobject 'g' is not initialized}} + +int test2() { return h{nullptr}; } +// expected-error@-1 {{call to consteval function 'GH64949::h::h' is not a constant expression}} +// expected-note@-2 {{subobject 'g' is not initialized}} + + +} Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -18352,15 +18352,17 @@ SemaRef.FailedImmediateInvocations.insert(CE); Expr *InnerExpr = CE->getSubExpr()->IgnoreImplicit(); if (auto *FunctionalCast = dyn_cast<CXXFunctionalCastExpr>(InnerExpr)) - InnerExpr = FunctionalCast->getSubExpr(); + InnerExpr = FunctionalCast->getSubExpr()->IgnoreImplicit(); FunctionDecl *FD = nullptr; if (auto *Call = dyn_cast<CallExpr>(InnerExpr)) FD = cast<FunctionDecl>(Call->getCalleeDecl()); else if (auto *Call = dyn_cast<CXXConstructExpr>(InnerExpr)) FD = Call->getConstructor(); - else - llvm_unreachable("unhandled decl kind"); - assert(FD && FD->isImmediateFunction()); + else if (auto *Cast = dyn_cast<CastExpr>(InnerExpr)) + FD = dyn_cast_or_null<FunctionDecl>(Cast->getConversionFunction()); + + assert(FD && FD->isImmediateFunction() && + "could not find an immediate function in this expression"); SemaRef.Diag(CE->getBeginLoc(), diag::err_invalid_consteval_call) << FD << FD->isConsteval(); if (auto Context = Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -198,6 +198,10 @@ - Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes: (`#64171 <https://github.com/llvm/llvm-project/issues/64171>`_). +- Fix a crash when an immediate invocation is not a constant expression + and appear in an implicit cast. + (`#64949 <https://github.com/llvm/llvm-project/issues/64949>`_). + Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed an import failure of recursive friend class template.
Index: clang/test/SemaCXX/cxx2a-consteval.cpp =================================================================== --- clang/test/SemaCXX/cxx2a-consteval.cpp +++ clang/test/SemaCXX/cxx2a-consteval.cpp @@ -1103,3 +1103,27 @@ // expected-note {{read of non-const variable 'bad' is not allowed in a constant expression}} } } + +namespace GH64949 { +struct f { + int g; // expected-note 2{{subobject declared here}} + constexpr ~f() {} +}; +class h { + +public: + consteval h(char *) {} + consteval operator int() const { return 1; } + f i; +}; + +void test() { (int)h{nullptr}; } +// expected-error@-1 {{call to consteval function 'GH64949::h::h' is not a constant expression}} +// expected-note@-2 {{subobject 'g' is not initialized}} + +int test2() { return h{nullptr}; } +// expected-error@-1 {{call to consteval function 'GH64949::h::h' is not a constant expression}} +// expected-note@-2 {{subobject 'g' is not initialized}} + + +} Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -18352,15 +18352,17 @@ SemaRef.FailedImmediateInvocations.insert(CE); Expr *InnerExpr = CE->getSubExpr()->IgnoreImplicit(); if (auto *FunctionalCast = dyn_cast<CXXFunctionalCastExpr>(InnerExpr)) - InnerExpr = FunctionalCast->getSubExpr(); + InnerExpr = FunctionalCast->getSubExpr()->IgnoreImplicit(); FunctionDecl *FD = nullptr; if (auto *Call = dyn_cast<CallExpr>(InnerExpr)) FD = cast<FunctionDecl>(Call->getCalleeDecl()); else if (auto *Call = dyn_cast<CXXConstructExpr>(InnerExpr)) FD = Call->getConstructor(); - else - llvm_unreachable("unhandled decl kind"); - assert(FD && FD->isImmediateFunction()); + else if (auto *Cast = dyn_cast<CastExpr>(InnerExpr)) + FD = dyn_cast_or_null<FunctionDecl>(Cast->getConversionFunction()); + + assert(FD && FD->isImmediateFunction() && + "could not find an immediate function in this expression"); SemaRef.Diag(CE->getBeginLoc(), diag::err_invalid_consteval_call) << FD << FD->isConsteval(); if (auto Context = Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -198,6 +198,10 @@ - Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes: (`#64171 <https://github.com/llvm/llvm-project/issues/64171>`_). +- Fix a crash when an immediate invocation is not a constant expression + and appear in an implicit cast. + (`#64949 <https://github.com/llvm/llvm-project/issues/64949>`_). + Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed an import failure of recursive friend class template.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits