-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Clang] Fix an assertion in expression recovery #112888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Explicit object member function calls are not modelled as member calls Fixes llvm#112559
|
@llvm/pr-subscribers-clang Author: cor3ntin (cor3ntin) ChangesExplicit object member function calls are not modelled as member calls Fixes #112559 Full diff: https://github.com/llvm/llvm-project/pull/112888.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a65bd6f382901b..e86d6200fae800 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -418,7 +418,7 @@ Improvements to Clang's diagnostics
- The warning for an unsupported type for a named register variable is now phrased ``unsupported type for named register variable``,
instead of ``bad type for named register variable``. This makes it clear that the type is not supported at all, rather than being
suboptimal in some way the error fails to mention (#GH111550).
-
+
- Clang now emits a ``-Wdepredcated-literal-operator`` diagnostic, even if the
name was a reserved name, which we improperly allowed to suppress the
diagnostic.
@@ -537,6 +537,7 @@ Bug Fixes to C++ Support
certain situations. (#GH47400), (#GH90896)
- Fix erroneous templated array size calculation leading to crashes in generated code. (#GH41441)
- During the lookup for a base class name, non-type names are ignored. (#GH16855)
+- Fix a crash when recovering an invalid expression involving an explicit object member conversion operator. (#GH112559)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 9ecbf121e3fc0d..66db6263cb1bd2 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1989,7 +1989,7 @@ Expr *CastExpr::getSubExprAsWritten() {
SubExpr = IgnoreExprNodes(cast<CXXConstructExpr>(SubExpr)->getArg(0),
ignoreImplicitSemaNodes);
} else if (E->getCastKind() == CK_UserDefinedConversion) {
- assert((isa<CXXMemberCallExpr>(SubExpr) || isa<BlockExpr>(SubExpr)) &&
+ assert((isa<CallExpr, BlockExpr>(SubExpr)) &&
"Unexpected SubExpr for CK_UserDefinedConversion.");
if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr))
SubExpr = MCE->getImplicitObjectArgument();
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 2a984a75f37d21..520052a89d1840 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -1097,3 +1097,20 @@ struct C4 {
// expected-warning {{volatile-qualified parameter type 'const volatile C4' is deprecated}}
};
}
+
+
+namespace GH112559 {
+struct Wrap {};
+struct S {
+ constexpr operator Wrap (this const S& self) {
+ return Wrap{};
+ };
+ constexpr int operator <<(this Wrap self, int i) {
+ return 0;
+ }
+};
+// Purposefully invalid expression to check an assertion in the
+// expression recovery machinery.
+static_assert((S{} << 11) == a);
+// expected-error@-1 {{use of undeclared identifier 'a'}}
+}
|
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/7768 Here is the relevant piece of the build log for the reference |
| ignoreImplicitSemaNodes); | ||
| } else if (E->getCastKind() == CK_UserDefinedConversion) { | ||
| assert((isa<CXXMemberCallExpr>(SubExpr) || isa<BlockExpr>(SubExpr)) && | ||
| assert((isa<CallExpr, BlockExpr>(SubExpr)) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious what change loosened the criteria here so that we can't restrict to CXXMemberCallExpr or was it that the assert was always too strict?
Explicit object member function calls are not modelled as member calls
Fixes #112559