Warn about unsupported codegen with the diags machinery, giving us:
t.c:3322:5: warning: cannot codegen this yet
__asm__ ("bswap %0" : "+r" (_data));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
instead of:
Unimplemented stmt!
(AsmStmt 0x80eaa0 <t.c:3331:5, line:3334:28>)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44501 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CodeGen/CGStmt.cpp b/CodeGen/CGStmt.cpp
index b010e81..d41d2de 100644
--- a/CodeGen/CGStmt.cpp
+++ b/CodeGen/CGStmt.cpp
@@ -19,6 +19,9 @@
using namespace clang;
using namespace CodeGen;
+#include "clang/Basic/Diagnostic.h"
+#include "CodeGenModule.h"
+
//===----------------------------------------------------------------------===//
// Statement Emission
//===----------------------------------------------------------------------===//
@@ -38,8 +41,11 @@
else
EmitAggExpr(E, 0, false);
} else {
- fprintf(stderr, "Unimplemented stmt!\n");
- S->dump(getContext().SourceMgr);
+
+ unsigned DiagID = CGM.getDiags().getCustomDiagID(Diagnostic::Warning,
+ "cannot codegen this yet");
+ SourceRange Range = S->getSourceRange();
+ CGM.getDiags().Report(S->getLocStart(), DiagID, 0, 0, &Range, 1);
}
break;
case Stmt::NullStmtClass: break;
diff --git a/CodeGen/CodeGenModule.cpp b/CodeGen/CodeGenModule.cpp
index 171a70c..54009b0 100644
--- a/CodeGen/CodeGenModule.cpp
+++ b/CodeGen/CodeGenModule.cpp
@@ -26,8 +26,9 @@
CodeGenModule::CodeGenModule(ASTContext &C, const LangOptions &LO,
- llvm::Module &M, const llvm::TargetData &TD)
- : Context(C), Features(LO), TheModule(M), TheTargetData(TD),
+ llvm::Module &M, const llvm::TargetData &TD,
+ Diagnostic &diags)
+ : Context(C), Features(LO), TheModule(M), TheTargetData(TD), Diags(diags),
Types(C, M, TD), MemCpyFn(0), CFConstantStringClassRef(0) {}
llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const ValueDecl *D) {
diff --git a/CodeGen/CodeGenModule.h b/CodeGen/CodeGenModule.h
index 9278e68..c4867c0 100644
--- a/CodeGen/CodeGenModule.h
+++ b/CodeGen/CodeGenModule.h
@@ -34,6 +34,7 @@
class ValueDecl;
class FileVarDecl;
struct LangOptions;
+ class Diagnostic;
namespace CodeGen {
@@ -44,6 +45,7 @@
const LangOptions &Features;
llvm::Module &TheModule;
const llvm::TargetData &TheTargetData;
+ Diagnostic &Diags;
CodeGenTypes Types;
llvm::Function *MemCpyFn;
@@ -56,12 +58,13 @@
std::vector<llvm::Function *> BuiltinFunctions;
public:
CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M,
- const llvm::TargetData &TD);
+ const llvm::TargetData &TD, Diagnostic &Diags);
ASTContext &getContext() const { return Context; }
const LangOptions &getLangOptions() const { return Features; }
llvm::Module &getModule() const { return TheModule; }
CodeGenTypes &getTypes() { return Types; }
+ Diagnostic &getDiags() const { return Diags; }
llvm::Constant *GetAddrOfGlobalDecl(const ValueDecl *D);
diff --git a/CodeGen/ModuleBuilder.cpp b/CodeGen/ModuleBuilder.cpp
index adc1878..9d28749 100644
--- a/CodeGen/ModuleBuilder.cpp
+++ b/CodeGen/ModuleBuilder.cpp
@@ -19,8 +19,9 @@
/// Init - Create an ModuleBuilder with the specified ASTContext.
clang::CodeGen::CodeGenModule *
clang::CodeGen::Init(ASTContext &Context, const LangOptions &Features,
- llvm::Module &M, const llvm::TargetData &TD) {
- return new CodeGenModule(Context, Features, M, TD);
+ llvm::Module &M, const llvm::TargetData &TD,
+ Diagnostic &Diags) {
+ return new CodeGenModule(Context, Features, M, TD, Diags);
}
void clang::CodeGen::Terminate(CodeGenModule *B) {
diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp
index a3d837f..da9cf64 100644
--- a/Driver/ASTConsumers.cpp
+++ b/Driver/ASTConsumers.cpp
@@ -570,7 +570,7 @@
M = new llvm::Module("foo");
M->setTargetTriple(Ctx->Target.getTargetTriple());
TD = new llvm::TargetData(Ctx->Target.getTargetDescription());
- Builder = CodeGen::Init(Context, Features, *M, *TD);
+ Builder = CodeGen::Init(Context, Features, *M, *TD, Diags);
}
virtual void HandleTopLevelDecl(Decl *D) {
diff --git a/include/clang/CodeGen/ModuleBuilder.h b/include/clang/CodeGen/ModuleBuilder.h
index 9ca3648..2ab7d2d 100644
--- a/include/clang/CodeGen/ModuleBuilder.h
+++ b/include/clang/CodeGen/ModuleBuilder.h
@@ -24,13 +24,15 @@
class FunctionDecl;
class FileVarDecl;
struct LangOptions;
+ class Diagnostic;
namespace CodeGen {
class CodeGenModule;
/// Init - Create an ModuleBuilder with the specified ASTContext.
CodeGenModule *Init(ASTContext &Context, const LangOptions &Features,
- llvm::Module &M, const llvm::TargetData &TD);
+ llvm::Module &M, const llvm::TargetData &TD,
+ Diagnostic &Diags);
/// CodeGenFunction - Convert the AST node for a FunctionDecl into LLVM.
///