[PATCH] D105446: [clang] fix constexpr code generation for user conversions.
Matheus Izvekov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 5 15:32:50 PDT 2021
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 <mizvekov at 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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105446.356570.patch
Type: text/x-patch
Size: 1025 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210705/6e9991ba/attachment-0001.bin>
More information about the cfe-commits
mailing list