mizvekov created this revision. mizvekov requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
When building the member call to a user conversion function during an implicit cast, the expression was not being checked for immediate invocation, so we were never adding the ConstantExpr node to AST. This would cause the call to the user conversion operator to be emitted even if it was constantexpr evaluated, and this would even trip an assert when said user conversion was declared consteval: `Assertion failed: !cast<FunctionDecl>(GD.getDecl())->isConsteval() && "consteval function should never be emitted", file clang\lib\CodeGen\CodeGenModule.cpp, line 3530` Fixes PR48855. Signed-off-by: Matheus Izvekov <mizve...@gmail.com> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D105446 Files: clang/lib/Sema/SemaExprCXX.cpp clang/test/CodeGenCXX/cxx2a-consteval.cpp Index: clang/test/CodeGenCXX/cxx2a-consteval.cpp =================================================================== --- clang/test/CodeGenCXX/cxx2a-consteval.cpp +++ clang/test/CodeGenCXX/cxx2a-consteval.cpp @@ -210,3 +210,15 @@ AggCtor C(i); return C.a + C.b; } + +struct UserConv { + consteval operator int() const noexcept { return 42; } +}; + +// EVAL-FN-LABEL: @_Z13test_UserConvv( +// EVAL-FN-NEXT: entry: +// EVAL-FN-NEXT: ret i32 42 +// +int test_UserConv() { + return UserConv(); +} Index: clang/lib/Sema/SemaExprCXX.cpp =================================================================== --- clang/lib/Sema/SemaExprCXX.cpp +++ clang/lib/Sema/SemaExprCXX.cpp @@ -7786,7 +7786,8 @@ Method->getType()->castAs<FunctionProtoType>())) return ExprError(); - return CE; + return CheckForImmediateInvocation(MaybeBindToTemporary(CE), + CE->getMethodDecl()); } ExprResult Sema::BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
Index: clang/test/CodeGenCXX/cxx2a-consteval.cpp =================================================================== --- clang/test/CodeGenCXX/cxx2a-consteval.cpp +++ clang/test/CodeGenCXX/cxx2a-consteval.cpp @@ -210,3 +210,15 @@ AggCtor C(i); return C.a + C.b; } + +struct UserConv { + consteval operator int() const noexcept { return 42; } +}; + +// EVAL-FN-LABEL: @_Z13test_UserConvv( +// EVAL-FN-NEXT: entry: +// EVAL-FN-NEXT: ret i32 42 +// +int test_UserConv() { + return UserConv(); +} Index: clang/lib/Sema/SemaExprCXX.cpp =================================================================== --- clang/lib/Sema/SemaExprCXX.cpp +++ clang/lib/Sema/SemaExprCXX.cpp @@ -7786,7 +7786,8 @@ Method->getType()->castAs<FunctionProtoType>())) return ExprError(); - return CE; + return CheckForImmediateInvocation(MaybeBindToTemporary(CE), + CE->getMethodDecl()); } ExprResult Sema::BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits