[clang] 505a9ae - [Clang] Look through type sugar when accessing FunctionProtoType (#88428)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 11 21:49:57 PDT 2024
Author: Sirraide
Date: 2024-04-12T06:49:53+02:00
New Revision: 505a9ae81d620b92284f7b2cbe874c936cf19583
URL: https://github.com/llvm/llvm-project/commit/505a9ae81d620b92284f7b2cbe874c936cf19583
DIFF: https://github.com/llvm/llvm-project/commit/505a9ae81d620b92284f7b2cbe874c936cf19583.diff
LOG: [Clang] Look through type sugar when accessing FunctionProtoType (#88428)
This fixes a bug introduced by #84473: if a lambda’s type is type sugar
(e.g. an `AttributedType`), we need to use `getAs()` instead of `cast()`
to retrieve the `FunctionProtoType`.
Added:
Modified:
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/cxx2b-deducing-this.cpp
clang/test/SemaCXX/lambda-expressions.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 846e7d5d3ab92b..ec5ca2b9352ed4 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -20704,7 +20704,7 @@ static void FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter(
if (MD->getType().isNull())
continue;
- const auto *Ty = cast<FunctionProtoType>(MD->getType());
+ const auto *Ty = MD->getType()->getAs<FunctionProtoType>();
if (!Ty || !MD->isExplicitObjectMemberFunction() ||
!Ty->getParamType(0)->isDependentType())
continue;
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 763901d4418d20..ac39cb99fc934e 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1488,7 +1488,7 @@ void Sema::MarkThisReferenced(CXXThisExpr *This) {
if (MD->getType().isNull())
return false;
- const auto *Ty = cast<FunctionProtoType>(MD->getType());
+ const auto *Ty = MD->getType()->getAs<FunctionProtoType>();
return Ty && MD->isExplicitObjectMemberFunction() &&
Ty->getParamType(0)->isDependentType();
}
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index c14c971afd2359..5f29a955e053c3 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -312,6 +312,18 @@ void TestMutationInLambda() {
l1();
l2();
}
+
+ // Check that we don't crash if the lambda has type sugar.
+ const auto l15 = [=](this auto&&) [[clang::annotate_type("foo")]] [[clang::annotate_type("bar")]] {
+ return x;
+ };
+
+ const auto l16 = [=]() [[clang::annotate_type("foo")]] [[clang::annotate_type("bar")]] {
+ return x;
+ };
+
+ l15();
+ l16();
}
struct Over_Call_Func_Example {
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp b/clang/test/SemaCXX/lambda-expressions.cpp
index 151d74f21d64dc..6be338064452ed 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -762,3 +762,12 @@ template auto t::operator()<int>(int a) const; // expected-note {{in instantiati
}
#endif
+
+namespace GH84473_bug {
+void f1() {
+ int b;
+ (void) [=] [[gnu::regcall]] () { // expected-warning {{an attribute specifier sequence in this position is a C++23 extension}}
+ (void) b;
+ };
+}
+}
More information about the cfe-commits
mailing list