Skip to content

Commit 100b6bf

Browse files
resistorIanWood1
authored andcommitted
Revert "FunctionDecl::getFunctionTypeLoc: ignore function type attributes (llvm#118420)"
This reverts commit 19c708c because it caused test failures on non-x86 targets.
1 parent 43a5f8e commit 100b6bf

File tree

3 files changed

+8
-105
lines changed

3 files changed

+8
-105
lines changed

clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,21 +1577,19 @@ TEST(TypeHints, Aliased) {
15771577
}
15781578

15791579
TEST(TypeHints, CallingConvention) {
1580-
// Check that we don't crash for lambdas with an annotation
1580+
// Check that we don't crash for lambdas without a FunctionTypeLoc
15811581
// https://github.com/clangd/clangd/issues/2223
1582-
Annotations Source(R"cpp(
1582+
std::string Code = R"cpp(
15831583
void test() {
1584-
[]($lambda[[)]]__cdecl {};
1584+
[]() __cdecl {};
15851585
}
1586-
)cpp");
1587-
TestTU TU = TestTU::withCode(Source.code());
1586+
)cpp";
1587+
TestTU TU = TestTU::withCode(Code);
15881588
TU.ExtraArgs.push_back("--target=x86_64-w64-mingw32");
15891589
TU.PredefineMacros = true; // for the __cdecl
15901590
auto AST = TU.build();
15911591

1592-
EXPECT_THAT(
1593-
hintsOfKind(AST, InlayHintKind::Type),
1594-
ElementsAre(HintMatcher(ExpectedHint{"-> void", "lambda"}, Source)));
1592+
EXPECT_THAT(hintsOfKind(AST, InlayHintKind::Type), IsEmpty());
15951593
}
15961594

15971595
TEST(TypeHints, Decltype) {

clang/lib/AST/Decl.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,25 +3910,8 @@ bool FunctionDecl::doesDeclarationForceExternallyVisibleDefinition() const {
39103910

39113911
FunctionTypeLoc FunctionDecl::getFunctionTypeLoc() const {
39123912
const TypeSourceInfo *TSI = getTypeSourceInfo();
3913-
3914-
if (!TSI)
3915-
return FunctionTypeLoc();
3916-
3917-
TypeLoc TL = TSI->getTypeLoc();
3918-
FunctionTypeLoc FTL;
3919-
3920-
while (!(FTL = TL.getAs<FunctionTypeLoc>())) {
3921-
if (const auto PTL = TL.getAs<ParenTypeLoc>())
3922-
TL = PTL.getInnerLoc();
3923-
else if (const auto ATL = TL.getAs<AttributedTypeLoc>())
3924-
TL = ATL.getEquivalentTypeLoc();
3925-
else if (const auto MQTL = TL.getAs<MacroQualifiedTypeLoc>())
3926-
TL = MQTL.getInnerLoc();
3927-
else
3928-
break;
3929-
}
3930-
3931-
return FTL;
3913+
return TSI ? TSI->getTypeLoc().IgnoreParens().getAs<FunctionTypeLoc>()
3914+
: FunctionTypeLoc();
39323915
}
39333916

39343917
SourceRange FunctionDecl::getReturnTypeSourceRange() const {

clang/unittests/AST/AttrTest.cpp

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,6 @@ TEST(Attr, AnnotateType) {
8686
struct S { int mem; };
8787
int [[clang::annotate_type("int")]]
8888
S::* [[clang::annotate_type("ptr_to_mem")]] ptr_to_member = &S::mem;
89-
90-
// Function Type Attributes
91-
__attribute__((noreturn)) int f_noreturn();
92-
__attribute__((preserve_most)) int f_cc_preserve_most();
93-
94-
#define PRESERVE_MOST __attribute__((preserve_most))
95-
PRESERVE_MOST int f_macro_attribue();
96-
97-
int (__attribute__((preserve_most)) f_paren_attribute)();
98-
99-
int (
100-
PRESERVE_MOST
101-
(
102-
__attribute__((warn_unused_result))
103-
(f_w_paren_and_attr)
104-
)
105-
) ();
10689
)cpp");
10790

10891
{
@@ -170,67 +153,6 @@ TEST(Attr, AnnotateType) {
170153
EXPECT_EQ(IntTL.getType(), AST->getASTContext().IntTy);
171154
}
172155

173-
{
174-
const FunctionDecl *Func = getFunctionNode(AST.get(), "f_noreturn");
175-
const FunctionTypeLoc FTL = Func->getFunctionTypeLoc();
176-
const FunctionType *FT = FTL.getTypePtr();
177-
178-
EXPECT_TRUE(FT->getNoReturnAttr());
179-
}
180-
181-
{
182-
const FunctionDecl *Func = getFunctionNode(AST.get(), "f_cc_preserve_most");
183-
const FunctionTypeLoc FTL = Func->getFunctionTypeLoc();
184-
const FunctionType *FT = FTL.getTypePtr();
185-
186-
EXPECT_TRUE(FT->getCallConv() == CC_PreserveMost);
187-
}
188-
189-
{
190-
for (auto should_have_func_type_loc : {
191-
"f_macro_attribue",
192-
"f_paren_attribute",
193-
"f_w_paren_and_attr",
194-
}) {
195-
llvm::errs() << "O: " << should_have_func_type_loc << "\n";
196-
const FunctionDecl *Func =
197-
getFunctionNode(AST.get(), should_have_func_type_loc);
198-
199-
EXPECT_TRUE(Func->getFunctionTypeLoc());
200-
}
201-
}
202-
203-
// The following test verifies getFunctionTypeLoc returns a type
204-
// which takes into account the attribute (instead of only the nake
205-
// type).
206-
//
207-
// This is hard to do with C/C++ because it seems using a function
208-
// type attribute with a C/C++ function declaration only results
209-
// with either:
210-
//
211-
// 1. It does NOT produce any AttributedType (for example it only
212-
// sets one flag of the FunctionType's ExtInfo, e.g. NoReturn).
213-
// 2. It produces an AttributedType with modified type and
214-
// equivalent type that are equal (for example, that's what
215-
// happens with Calling Convention attributes).
216-
//
217-
// Fortunately, ObjC has one specific function type attribute that
218-
// creates an AttributedType with different modified type and
219-
// equivalent type.
220-
auto AST_ObjC = buildASTFromCodeWithArgs(
221-
R"objc(
222-
__attribute__((ns_returns_retained)) id f();
223-
)objc",
224-
{"-fobjc-arc", "-fsyntax-only", "-fobjc-runtime=macosx-10.7"},
225-
"input.mm");
226-
{
227-
const FunctionDecl *f = getFunctionNode(AST_ObjC.get(), "f");
228-
const FunctionTypeLoc FTL = f->getFunctionTypeLoc();
229-
230-
const FunctionType *FT = FTL.getTypePtr();
231-
EXPECT_TRUE(FT->getExtInfo().getProducesResult());
232-
}
233-
234156
// Test type annotation on an `__auto_type` type in C mode.
235157
AST = buildASTFromCodeWithArgs(R"c(
236158
__auto_type [[clang::annotate_type("auto")]] auto_var = 1;

0 commit comments

Comments
 (0)