@@ -1264,11 +1264,36 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
1264
1264
else if (isNoUsageDiagnostic (diagnostic.getID ()))
1265
1265
Category = " no-usage" ;
1266
1266
1267
+ auto fixIts = diagnostic.getFixIts ();
1268
+ if (loc.isValid ()) {
1269
+ // If the diagnostic is being emitted in a generated buffer, drop the
1270
+ // fix-its, as the user will have no way of applying them.
1271
+ auto bufferID = SourceMgr.findBufferContainingLoc (loc);
1272
+ if (auto generatedInfo = SourceMgr.getGeneratedSourceInfo (bufferID)) {
1273
+ switch (generatedInfo->kind ) {
1274
+ case GeneratedSourceInfo::ExpressionMacroExpansion:
1275
+ case GeneratedSourceInfo::FreestandingDeclMacroExpansion:
1276
+ case GeneratedSourceInfo::AccessorMacroExpansion:
1277
+ case GeneratedSourceInfo::MemberAttributeMacroExpansion:
1278
+ case GeneratedSourceInfo::MemberMacroExpansion:
1279
+ case GeneratedSourceInfo::PeerMacroExpansion:
1280
+ case GeneratedSourceInfo::ConformanceMacroExpansion:
1281
+ case GeneratedSourceInfo::PrettyPrinted:
1282
+ fixIts = {};
1283
+ break ;
1284
+ case GeneratedSourceInfo::ReplacedFunctionBody:
1285
+ // A replaced function body is for user-written code, so fix-its are
1286
+ // still valid.
1287
+ break ;
1288
+ }
1289
+ }
1290
+ }
1291
+
1267
1292
return DiagnosticInfo (
1268
1293
diagnostic.getID (), loc, toDiagnosticKind (behavior),
1269
1294
diagnosticStringFor (diagnostic.getID (), getPrintDiagnosticNames ()),
1270
1295
diagnostic.getArgs (), Category, getDefaultDiagnosticLoc (),
1271
- /* child note info*/ {}, diagnostic.getRanges (), diagnostic. getFixIts () ,
1296
+ /* child note info*/ {}, diagnostic.getRanges (), fixIts ,
1272
1297
diagnostic.isChildNote ());
1273
1298
}
1274
1299
0 commit comments