Skip to content

Commit 1fcfc0a

Browse files
Vladislav Aranovgiulianobelinassi
authored andcommitted
Eliminate the assert in specific situations.
The llvm code generates an assert originating from https://clang.llvm.org/doxygen/DeclBase_8cpp_source.html#l01047 in case of requesting attributes when attributes are not there. This change addresses this case.
1 parent 5da3619 commit 1fcfc0a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

libcextract/PrettyPrint.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ SourceLocation PrettyPrint::Get_Expanded_Loc(Decl *decl)
403403
Therefore we must check for the attributes of this declaration and compute
404404
the furthest location. */
405405

406-
AttrVec &attrvec = decl->getAttrs();
407406
bool has_attr = false;
408407
SourceManager &SM = AST->getSourceManager();
409408

@@ -416,14 +415,18 @@ SourceLocation PrettyPrint::Get_Expanded_Loc(Decl *decl)
416415
}
417416
}
418417

419-
for (size_t i = 0; i < attrvec.size(); i++) {
420-
const Attr *attr = attrvec[i];
421-
SourceLocation loc = attr->getRange().getEnd();
422-
loc = SM.getExpansionLoc(loc);
423-
424-
if (loc.isValid() && Is_Before(furthest, loc)) {
425-
furthest = loc;
426-
has_attr = true;
418+
/* Get atttributes vector if it exists. */
419+
if(decl->hasAttrs()) {
420+
AttrVec &attrvec = decl->getAttrs();
421+
for (size_t i = 0; i < attrvec.size(); i++) {
422+
const Attr *attr = attrvec[i];
423+
SourceLocation loc = attr->getRange().getEnd();
424+
loc = SM.getExpansionLoc(loc);
425+
426+
if (loc.isValid() && Is_Before(furthest, loc)) {
427+
furthest = loc;
428+
has_attr = true;
429+
}
427430
}
428431
}
429432

0 commit comments

Comments
 (0)