[PATCH] D105446: [clang] fix constexpr code generation for user conversions.
Matheus Izvekov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 8 11:23:31 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5a1c50410ccc: [clang] fix constexpr code generation for user conversions. (authored by mizvekov).
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.357293.patch
Type: text/x-patch
Size: 2144 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210708/84d9ff74/attachment.bin>
More information about the cfe-commits
mailing list