[clang] [clang] Fix crash in concept deprecation (PR #98622)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 12 05:13:22 PDT 2024
https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/98622
Apparently we can't assume that `AutoTypeLoc` from `AutoType` is always valid.
Fixes #98164
>From 5310764fb4044bcd4229434e80b64870c4b4ee8c Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Fri, 12 Jul 2024 15:12:37 +0300
Subject: [PATCH] [clang] Fix crash in concept deprecation
Apparently we can't assume that `AutoTypeLoc` from `AutoType` is always valid.
Fixes #98164
---
clang/lib/Sema/SemaDecl.cpp | 9 +++++----
clang/lib/Sema/SemaType.cpp | 10 +++++-----
clang/test/SemaCXX/cxx-deprecated.cpp | 7 +++++++
3 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 66eeaa8e6f777..7e4328cc176a2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7416,10 +7416,11 @@ NamedDecl *Sema::ActOnVariableDeclarator(
tryToFixVariablyModifiedVarType(TInfo, R, D.getIdentifierLoc(),
/*DiagID=*/0);
- if (const AutoType *AutoT = R->getAs<AutoType>())
- CheckConstrainedAuto(
- AutoT,
- TInfo->getTypeLoc().getContainedAutoTypeLoc().getConceptNameLoc());
+ if (const AutoType *AutoT = R->getAs<AutoType>()) {
+ AutoTypeLoc Loc = TInfo->getTypeLoc().getContainedAutoTypeLoc();
+ CheckConstrainedAuto(AutoT,
+ Loc ? Loc.getConceptNameLoc() : SourceLocation());
+ }
bool IsMemberSpecialization = false;
bool IsVariableTemplateSpecialization = false;
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 714409f927a8d..887d1b395d475 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -6308,11 +6308,11 @@ TypeResult Sema::ActOnTypeName(Declarator &D) {
CheckExtraCXXDefaultArguments(D);
}
- if (const AutoType *AutoT = T->getAs<AutoType>())
- CheckConstrainedAuto(
- AutoT,
- TInfo->getTypeLoc().getContainedAutoTypeLoc().getConceptNameLoc());
-
+ if (const AutoType *AutoT = T->getAs<AutoType>()) {
+ AutoTypeLoc Loc = TInfo->getTypeLoc().getContainedAutoTypeLoc();
+ CheckConstrainedAuto(AutoT,
+ Loc ? Loc.getConceptNameLoc() : SourceLocation());
+ }
return CreateParsedType(T, TInfo);
}
diff --git a/clang/test/SemaCXX/cxx-deprecated.cpp b/clang/test/SemaCXX/cxx-deprecated.cpp
index 81eb07608300d..870930f54af72 100644
--- a/clang/test/SemaCXX/cxx-deprecated.cpp
+++ b/clang/test/SemaCXX/cxx-deprecated.cpp
@@ -36,4 +36,11 @@ template <C T>
// expected-warning at -1 {{'C' is deprecated}}
// expected-note@#C {{'C' has been explicitly marked deprecated here}}
void f();
+
+template <int>
+auto b() = delete; // #b
+
+decltype(b<0>()) x;
+// expected-error at -1 {{call to deleted function 'b'}}
+// expected-note@#b {{candidate function [with $0 = 0] has been explicitly deleted}}
} // namespace cxx20_concept
More information about the cfe-commits
mailing list