clang 24.0.0git
BackendDiagnosticHandler.cpp
Go to the documentation of this file.
1//===--- BackendDiagnosticHandler.cpp - Shared Backend Diagnostics ------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
15#include "llvm/ADT/Hashing.h"
16#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
17#include "llvm/Demangle/Demangle.h"
18#include "llvm/IR/DiagnosticInfo.h"
19#include "llvm/IR/DiagnosticPrinter.h"
20#include "llvm/IR/Function.h"
21#include "llvm/IR/Module.h"
22#include "llvm/Support/raw_ostream.h"
23
24using namespace clang;
25using namespace llvm;
26
27namespace {
28/// Forwards llvm::DiagnosticHandler callbacks into a BackendDiagnosticConsumer.
29class BackendDiagnosticHandlerImpl final : public DiagnosticHandler {
30public:
31 BackendDiagnosticHandlerImpl(const clang::CodeGenOptions &CGOpts,
32 BackendDiagnosticConsumer *Consumer)
33 : CodeGenOpts(CGOpts), Consumer(Consumer) {}
34
35 bool handleDiagnostics(const DiagnosticInfo &DI) override {
36 Consumer->handleDiagnostics(DI);
37 return true;
38 }
39
40 bool isAnalysisRemarkEnabled(StringRef PassName) const override {
41 return CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(PassName);
42 }
43 bool isMissedOptRemarkEnabled(StringRef PassName) const override {
44 return CodeGenOpts.OptimizationRemarkMissed.patternMatches(PassName);
45 }
46 bool isPassedOptRemarkEnabled(StringRef PassName) const override {
47 return CodeGenOpts.OptimizationRemark.patternMatches(PassName);
48 }
49
50 bool isAnyRemarkEnabled() const override {
51 return CodeGenOpts.OptimizationRemarkAnalysis.hasValidPattern() ||
52 CodeGenOpts.OptimizationRemarkMissed.hasValidPattern() ||
53 CodeGenOpts.OptimizationRemark.hasValidPattern();
54 }
55
56private:
57 const clang::CodeGenOptions &CodeGenOpts;
58 BackendDiagnosticConsumer *Consumer;
59};
60
61/// Convert a location in a temporary llvm::SourceMgr buffer to be a valid
62/// FullSourceLoc.
63FullSourceLoc ConvertBackendLocation(const llvm::SMDiagnostic &D,
64 SourceManager &CSM) {
65 // Get both the clang and llvm source managers. The location is relative to
66 // a memory buffer that the LLVM Source Manager is handling, we need to add
67 // a copy to the Clang source manager.
68 const llvm::SourceMgr &LSM = *D.getSourceMgr();
69
70 // We need to copy the underlying LLVM memory buffer because llvm::SourceMgr
71 // already owns its one and clang::SourceManager wants to own its one.
72 const MemoryBuffer *LBuf =
73 LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc()));
74
75 // Create the copy and transfer ownership to clang::SourceManager.
76 // TODO: Avoid copying files into memory.
77 std::unique_ptr<llvm::MemoryBuffer> CBuf =
78 llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(),
79 LBuf->getBufferIdentifier());
80 // FIXME: Keep a file ID map instead of creating new IDs for each location.
81 FileID FID = CSM.createFileID(std::move(CBuf));
82
83 // Translate the offset into the file.
84 unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart();
85 SourceLocation NewLoc =
87 return FullSourceLoc(NewLoc, CSM);
88}
89
90} // namespace
91
92#define ComputeDiagID(Severity, GroupName, DiagID) \
93 do { \
94 switch (Severity) { \
95 case llvm::DS_Error: \
96 DiagID = diag::err_fe_##GroupName; \
97 break; \
98 case llvm::DS_Warning: \
99 DiagID = diag::warn_fe_##GroupName; \
100 break; \
101 case llvm::DS_Remark: \
102 llvm_unreachable("'remark' severity not expected"); \
103 break; \
104 case llvm::DS_Note: \
105 DiagID = diag::note_fe_##GroupName; \
106 break; \
107 } \
108 } while (false)
109
110#define ComputeDiagRemarkID(Severity, GroupName, DiagID) \
111 do { \
112 switch (Severity) { \
113 case llvm::DS_Error: \
114 DiagID = diag::err_fe_##GroupName; \
115 break; \
116 case llvm::DS_Warning: \
117 DiagID = diag::warn_fe_##GroupName; \
118 break; \
119 case llvm::DS_Remark: \
120 DiagID = diag::remark_fe_##GroupName; \
121 break; \
122 case llvm::DS_Note: \
123 DiagID = diag::note_fe_##GroupName; \
124 break; \
125 } \
126 } while (false)
127
128std::unique_ptr<llvm::DiagnosticHandler>
130 return std::make_unique<BackendDiagnosticHandlerImpl>(CodeGenOpts, this);
131}
132
134 FullSourceLoc Loc) {
135 // TODO: use a fast content hash when available.
136 auto NameHash = llvm::hash_value(MangledName);
137 ManglingFullSourceLocs.push_back(std::make_pair(NameHash, Loc));
138}
139
140std::optional<FullSourceLoc>
142 auto Hash = llvm::hash_value(F.getName());
143 for (const auto &Pair : ManglingFullSourceLocs) {
144 if (Pair.first == Hash)
145 return Pair.second;
146 }
147 return std::nullopt;
148}
149
151BackendDiagnosticConsumer::getSourceFile(const llvm::DIFile *File,
152 ArrayRef<StringRef> Names) const {
153 auto It = DIFileSources.find(File);
154 // A DIFile shared by several files identifies none of them, and looking up
155 // its name could find the wrong one.
156 if (It != DIFileSources.end())
157 return It->second;
159 for (StringRef Name : Names)
160 if (auto FE = FileMgr.getOptionalFileRef(Name))
161 return FE;
162 return std::nullopt;
163}
164
166 const llvm::DiagnosticInfoWithLocationBase &D, bool &BadDebugInfo,
167 StringRef &Filename, unsigned &Line, unsigned &Column) const {
168 SourceManager &SourceMgr = *SM;
169 SourceLocation DILoc;
170
171 if (D.isLocationAvailable()) {
172 D.getLocation(Filename, Line, Column);
173 if (Line > 0) {
174 auto FE = getSourceFile(D.getLocation().getFile(),
175 {Filename, D.getAbsolutePath()});
176 if (FE) {
177 // If -gcolumn-info was not used, Column will be 0. This upsets the
178 // source manager, so pass 1 if Column is not set.
179 DILoc = SourceMgr.translateFileLineCol(*FE, Line, Column ? Column : 1);
180 }
181 }
182 BadDebugInfo = DILoc.isInvalid();
183 }
184
185 // If a location isn't available, try to approximate it using the associated
186 // function definition. We use the definition's right brace to differentiate
187 // from diagnostics that genuinely relate to the function itself.
188 FullSourceLoc Loc(DILoc, SourceMgr);
189 if (Loc.isInvalid()) {
190 if (auto MaybeLoc = getFunctionSourceLocation(D.getFunction()))
191 Loc = *MaybeLoc;
192 }
193
194 if (DILoc.isInvalid() && D.isLocationAvailable())
195 // If we were not able to translate the file:line:col information
196 // back to a SourceLocation, at least emit a note stating that
197 // we could not translate this location. This can happen in the
198 // case of #line directives.
199 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
200 << Filename << Line << Column;
201
202 return Loc;
203}
204
205void BackendDiagnosticConsumer::SrcMgrDiagHandler(
206 const llvm::DiagnosticInfoSrcMgr &DI) {
207 const llvm::SMDiagnostic &D = DI.getSMDiag();
208
209 unsigned DiagID;
210 if (DI.isInlineAsmDiag())
211 ComputeDiagID(DI.getSeverity(), inline_asm, DiagID);
212 else
213 ComputeDiagID(DI.getSeverity(), source_mgr, DiagID);
214
215 // This is for the empty consumer that uses the clang diagnostic
216 // handler for IR input files.
217 if (!SM) {
218 D.print(nullptr, llvm::errs());
219 Diags.Report(DiagID).AddString("cannot compile inline asm");
220 return;
221 }
222
223 // There are a couple of different kinds of errors we could get here.
224 // First, we re-format the SMDiagnostic in terms of a clang diagnostic.
225
226 // Strip "error: " off the start of the message string.
227 StringRef Message = D.getMessage();
228 (void)Message.consume_front("error: ");
229
230 // If the SMDiagnostic has an inline asm source location, translate it.
231 FullSourceLoc Loc;
232 if (D.getLoc() != SMLoc())
233 Loc = ConvertBackendLocation(D, *SM);
234
235 // If this problem has clang-level source location information, report the
236 // issue in the source with a note showing the instantiated
237 // code.
238 if (DI.isInlineAsmDiag()) {
239 SourceLocation LocCookie =
240 SourceLocation::getFromRawEncoding(DI.getLocCookie());
241 if (LocCookie.isValid()) {
242 Diags.Report(LocCookie, DiagID).AddString(Message);
243
244 if (D.getLoc().isValid()) {
245 DiagnosticBuilder B = Diags.Report(Loc, diag::note_fe_inline_asm_here);
246 // Convert the SMDiagnostic ranges into SourceRange and attach them
247 // to the diagnostic.
248 for (const std::pair<unsigned, unsigned> &Range : D.getRanges()) {
249 unsigned Column = D.getColumnNo();
250 B << SourceRange(Loc.getLocWithOffset(Range.first - Column),
251 Loc.getLocWithOffset(Range.second - Column));
252 }
253 }
254 return;
255 }
256 }
257
258 // Otherwise, report the backend issue as occurring in the generated .s file.
259 // If Loc is invalid, we still need to report the issue, it just gets no
260 // location info.
261 Diags.Report(Loc, DiagID).AddString(Message);
262}
263
264bool BackendDiagnosticConsumer::InlineAsmDiagHandler(
265 const llvm::DiagnosticInfoInlineAsm &D) {
266 unsigned DiagID;
267 ComputeDiagID(D.getSeverity(), inline_asm, DiagID);
268 std::string Message = D.getMsgStr().str();
269
270 // If this problem has clang-level source location information, report the
271 // issue as being a problem in the source with a note showing the instantiated
272 // code.
273 SourceLocation LocCookie =
274 SourceLocation::getFromRawEncoding(D.getLocCookie());
275 if (LocCookie.isValid())
276 Diags.Report(LocCookie, DiagID).AddString(Message);
277 else {
278 // Otherwise, report the backend diagnostic as occurring in the generated
279 // .s file.
280 // If Loc is invalid, we still need to report the diagnostic, it just gets
281 // no location info.
282 FullSourceLoc Loc;
283 Diags.Report(Loc, DiagID).AddString(Message);
284 }
285 // We handled all the possible severities.
286 return true;
287}
288
289bool BackendDiagnosticConsumer::StackSizeDiagHandler(
290 const llvm::DiagnosticInfoStackSize &D) {
291 if (D.getSeverity() != llvm::DS_Warning)
292 // For now, the only support we have for StackSize diagnostic is warning.
293 // We do not know how to format other severities.
294 return false;
295
296 auto Loc = getFunctionSourceLocation(D.getFunction());
297 if (!Loc)
298 return false;
299
300 Diags.Report(*Loc, diag::warn_fe_frame_larger_than)
301 << D.getStackSize() << D.getStackLimit()
302 << llvm::demangle(D.getFunction().getName());
303 return true;
304}
305
306bool BackendDiagnosticConsumer::ResourceLimitDiagHandler(
307 const llvm::DiagnosticInfoResourceLimit &D) {
308 auto Loc = getFunctionSourceLocation(D.getFunction());
309 if (!Loc)
310 return false;
311 unsigned DiagID = diag::err_fe_backend_resource_limit;
312 ComputeDiagID(D.getSeverity(), backend_resource_limit, DiagID);
313
314 Diags.Report(*Loc, DiagID)
315 << D.getResourceName() << D.getResourceSize() << D.getResourceLimit()
316 << llvm::demangle(D.getFunction().getName());
317 return true;
318}
319
320void BackendDiagnosticConsumer::UnsupportedDiagHandler(
321 const llvm::DiagnosticInfoUnsupported &D) {
322 // We only support warnings or errors.
323 assert(D.getSeverity() == llvm::DS_Error ||
324 D.getSeverity() == llvm::DS_Warning);
325
326 StringRef Filename;
327 unsigned Line, Column;
328 bool BadDebugInfo = false;
329 FullSourceLoc Loc;
330 std::string Msg;
331 raw_string_ostream MsgStream(Msg);
332
333 // SM will be null for IR input files, we will construct the diag
334 // message from llvm::DiagnosticInfoUnsupported.
335 if (SM != nullptr) {
336 Loc = getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
337 MsgStream << D.getMessage();
338 } else {
339 DiagnosticPrinterRawOStream DP(MsgStream);
340 D.print(DP);
341 }
342
343 auto DiagType = D.getSeverity() == llvm::DS_Error
344 ? diag::err_fe_backend_unsupported
345 : diag::warn_fe_backend_unsupported;
346 Diags.Report(Loc, DiagType) << Msg;
347
348 if (BadDebugInfo)
349 // If we were not able to translate the file:line:col information
350 // back to a SourceLocation, at least emit a note stating that
351 // we could not translate this location. This can happen in the
352 // case of #line directives.
353 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
354 << Filename << Line << Column;
355}
356
357void BackendDiagnosticConsumer::UnsupportedTargetIntrinsicDiagHandler(
358 const llvm::DiagnosticInfoUnsupportedTargetIntrinsic &D) {
359 assert(D.getSeverity() == llvm::DS_Error &&
360 "unsupported target intrinsic diagnostic should be an error");
361
362 StringRef Filename;
363 unsigned Line, Column;
364 bool BadDebugInfo = false;
365 FullSourceLoc Loc;
366 std::string Msg;
367 raw_string_ostream MsgStream(Msg);
368
369 // SM will be null for IR input files, so construct the diagnostic
370 // message from llvm::DiagnosticInfoUnsupportedTargetIntrinsic.
371 if (SM != nullptr) {
372 Loc = getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
373 MsgStream << D.getMessage();
374 } else {
375 DiagnosticPrinterRawOStream DP(MsgStream);
376 D.print(DP);
377 }
378
379 Diags.Report(Loc, diag::err_fe_backend_unsupported) << Msg;
380
381 if (BadDebugInfo) {
382 // If we were not able to translate the file:line:col information
383 // back to a SourceLocation, at least emit a note stating that
384 // we could not translate this location. This can happen in the
385 // case of #line directives.
386 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
387 << Filename << Line << Column;
388 }
389}
390
391void BackendDiagnosticConsumer::EmitOptimizationMessage(
392 const llvm::DiagnosticInfoOptimizationBase &D, unsigned DiagID) {
393 // We only support warnings and remarks.
394 assert(D.getSeverity() == llvm::DS_Remark ||
395 D.getSeverity() == llvm::DS_Warning);
396
397 StringRef Filename;
398 unsigned Line, Column;
399 bool BadDebugInfo = false;
400 FullSourceLoc Loc;
401 std::string Msg;
402 raw_string_ostream MsgStream(Msg);
403
404 // SM will be null for IR input files, we will construct the remark
405 // message from llvm::DiagnosticInfoOptimizationBase.
406 if (SM != nullptr) {
407 Loc = getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
408 MsgStream << D.getMsg();
409 } else {
410 DiagnosticPrinterRawOStream DP(MsgStream);
411 D.print(DP);
412 }
413
414 if (D.getHotness())
415 MsgStream << " (hotness: " << *D.getHotness() << ")";
416
417 Diags.Report(Loc, DiagID) << AddFlagValue(D.getPassName()) << Msg;
418
419 if (BadDebugInfo)
420 // If we were not able to translate the file:line:col information
421 // back to a SourceLocation, at least emit a note stating that
422 // we could not translate this location. This can happen in the
423 // case of #line directives.
424 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
425 << Filename << Line << Column;
426}
427
428void BackendDiagnosticConsumer::OptimizationRemarkHandler(
429 const llvm::DiagnosticInfoOptimizationBase &D) {
430 // Without hotness information, don't show noisy remarks.
431 if (D.isVerbose() && !D.getHotness())
432 return;
433
434 if (D.isPassed()) {
435 // Optimization remarks are active only if the -Rpass flag has a regular
436 // expression that matches the name of the pass name in \p D.
437 if (CodeGenOpts.OptimizationRemark.patternMatches(D.getPassName()))
438 EmitOptimizationMessage(D, diag::remark_fe_backend_optimization_remark);
439 } else if (D.isMissed()) {
440 // Missed optimization remarks are active only if the -Rpass-missed
441 // flag has a regular expression that matches the name of the pass
442 // name in \p D.
443 if (CodeGenOpts.OptimizationRemarkMissed.patternMatches(D.getPassName()))
444 EmitOptimizationMessage(
445 D, diag::remark_fe_backend_optimization_remark_missed);
446 } else {
447 assert(D.isAnalysis() && "Unknown remark type");
448
449 bool ShouldAlwaysPrint = false;
450 if (auto *ORA = dyn_cast<llvm::OptimizationRemarkAnalysis>(&D))
451 ShouldAlwaysPrint = ORA->shouldAlwaysPrint();
452
453 if (ShouldAlwaysPrint ||
454 CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(D.getPassName()))
455 EmitOptimizationMessage(
456 D, diag::remark_fe_backend_optimization_remark_analysis);
457 }
458}
459
460void BackendDiagnosticConsumer::OptimizationRemarkHandler(
461 const llvm::OptimizationRemarkAnalysisFPCommute &D) {
462 // Optimization analysis remarks are active if the pass name is set to
463 // llvm::DiagnosticInfo::AlwaysPrint or if the -Rpass-analysis flag has a
464 // regular expression that matches the name of the pass name in \p D.
465
466 if (D.shouldAlwaysPrint() ||
467 CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(D.getPassName()))
468 EmitOptimizationMessage(
469 D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute);
470}
471
472void BackendDiagnosticConsumer::OptimizationRemarkHandler(
473 const llvm::OptimizationRemarkAnalysisAliasing &D) {
474 // Optimization analysis remarks are active if the pass name is set to
475 // llvm::DiagnosticInfo::AlwaysPrint or if the -Rpass-analysis flag has a
476 // regular expression that matches the name of the pass name in \p D.
477
478 if (D.shouldAlwaysPrint() ||
479 CodeGenOpts.OptimizationRemarkAnalysis.patternMatches(D.getPassName()))
480 EmitOptimizationMessage(
481 D, diag::remark_fe_backend_optimization_remark_analysis_aliasing);
482}
483
484void BackendDiagnosticConsumer::OptimizationFailureHandler(
485 const llvm::DiagnosticInfoOptimizationFailure &D) {
486 EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure);
487}
488
489void BackendDiagnosticConsumer::DontCallDiagHandler(
490 const DiagnosticInfoDontCall &D) {
491 SourceLocation LocCookie =
492 SourceLocation::getFromRawEncoding(D.getLocCookie());
493
494 // FIXME: we can't yet diagnose indirect calls. When/if we can, we
495 // should instead assert that LocCookie.isValid().
496 if (!LocCookie.isValid())
497 return;
498
499 Diags.Report(LocCookie, D.getSeverity() == DiagnosticSeverity::DS_Error
500 ? diag::err_fe_backend_error_attr
501 : diag::warn_fe_backend_warning_attr)
502 << llvm::demangle(D.getFunctionName()) << D.getNote();
503
504 if (!CodeGenOpts.ShowInliningChain)
505 return;
506
507 auto EmitNote = [&](SourceLocation Loc, StringRef FuncName, bool IsFirst) {
508 if (!Loc.isValid())
509 Loc = LocCookie;
510 unsigned DiagID =
511 IsFirst ? diag::note_fe_backend_in : diag::note_fe_backend_inlined;
512 Diags.Report(Loc, DiagID) << llvm::demangle(FuncName.str());
513 };
514
515 // Try debug info first for accurate source locations.
516 if (!D.getDebugInlineChain().empty()) {
517 SourceManager &SrcMgr = *SM;
518 for (const auto &[I, Info] : llvm::enumerate(D.getDebugInlineChain())) {
519 SourceLocation Loc;
520 if (Info.Line > 0)
521 if (auto FE = getSourceFile(Info.File, Info.Filename))
522 Loc = SrcMgr.translateFileLineCol(*FE, Info.Line,
523 Info.Column ? Info.Column : 1);
524 EmitNote(Loc, Info.FuncName, I == 0);
525 }
526 return;
527 }
528
529 // Fall back to heuristic (srcloc metadata) when debug info is unavailable.
530 auto InliningDecisions = D.getInliningDecisions();
531 if (InliningDecisions.empty())
532 return;
533
534 for (const auto &[I, Entry] : llvm::enumerate(InliningDecisions)) {
535 SourceLocation Loc =
536 I == 0 ? LocCookie : SourceLocation::getFromRawEncoding(Entry.second);
537 EmitNote(Loc, Entry.first, I == 0);
538 }
539
540 // Suggest enabling debug info (at least -gline-directives-only) for more
541 // accurate locations.
542 Diags.Report(LocCookie, diag::note_fe_backend_inlining_debug_info);
543}
544
545void BackendDiagnosticConsumer::MisExpectDiagHandler(
546 const llvm::DiagnosticInfoMisExpect &D) {
547 StringRef Filename;
548 unsigned Line, Column;
549 bool BadDebugInfo = false;
550 FullSourceLoc Loc =
551 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
552
553 Diags.Report(Loc, diag::warn_profile_data_misexpect) << D.getMsg().str();
554
555 if (BadDebugInfo)
556 // If we were not able to translate the file:line:col information
557 // back to a SourceLocation, at least emit a note stating that
558 // we could not translate this location. This can happen in the
559 // case of #line directives.
560 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
561 << Filename << Line << Column;
562}
563
564void BackendDiagnosticConsumer::handleDiagnostics(const DiagnosticInfo &DI) {
565 unsigned DiagID = diag::err_fe_inline_asm;
566 llvm::DiagnosticSeverity Severity = DI.getSeverity();
567 // Get the diagnostic ID based.
568 switch (DI.getKind()) {
569 case llvm::DK_InlineAsm:
570 if (InlineAsmDiagHandler(cast<DiagnosticInfoInlineAsm>(DI)))
571 return;
572 ComputeDiagID(Severity, inline_asm, DiagID);
573 break;
574 case llvm::DK_SrcMgr:
575 SrcMgrDiagHandler(cast<DiagnosticInfoSrcMgr>(DI));
576 return;
577 case llvm::DK_StackSize:
578 if (StackSizeDiagHandler(cast<DiagnosticInfoStackSize>(DI)))
579 return;
580 ComputeDiagID(Severity, backend_frame_larger_than, DiagID);
581 break;
582 case llvm::DK_ResourceLimit:
583 if (ResourceLimitDiagHandler(cast<DiagnosticInfoResourceLimit>(DI)))
584 return;
585 ComputeDiagID(Severity, backend_resource_limit, DiagID);
586 break;
587 case DK_Linker:
588 ComputeDiagID(Severity, linking_module, DiagID);
589 break;
590 case llvm::DK_OptimizationRemark:
591 // Optimization remarks are always handled completely by this
592 // handler. There is no generic way of emitting them.
593 OptimizationRemarkHandler(cast<OptimizationRemark>(DI));
594 return;
595 case llvm::DK_OptimizationRemarkMissed:
596 // Optimization remarks are always handled completely by this
597 // handler. There is no generic way of emitting them.
598 OptimizationRemarkHandler(cast<OptimizationRemarkMissed>(DI));
599 return;
600 case llvm::DK_OptimizationRemarkAnalysis:
601 // Optimization remarks are always handled completely by this
602 // handler. There is no generic way of emitting them.
603 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysis>(DI));
604 return;
605 case llvm::DK_OptimizationRemarkAnalysisFPCommute:
606 // Optimization remarks are always handled completely by this
607 // handler. There is no generic way of emitting them.
608 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisFPCommute>(DI));
609 return;
610 case llvm::DK_OptimizationRemarkAnalysisAliasing:
611 // Optimization remarks are always handled completely by this
612 // handler. There is no generic way of emitting them.
613 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisAliasing>(DI));
614 return;
615 case llvm::DK_MachineOptimizationRemark:
616 // Optimization remarks are always handled completely by this
617 // handler. There is no generic way of emitting them.
618 OptimizationRemarkHandler(cast<MachineOptimizationRemark>(DI));
619 return;
620 case llvm::DK_MachineOptimizationRemarkMissed:
621 // Optimization remarks are always handled completely by this
622 // handler. There is no generic way of emitting them.
623 OptimizationRemarkHandler(cast<MachineOptimizationRemarkMissed>(DI));
624 return;
625 case llvm::DK_MachineOptimizationRemarkAnalysis:
626 // Optimization remarks are always handled completely by this
627 // handler. There is no generic way of emitting them.
628 OptimizationRemarkHandler(cast<MachineOptimizationRemarkAnalysis>(DI));
629 return;
630 case llvm::DK_OptimizationFailure:
631 // Optimization failures are always handled completely by this
632 // handler.
633 OptimizationFailureHandler(cast<DiagnosticInfoOptimizationFailure>(DI));
634 return;
635 case llvm::DK_Unsupported:
636 UnsupportedDiagHandler(cast<DiagnosticInfoUnsupported>(DI));
637 return;
638 case llvm::DK_UnsupportedTargetIntrinsic:
639 UnsupportedTargetIntrinsicDiagHandler(
641 return;
642 case llvm::DK_DontCall:
643 DontCallDiagHandler(cast<DiagnosticInfoDontCall>(DI));
644 return;
645 case llvm::DK_MisExpect:
646 MisExpectDiagHandler(cast<DiagnosticInfoMisExpect>(DI));
647 return;
648 default:
649 // Plugin IDs are not bound to any value as they are set dynamically.
650 ComputeDiagRemarkID(Severity, backend_plugin, DiagID);
651 break;
652 }
653 std::string MsgStorage;
654 {
655 raw_string_ostream Stream(MsgStorage);
656 DiagnosticPrinterRawOStream DP(Stream);
657 DI.print(DP);
658 }
659
660 if (DI.getKind() == DK_Linker) {
661 assert(CurLinkModule && "CurLinkModule must be set for linker diagnostics");
662 Diags.Report(DiagID) << CurLinkModule->getModuleIdentifier() << MsgStorage;
663 return;
664 }
665
666 // Report the backend message using the usual diagnostic mechanism.
667 FullSourceLoc Loc;
668 Diags.Report(Loc, DiagID).AddString(MsgStorage);
669}
670
671#undef ComputeDiagID
672#undef ComputeDiagRemarkID
#define ComputeDiagID(Severity, GroupName, DiagID)
#define ComputeDiagRemarkID(Severity, GroupName, DiagID)
Defines the Diagnostic-related interfaces.
Defines the clang::FileManager interface and associated types.
unsigned IsFirst
Indicates that this is the first token of the file.
Defines the SourceManager interface.
void addFunctionSourceLocation(StringRef MangledName, FullSourceLoc Loc)
Record the source location of the function with the given mangled name, used to approximate a locatio...
std::unique_ptr< llvm::DiagnosticHandler > createDiagnosticHandler()
Create an llvm::DiagnosticHandler that forwards diagnostics to this consumer.
std::optional< FullSourceLoc > getFunctionSourceLocation(const llvm::Function &F) const
void handleDiagnostics(const llvm::DiagnosticInfo &DI)
This is invoked when the backend needs to report something to the user.
const FullSourceLoc getBestLocationFromDebugLoc(const llvm::DiagnosticInfoWithLocationBase &D, bool &BadDebugInfo, StringRef &Filename, unsigned &Line, unsigned &Column) const
Get the best possible source location to represent a diagnostic that may have associated debug info.
A little helper class used to produce diagnostics.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Implements support for file system lookup, file system caching, and directory search management.
Definition FileManager.h:57
A SourceLocation and its associated SourceManager.
Encodes a location in the source.
static SourceLocation getFromRawEncoding(UIntTy Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
This class handles loading and caching of source files into memory.
FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
FileManager & getFileManager() const
SourceLocation translateFileLineCol(const FileEntry *SourceFile, unsigned Line, unsigned Col) const
Get the source location for the given file:line:col triplet.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
A trivial tuple used to represent a source range.
void AddString(StringRef V) const
Top level wrappers for InstallAPI frontend operations.
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
Definition FileEntry.h:196
U cast(CodeGen::Address addr)
Definition Address.h:327
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
hash_code hash_value(const clang::dependencies::ModuleID &ID)