From 2943071e2ee0c7f31f34062a44d12aeb0e3a66fd Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Thu, 23 Sep 2021 13:54:24 -0700 Subject: [clang] Rework dontcall attributes To avoid using the AST when emitting diagnostics, split the "dontcall" attribute into "dontcall-warn" and "dontcall-error", and also add the frontend attribute value as the LLVM attribute value. This gives us all the information to report diagnostics we need from within the IR (aside from access to the original source). One downside is we directly use LLVM's demangler rather than using the existing Clang diagnostic pretty printing of symbols. Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D110364 --- clang/lib/CodeGen/CodeGenAction.cpp | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenAction.cpp') diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 789c06a..6e1d7f3 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -27,6 +27,7 @@ #include "clang/Lex/Preprocessor.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" +#include "llvm/Demangle/Demangle.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/DiagnosticPrinter.h" @@ -760,30 +761,18 @@ void BackendConsumer::OptimizationFailureHandler( } void BackendConsumer::DontCallDiagHandler(const DiagnosticInfoDontCall &D) { - if (const Decl *DE = Gen->GetDeclForMangledName(D.getFunctionName())) - if (const auto *FD = dyn_cast(DE)) { - assert(FD->hasAttr() && - "expected error or warning function attribute"); - - if (const auto *EA = FD->getAttr()) { - assert((EA->isError() || EA->isWarning()) && - "ErrorAttr neither error or warning"); - - SourceLocation LocCookie = - SourceLocation::getFromRawEncoding(D.getLocCookie()); - - // FIXME: we can't yet diagnose indirect calls. When/if we can, we - // should instead assert that LocCookie.isValid(). - if (!LocCookie.isValid()) - return; - - Diags.Report(LocCookie, EA->isError() - ? diag::err_fe_backend_error_attr - : diag::warn_fe_backend_warning_attr) - << FD << EA->getUserDiagnostic(); - } - } - // TODO: assert if DE or FD were nullptr? + SourceLocation LocCookie = + SourceLocation::getFromRawEncoding(D.getLocCookie()); + + // FIXME: we can't yet diagnose indirect calls. When/if we can, we + // should instead assert that LocCookie.isValid(). + if (!LocCookie.isValid()) + return; + + Diags.Report(LocCookie, D.getSeverity() == DiagnosticSeverity::DS_Error + ? diag::err_fe_backend_error_attr + : diag::warn_fe_backend_warning_attr) + << llvm::demangle(D.getFunctionName().str()) << D.getNote(); } /// This function is invoked when the backend needs -- cgit v1.1