@@ -301,14 +301,7 @@ namespace clang {
301
301
if (!getModule ())
302
302
return ;
303
303
304
- // Install an inline asm handler so that diagnostics get printed through
305
- // our diagnostics hooks.
306
304
LLVMContext &Ctx = getModule ()->getContext ();
307
- LLVMContext::InlineAsmDiagHandlerTy OldHandler =
308
- Ctx.getInlineAsmDiagnosticHandler ();
309
- void *OldContext = Ctx.getInlineAsmDiagnosticContext ();
310
- Ctx.setInlineAsmDiagnosticHandler (InlineAsmDiagHandler, this );
311
-
312
305
std::unique_ptr<DiagnosticHandler> OldDiagnosticHandler =
313
306
Ctx.getDiagnosticHandler ();
314
307
Ctx.setDiagnosticHandler (std::make_unique<ClangDiagnosticHandler>(
@@ -342,8 +335,6 @@ namespace clang {
342
335
LangOpts, C.getTargetInfo ().getDataLayout (),
343
336
getModule (), Action, std::move (AsmOutStream));
344
337
345
- Ctx.setInlineAsmDiagnosticHandler (OldHandler, OldContext);
346
-
347
338
Ctx.setDiagnosticHandler (std::move (OldDiagnosticHandler));
348
339
349
340
if (OptRecordFile)
@@ -377,27 +368,20 @@ namespace clang {
377
368
Gen->HandleVTable (RD);
378
369
}
379
370
380
- static void InlineAsmDiagHandler (const llvm::SMDiagnostic &SM,void *Context,
381
- unsigned LocCookie) {
382
- SourceLocation Loc = SourceLocation::getFromRawEncoding (LocCookie);
383
- ((BackendConsumer*)Context)->InlineAsmDiagHandler2 (SM, Loc);
384
- }
385
-
386
371
// / Get the best possible source location to represent a diagnostic that
387
372
// / may have associated debug info.
388
373
const FullSourceLoc
389
374
getBestLocationFromDebugLoc (const llvm::DiagnosticInfoWithLocationBase &D,
390
375
bool &BadDebugInfo, StringRef &Filename,
391
376
unsigned &Line, unsigned &Column) const ;
392
377
393
- void InlineAsmDiagHandler2 (const llvm::SMDiagnostic &,
394
- SourceLocation LocCookie);
395
-
396
378
void DiagnosticHandlerImpl (const llvm::DiagnosticInfo &DI);
397
379
// / Specialized handler for InlineAsm diagnostic.
398
380
// / \return True if the diagnostic has been successfully reported, false
399
381
// / otherwise.
400
382
bool InlineAsmDiagHandler (const llvm::DiagnosticInfoInlineAsm &D);
383
+ // / Specialized handler for diagnostics reported using SMDiagnostic.
384
+ void SrcMgrDiagHandler (const llvm::DiagnosticInfoSrcMgr &D);
401
385
// / Specialized handler for StackSize diagnostic.
402
386
// / \return True if the diagnostic has been successfully reported, false
403
387
// / otherwise.
@@ -456,64 +440,6 @@ static FullSourceLoc ConvertBackendLocation(const llvm::SMDiagnostic &D,
456
440
return FullSourceLoc (NewLoc, CSM);
457
441
}
458
442
459
-
460
- // / InlineAsmDiagHandler2 - This function is invoked when the backend hits an
461
- // / error parsing inline asm. The SMDiagnostic indicates the error relative to
462
- // / the temporary memory buffer that the inline asm parser has set up.
463
- void BackendConsumer::InlineAsmDiagHandler2 (const llvm::SMDiagnostic &D,
464
- SourceLocation LocCookie) {
465
- // There are a couple of different kinds of errors we could get here. First,
466
- // we re-format the SMDiagnostic in terms of a clang diagnostic.
467
-
468
- // Strip "error: " off the start of the message string.
469
- StringRef Message = D.getMessage ();
470
- if (Message.startswith (" error: " ))
471
- Message = Message.substr (7 );
472
-
473
- // If the SMDiagnostic has an inline asm source location, translate it.
474
- FullSourceLoc Loc;
475
- if (D.getLoc () != SMLoc ())
476
- Loc = ConvertBackendLocation (D, Context->getSourceManager ());
477
-
478
- unsigned DiagID;
479
- switch (D.getKind ()) {
480
- case llvm::SourceMgr::DK_Error:
481
- DiagID = diag::err_fe_inline_asm;
482
- break ;
483
- case llvm::SourceMgr::DK_Warning:
484
- DiagID = diag::warn_fe_inline_asm;
485
- break ;
486
- case llvm::SourceMgr::DK_Note:
487
- DiagID = diag::note_fe_inline_asm;
488
- break ;
489
- case llvm::SourceMgr::DK_Remark:
490
- llvm_unreachable (" remarks unexpected" );
491
- }
492
- // If this problem has clang-level source location information, report the
493
- // issue in the source with a note showing the instantiated
494
- // code.
495
- if (LocCookie.isValid ()) {
496
- Diags.Report (LocCookie, DiagID).AddString (Message);
497
-
498
- if (D.getLoc ().isValid ()) {
499
- DiagnosticBuilder B = Diags.Report (Loc, diag::note_fe_inline_asm_here);
500
- // Convert the SMDiagnostic ranges into SourceRange and attach them
501
- // to the diagnostic.
502
- for (const std::pair<unsigned , unsigned > &Range : D.getRanges ()) {
503
- unsigned Column = D.getColumnNo ();
504
- B << SourceRange (Loc.getLocWithOffset (Range.first - Column),
505
- Loc.getLocWithOffset (Range.second - Column));
506
- }
507
- }
508
- return ;
509
- }
510
-
511
- // Otherwise, report the backend issue as occurring in the generated .s file.
512
- // If Loc is invalid, we still need to report the issue, it just gets no
513
- // location info.
514
- Diags.Report (Loc, DiagID).AddString (Message);
515
- }
516
-
517
443
#define ComputeDiagID (Severity, GroupName, DiagID ) \
518
444
do { \
519
445
switch (Severity) { \
@@ -550,6 +476,65 @@ void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D,
550
476
} \
551
477
} while (false )
552
478
479
+ void BackendConsumer::SrcMgrDiagHandler (const llvm::DiagnosticInfoSrcMgr &DI) {
480
+ const llvm::SMDiagnostic &D = DI.getSMDiag ();
481
+
482
+ unsigned DiagID;
483
+ if (DI.isInlineAsmDiag ())
484
+ ComputeDiagID (DI.getSeverity (), inline_asm, DiagID);
485
+ else
486
+ ComputeDiagID (DI.getSeverity (), source_mgr, DiagID);
487
+
488
+ // This is for the empty BackendConsumer that uses the clang diagnostic
489
+ // handler for IR input files.
490
+ if (!Context) {
491
+ D.print (nullptr , llvm::errs ());
492
+ Diags.Report (DiagID).AddString (" cannot compile inline asm" );
493
+ return ;
494
+ }
495
+
496
+ // There are a couple of different kinds of errors we could get here.
497
+ // First, we re-format the SMDiagnostic in terms of a clang diagnostic.
498
+
499
+ // Strip "error: " off the start of the message string.
500
+ StringRef Message = D.getMessage ();
501
+ (void )Message.consume_front (" error: " );
502
+
503
+ // If the SMDiagnostic has an inline asm source location, translate it.
504
+ FullSourceLoc Loc;
505
+ if (D.getLoc () != SMLoc ())
506
+ Loc = ConvertBackendLocation (D, Context->getSourceManager ());
507
+
508
+ // If this problem has clang-level source location information, report the
509
+ // issue in the source with a note showing the instantiated
510
+ // code.
511
+ if (DI.isInlineAsmDiag ()) {
512
+ SourceLocation LocCookie =
513
+ SourceLocation::getFromRawEncoding (DI.getLocCookie ());
514
+ if (LocCookie.isValid ()) {
515
+ Diags.Report (LocCookie, DiagID).AddString (Message);
516
+
517
+ if (D.getLoc ().isValid ()) {
518
+ DiagnosticBuilder B = Diags.Report (Loc, diag::note_fe_inline_asm_here);
519
+ // Convert the SMDiagnostic ranges into SourceRange and attach them
520
+ // to the diagnostic.
521
+ for (const std::pair<unsigned , unsigned > &Range : D.getRanges ()) {
522
+ unsigned Column = D.getColumnNo ();
523
+ B << SourceRange (Loc.getLocWithOffset (Range.first - Column),
524
+ Loc.getLocWithOffset (Range.second - Column));
525
+ }
526
+ }
527
+ return ;
528
+ }
529
+ }
530
+
531
+ // Otherwise, report the backend issue as occurring in the generated .s file.
532
+ // If Loc is invalid, we still need to report the issue, it just gets no
533
+ // location info.
534
+ Diags.Report (Loc, DiagID).AddString (Message);
535
+ return ;
536
+ }
537
+
553
538
bool
554
539
BackendConsumer::InlineAsmDiagHandler (const llvm::DiagnosticInfoInlineAsm &D) {
555
540
unsigned DiagID;
@@ -783,6 +768,9 @@ void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) {
783
768
return ;
784
769
ComputeDiagID (Severity, inline_asm, DiagID);
785
770
break ;
771
+ case llvm::DK_SrcMgr:
772
+ SrcMgrDiagHandler (cast<DiagnosticInfoSrcMgr>(DI));
773
+ return ;
786
774
case llvm::DK_StackSize:
787
775
if (StackSizeDiagHandler (cast<DiagnosticInfoStackSize>(DI)))
788
776
return ;
@@ -979,30 +967,6 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
979
967
return std::move (Result);
980
968
}
981
969
982
- static void BitcodeInlineAsmDiagHandler (const llvm::SMDiagnostic &SM,
983
- void *Context,
984
- unsigned LocCookie) {
985
- SM.print (nullptr , llvm::errs ());
986
-
987
- auto Diags = static_cast <DiagnosticsEngine *>(Context);
988
- unsigned DiagID;
989
- switch (SM.getKind ()) {
990
- case llvm::SourceMgr::DK_Error:
991
- DiagID = diag::err_fe_inline_asm;
992
- break ;
993
- case llvm::SourceMgr::DK_Warning:
994
- DiagID = diag::warn_fe_inline_asm;
995
- break ;
996
- case llvm::SourceMgr::DK_Note:
997
- DiagID = diag::note_fe_inline_asm;
998
- break ;
999
- case llvm::SourceMgr::DK_Remark:
1000
- llvm_unreachable (" remarks unexpected" );
1001
- }
1002
-
1003
- Diags->Report (DiagID).AddString (" cannot compile inline asm" );
1004
- }
1005
-
1006
970
std::unique_ptr<llvm::Module>
1007
971
CodeGenAction::loadModule (MemoryBufferRef MBRef) {
1008
972
CompilerInstance &CI = getCompilerInstance ();
@@ -1105,7 +1069,6 @@ void CodeGenAction::ExecuteAction() {
1105
1069
EmbedBitcode (TheModule.get (), CodeGenOpts, *MainFile);
1106
1070
1107
1071
LLVMContext &Ctx = TheModule->getContext ();
1108
- Ctx.setInlineAsmDiagnosticHandler (BitcodeInlineAsmDiagHandler, &Diagnostics);
1109
1072
1110
1073
// Restore any diagnostic handler previously set before returning from this
1111
1074
// function.
0 commit comments