From 506deca07fd8c38f3a2fc7ae86e7bbfb555d35d7 Mon Sep 17 00:00:00 2001 From: Chris Kitching Date: Mon, 13 Nov 2017 16:14:42 +0000 Subject: [PATCH] Use proper clang diagnostics for printing warnings Much pretty. Very wow This gives users all the usual power when it comes to manipulating clang diagnostics. People can pass -Werror can have hipify fail if it doesn't completely translate a file, for example. Much nicer than reinventing the wheel. --- hipamd/hipify-clang/src/HipifyAction.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hipamd/hipify-clang/src/HipifyAction.cpp b/hipamd/hipify-clang/src/HipifyAction.cpp index 7608e4040b..192dd00949 100644 --- a/hipamd/hipify-clang/src/HipifyAction.cpp +++ b/hipamd/hipify-clang/src/HipifyAction.cpp @@ -76,7 +76,9 @@ void HipifyAction::RewriteToken(const clang::Token& t) { clang::SourceLocation sl = t.getLocation(); if (found->second.unsupported) { // An unsupported identifier? Curses! Warn the user. - llvm::errs() << "Unsupported CUDA identifier used: " + name.str() << "\n"; + clang::DiagnosticsEngine& DE = getCompilerInstance().getDiagnostics(); + const auto ID = DE.getCustomDiagID(clang::DiagnosticsEngine::Warning, "CUDA identifier unsupported in hip"); + DE.Report(sl, ID); return; } @@ -284,8 +286,9 @@ bool HipifyAction::cudaBuiltin(const clang::ast_matchers::MatchFinder::MatchResu insertReplacement(Rep, fullSL); } } else { - std::string msg = "the following reference is not handled: '" + name.str() + "' [builtin]."; - llvm::errs() << msg << "\n"; + clang::DiagnosticsEngine& DE = getCompilerInstance().getDiagnostics(); + const auto ID = DE.getCustomDiagID(clang::DiagnosticsEngine::Warning, "Unknown CUDA builtin"); + DE.Report(sl, ID); } return true;