[clang] 70d6e7c - [Clang] Rewrite SourceLocExpr in default args (#93383)
via cfe-commits
cfe-commits at lists.llvm.org
Sun May 26 00:18:37 PDT 2024
Author: cor3ntin
Date: 2024-05-26T09:18:33+02:00
New Revision: 70d6e7c09fd1a79ca5c2c2deeb72e6b0e1e80a52
URL: https://github.com/llvm/llvm-project/commit/70d6e7c09fd1a79ca5c2c2deeb72e6b0e1e80a52
DIFF: https://github.com/llvm/llvm-project/commit/70d6e7c09fd1a79ca5c2c2deeb72e6b0e1e80a52.diff
LOG: [Clang] Rewrite SourceLocExpr in default args (#93383)
In order for their dependency to be computed correctly, SourceLocExpr
should refer to the context in which they are used.
Fixes #92680
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/source_location.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d023f53754cb3..825e91876ffce 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -794,6 +794,8 @@ Bug Fixes to C++ Support
Fixes (#GH87210), (GH89541).
- Clang no longer tries to check if an expression is immediate-escalating in an unevaluated context.
Fixes (#GH91308).
+- Fix a crash caused by a regression in the handling of ``source_location``
+ in dependent contexts. Fixes (#GH92680).
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ff9c5ead36dcf..410f80ae864a1 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5506,6 +5506,15 @@ struct EnsureImmediateInvocationInDefaultArgs
// cause it to incorrectly point it to the outermost class
// in the case of nested struct initialization.
ExprResult TransformCXXThisExpr(CXXThisExpr *E) { return E; }
+
+ // Rewrite to source location to refer to the context in which they are used.
+ ExprResult TransformSourceLocExpr(SourceLocExpr *E) {
+ if (E->getParentContext() == SemaRef.CurContext)
+ return E;
+ return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
+ E->getBeginLoc(), E->getEndLoc(),
+ SemaRef.CurContext);
+ }
};
ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc,
diff --git a/clang/test/SemaCXX/source_location.cpp b/clang/test/SemaCXX/source_location.cpp
index 63157cfacdd98..6b3610d703e71 100644
--- a/clang/test/SemaCXX/source_location.cpp
+++ b/clang/test/SemaCXX/source_location.cpp
@@ -912,3 +912,20 @@ auto g() {
}
}
+
+namespace GH92680 {
+
+struct IntConstuctible {
+ IntConstuctible(std::source_location = std::source_location::current());
+};
+
+template <typename>
+auto construct_at(IntConstuctible) -> decltype(IntConstuctible()) {
+ return {};
+}
+
+void test() {
+ construct_at<IntConstuctible>({});
+}
+
+}
More information about the cfe-commits
mailing list