[PATCH] D105446: DRAFT: [clang] fix constexpr code generation for user conversions.
Matheus Izvekov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 8 09:48:13 PDT 2021
mizvekov updated this revision to Diff 357260.
mizvekov added a comment.
.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105446/new/
https://reviews.llvm.org/D105446
Files:
clang/lib/AST/Expr.cpp
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,36 @@
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();
+}
+
+int test_UserConvOverload_helper(int a) { return a; }
+
+// EVAL-FN-LABEL: @_Z21test_UserConvOverloadv(
+// EVAL-FN-NEXT: entry:
+// EVAL-FN-NEXT: %call = call i32 @_Z28test_UserConvOverload_helperi(i32 42)
+// EVAL-FN-NEXT: ret i32 %call
+//
+int test_UserConvOverload() {
+ return test_UserConvOverload_helper(UserConv());
+}
+
+consteval int test_UserConvOverload_helper_ceval(int a) { return a; }
+
+// EVAL-FN-LABEL: @_Z27test_UserConvOverload_cevalv(
+// EVAL-FN-NEXT: entry:
+// EVAL-FN-NEXT: ret i32 42
+//
+int test_UserConvOverload_ceval() {
+ return test_UserConvOverload_helper_ceval(UserConv());
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -7786,7 +7786,7 @@
Method->getType()->castAs<FunctionProtoType>()))
return ExprError();
- return CE;
+ return CheckForImmediateInvocation(CE, CE->getMethodDecl());
}
ExprResult Sema::BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,
Index: clang/lib/AST/Expr.cpp
===================================================================
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -1913,6 +1913,7 @@
SubExpr =
skipImplicitTemporary(cast<CXXConstructExpr>(SubExpr->IgnoreImplicit())->getArg(0));
else if (E->getCastKind() == CK_UserDefinedConversion) {
+ SubExpr = SubExpr->IgnoreImplicit();
assert((isa<CXXMemberCallExpr>(SubExpr) ||
isa<BlockExpr>(SubExpr)) &&
"Unexpected SubExpr for CK_UserDefinedConversion.");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105446.357260.patch
Type: text/x-patch
Size: 2144 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210708/e7283ec3/attachment-0001.bin>
More information about the cfe-commits
mailing list