Skip to content

Commit

Permalink
Fixed #354: Attribute which appeared after return type was broken.
Browse files Browse the repository at this point in the history
The current implementation assumed that attributes always
come before the return-type. However, this is not the case.
This patch uses the attribute location only if it is before
the location of the function declaration.
  • Loading branch information
andreasfertig committed Dec 12, 2020
1 parent ec409c1 commit 4d660f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions FunctionDeclHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ void FunctionDeclHandler::run(const MatchFinder::MatchResult& result)
// Find the first attribute with a valid source-location
for(const auto& attr : funcDecl->attrs()) {
if(const auto location = attr->getLocation(); location.isValid()) {
// the -3 are a guess that seems to work
funcRange.setBegin(location.getLocWithOffset(-3));

// only use the begin location of the attribute, if it is before the one of the function decl.
if(funcRange.getBegin() > location) {
// the -3 are a guess that seems to work
funcRange.setBegin(location.getLocWithOffset(-3));
}

return funcRange;
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Issue354.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
unsigned __attribute__((const))
ctz(unsigned x)
{
return 0;
}
5 changes: 5 additions & 0 deletions tests/Issue354.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__attribute__((const)) unsigned int ctz(unsigned int x)
{
return 0;
}

0 comments on commit 4d660f6

Please sign in to comment.