Skip to content

Commit 4f49598

Browse files
committed
Add Diagnostic files for Frontend and move a couple errors over.
- Notably, clang now exits with an error if it can't find a file. This flushed out a bug in the CGColorSpace.c test case. :) llvm-svn: 66789
1 parent 4ef9bc0 commit 4f49598

File tree

8 files changed

+92
-15
lines changed

8 files changed

+92
-15
lines changed

clang/Driver/clang.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
#include "clang.h"
2626
#include "ASTConsumers.h"
2727
#include "clang/Frontend/CompileOptions.h"
28-
#include "clang/Frontend/PathDiagnosticClients.h"
28+
#include "clang/Frontend/FrontendDiagnostic.h"
2929
#include "clang/Frontend/InitHeaderSearch.h"
30+
#include "clang/Frontend/PathDiagnosticClients.h"
3031
#include "clang/Frontend/TextDiagnosticBuffer.h"
3132
#include "clang/Frontend/TextDiagnosticPrinter.h"
3233
#include "clang/Analysis/PathDiagnostic.h"
@@ -857,14 +858,16 @@ static bool InitializePreprocessor(Preprocessor &PP,
857858
const FileEntry *File = FileMgr.getFile(InFile);
858859
if (File) SourceMgr.createMainFileID(File, SourceLocation());
859860
if (SourceMgr.getMainFileID().isInvalid()) {
860-
fprintf(stderr, "Error reading '%s'!\n",InFile.c_str());
861+
PP.getDiagnostics().Report(FullSourceLoc(), diag::err_fe_error_reading)
862+
<< InFile.c_str();
861863
return true;
862864
}
863865
} else {
864866
llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
865867
if (SB) SourceMgr.createMainFileIDForMemBuffer(SB);
866868
if (SourceMgr.getMainFileID().isInvalid()) {
867-
fprintf(stderr, "Error reading standard input! Empty?\n");
869+
PP.getDiagnostics().Report(FullSourceLoc(),
870+
diag::err_fe_error_reading_stdin);
868871
return true;
869872
}
870873
}
@@ -1525,9 +1528,8 @@ int main(int argc, char **argv) {
15251528
llvm::OwningPtr<TargetInfo> Target(TargetInfo::CreateTargetInfo(Triple));
15261529

15271530
if (Target == 0) {
1528-
fprintf(stderr, "Sorry, I don't know what target this is: %s\n",
1529-
Triple.c_str());
1530-
fprintf(stderr, "Please use -triple or -arch.\n");
1531+
Diags.Report(FullSourceLoc(), diag::err_fe_unknown_triple)
1532+
<< Triple.c_str();
15311533
return 1;
15321534
}
15331535

clang/include/clang/Basic/Diagnostic.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ namespace clang {
3333
// Start position for diagnostics.
3434
enum {
3535
DIAG_START_DRIVER = 300,
36-
DIAG_START_LEX = DIAG_START_DRIVER + 100,
36+
DIAG_START_FRONTEND = DIAG_START_DRIVER + 100,
37+
DIAG_START_LEX = DIAG_START_FRONTEND + 100,
3738
DIAG_START_PARSE = DIAG_START_LEX + 300,
3839
DIAG_START_AST = DIAG_START_PARSE + 300,
3940
DIAG_START_SEMA = DIAG_START_AST + 100,

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
let Component = "Driver" in {
1111

12-
def driver_no_such_file : Error<"no such file or directory: '%0'">
13-
def driver_unsupported_opt : Error<"unsupported option '%0'">
14-
def driver_unknown_stdin_type : Error<
12+
def err_drv_no_such_file : Error<"no such file or directory: '%0'">
13+
def err_drv_unsupported_opt : Error<"unsupported option '%0'">
14+
def err_drv_unknown_stdin_type : Error<
1515
"-E or -x required when input is from standard input">
16-
def driver_unknown_language : Error<"language not recognized: '%0'">
16+
def err_drv_unknown_language : Error<"language not recognized: '%0'">
1717

1818
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//==--- DiagnosticFrontendKinds.def - frontend diagnostics ------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifdef FRONTENDSTART
11+
__FRONTENDSTART = DIAG_START_FRONTEND,
12+
#undef FRONTENDSTART
13+
#endif
14+
15+
DIAG(err_fe_unknown_triple, ERROR,
16+
"unknown target triple '%0', please use -triple or -arch")
17+
DIAG(err_fe_error_reading, ERROR,
18+
"error reading '%0'")
19+
DIAG(err_fe_error_reading_stdin, ERROR,
20+
"error reading stdin")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//==--- DiagnosticFrontendKinds.td - frontend diagnostics -----------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
let Component = "Frontend" in {
11+
12+
def err_fe_error_reading, Error< "error reading '%0'">
13+
def err_fe_error_reading_stdin : Error<"error reading stdin">
14+
15+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===--- DiagnosticFrontend.h - Diagnostics for frontend --------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef LLVM_CLANG_FRONTENDDIAGNOSTIC_H
11+
#define LLVM_CLANG_FRONTENDDIAGNOSTIC_H
12+
13+
#include "clang/Basic/Diagnostic.h"
14+
15+
namespace clang {
16+
namespace diag {
17+
enum {
18+
#define DIAG(ENUM,FLAGS,DESC) ENUM,
19+
#define FRONTENDSTART
20+
#include "clang/Basic/DiagnosticFrontendKinds.def"
21+
#undef DIAG
22+
NUM_BUILTIN_FRONTEND_DIAGNOSTICS
23+
};
24+
} // end namespace diag
25+
} // end namespace clang
26+
27+
#endif

clang/lib/Basic/Diagnostic.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ static unsigned char DiagnosticFlagsDriver[] = {
4848
#include "clang/Basic/DiagnosticDriverKinds.def"
4949
0
5050
};
51+
static unsigned char DiagnosticFlagsFrontend[] = {
52+
#include "clang/Basic/DiagnosticFrontendKinds.def"
53+
0
54+
};
5155
static unsigned char DiagnosticFlagsLex[] = {
5256
#include "clang/Basic/DiagnosticLexKinds.def"
5357
0
@@ -78,8 +82,10 @@ static unsigned getBuiltinDiagClass(unsigned DiagID) {
7882
unsigned res;
7983
if (DiagID < diag::DIAG_START_DRIVER)
8084
res = DiagnosticFlagsCommon[DiagID];
81-
else if (DiagID < diag::DIAG_START_LEX)
85+
else if (DiagID < diag::DIAG_START_FRONTEND)
8286
res = DiagnosticFlagsDriver[DiagID - diag::DIAG_START_DRIVER - 1];
87+
else if (DiagID < diag::DIAG_START_LEX)
88+
res = DiagnosticFlagsFrontend[DiagID - diag::DIAG_START_FRONTEND - 1];
8389
else if (DiagID < diag::DIAG_START_PARSE)
8490
res = DiagnosticFlagsLex[DiagID - diag::DIAG_START_LEX - 1];
8591
else if (DiagID < diag::DIAG_START_AST)
@@ -104,6 +110,10 @@ static const char * const DiagnosticTextDriver[] = {
104110
#include "clang/Basic/DiagnosticDriverKinds.def"
105111
0
106112
};
113+
static const char * const DiagnosticTextFrontend[] = {
114+
#include "clang/Basic/DiagnosticFrontendKinds.def"
115+
0
116+
};
107117
static const char * const DiagnosticTextLex[] = {
108118
#include "clang/Basic/DiagnosticLexKinds.def"
109119
0
@@ -249,8 +259,10 @@ bool Diagnostic::isBuiltinNote(unsigned DiagID) {
249259
const char *Diagnostic::getDescription(unsigned DiagID) const {
250260
if (DiagID < diag::DIAG_START_DRIVER)
251261
return DiagnosticTextCommon[DiagID];
252-
else if (DiagID < diag::DIAG_START_LEX)
262+
else if (DiagID < diag::DIAG_START_FRONTEND)
253263
return DiagnosticTextDriver[DiagID - diag::DIAG_START_DRIVER - 1];
264+
else if (DiagID < diag::DIAG_START_LEX)
265+
return DiagnosticTextFrontend[DiagID - diag::DIAG_START_FRONTEND - 1];
254266
else if (DiagID < diag::DIAG_START_PARSE)
255267
return DiagnosticTextLex[DiagID - diag::DIAG_START_LEX - 1];
256268
else if (DiagID < diag::DIAG_START_AST)

clang/test/Analysis/CGColorSpace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: clang -analyze -checker-cfref -analyzer-store=basic -analyzer-constraints=basic verify %s &&
2-
// RUN: clang -analyze -checker-cfref -analyzer-store=basic -analyzer-constraints=range verify %s &&
1+
// RUN: clang -analyze -checker-cfref -analyzer-store=basic -analyzer-constraints=basic -verify %s &&
2+
// RUN: clang -analyze -checker-cfref -analyzer-store=basic -analyzer-constraints=range -verify %s &&
33
// RUN: clang -analyze -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s &&
44
// RUN: clang -analyze -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s
55

0 commit comments

Comments
 (0)