aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenAction.cpp
diff options
context:
space:
mode:
authorArthur Eubanks <aeubanks@google.com>2021-09-23 13:54:24 -0700
committerArthur Eubanks <aeubanks@google.com>2021-09-28 14:21:10 -0700
commit2943071e2ee0c7f31f34062a44d12aeb0e3a66fd (patch)
treecb2d13bc12775a1f42520c469a9c68d5abac4ae8 /clang/lib/CodeGen/CodeGenAction.cpp
parent8379fc4a53cfd9e1a0280d60908ad4a171ad977d (diff)
downloadllvm-2943071e2ee0c7f31f34062a44d12aeb0e3a66fd.zip
llvm-2943071e2ee0c7f31f34062a44d12aeb0e3a66fd.tar.gz
llvm-2943071e2ee0c7f31f34062a44d12aeb0e3a66fd.tar.bz2
[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
Diffstat (limited to 'clang/lib/CodeGen/CodeGenAction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenAction.cpp37
1 files changed, 13 insertions, 24 deletions
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<FunctionDecl>(DE)) {
- assert(FD->hasAttr<ErrorAttr>() &&
- "expected error or warning function attribute");
-
- if (const auto *EA = FD->getAttr<ErrorAttr>()) {
- 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