Skip to content

Commit 3d18b08

Browse files
author
v01dxyz
committed
Support MacroQualifiedTypeLoc, fix typos
1 parent 6d749da commit 3d18b08

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

clang/lib/AST/Decl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3884,10 +3884,12 @@ FunctionTypeLoc FunctionDecl::getFunctionTypeLoc() const {
38843884
FunctionTypeLoc FTL;
38853885

38863886
while (!(FTL = TL.getAs<FunctionTypeLoc>())) {
3887-
if (auto PTL = TL.getAs<ParenTypeLoc>())
3887+
if (const auto PTL = TL.getAs<ParenTypeLoc>())
38883888
TL = PTL.getInnerLoc();
3889-
else if (auto ATL = TL.getAs<AttributedTypeLoc>())
3889+
else if (const auto ATL = TL.getAs<AttributedTypeLoc>())
38903890
TL = ATL.getEquivalentTypeLoc();
3891+
else if (const auto MQTL = TL.getAs<MacroQualifiedTypeLoc>())
3892+
TL = MQTL.getInnerLoc();
38913893
else
38923894
break;
38933895
}

clang/unittests/AST/AttrTest.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ TEST(Attr, AnnotateType) {
9090
// Function Type Attributes
9191
__attribute__((noreturn)) int f_noreturn();
9292
__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+
) ();
93106
)cpp");
94107

95108
{
@@ -173,6 +186,19 @@ TEST(Attr, AnnotateType) {
173186
EXPECT_TRUE(FT->getCallConv() == CC_PreserveMost);
174187
}
175188

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 = getFunctionNode(AST.get(), should_have_func_type_loc);
197+
198+
EXPECT_TRUE(Func->getFunctionTypeLoc());
199+
}
200+
}
201+
176202
// The following test verifies getFunctionTypeLoc returns a type
177203
// which takes into account the attribute (instead of only the nake
178204
// type).
@@ -182,7 +208,7 @@ TEST(Attr, AnnotateType) {
182208
// with either:
183209
//
184210
// 1. It does NOT produce any AttributedType (for example it only
185-
// sets one flag of the FunctionType's ExtInfo, ie NoReturn).
211+
// sets one flag of the FunctionType's ExtInfo, e.g. NoReturn).
186212
// 2. It produces an AttributedType with modified type and
187213
// equivalent type that are equal (for example, that's what
188214
// happens with Calling Convention attributes).

0 commit comments

Comments
 (0)