Skip to content

Commit 924d795

Browse files
committed
Better handling of insertion points when no diagnostics are present
1 parent 096471c commit 924d795

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

main.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,20 @@ class INOPreprocessorMatcherCallback : public MatchFinder::MatchCallback {
160160
}
161161

162162
void detectInsertionPoint(SourceManager &sm, FullSourceLoc &begin, FullSourceLoc &end) {
163-
if (insertionPointFound)return;
163+
if (insertionPointFound) {
164+
return;
165+
}
164166

165-
FullSourceLoc first = undeclaredIdentifiers.front()->location;
167+
if (undeclaredIdentifiers.empty()) {
168+
//insertionPoint = begin;
169+
//insertionPointFound = true;
170+
//if (debugOutput) {
171+
// outs() << " !! Insertion point found (using the first available position)\n";
172+
//}
173+
return;
174+
}
166175

176+
FullSourceLoc first = undeclaredIdentifiers.back()->location;
167177
if (first.isBeforeInTranslationUnitThan(begin)) {
168178
if (debugOutput) {
169179
outs() << " !! Insertion point found!\n";
@@ -172,6 +182,10 @@ class INOPreprocessorMatcherCallback : public MatchFinder::MatchCallback {
172182
return;
173183
}
174184

185+
if (end.isInvalid()) {
186+
return;
187+
}
188+
175189
insertionPoint = begin;
176190
presumedInsertionPoint = sm.getPresumedLoc(begin, true);
177191
if (debugOutput) {

0 commit comments

Comments
 (0)