Skip to content

Commit ce1035c

Browse files
committed
Frontend: Fix a crash in CC_LOG_DIAGNOSTICS handling.
llvm-svn: 130909
1 parent c60695a commit ce1035c

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

clang/lib/Frontend/LogDiagnosticPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void LogDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
9999
DiagnosticClient::HandleDiagnostic(Level, Info);
100100

101101
// Initialize the main file name, if we haven't already fetched it.
102-
if (MainFilename.empty()) {
102+
if (MainFilename.empty() && Info.hasSourceManager()) {
103103
const SourceManager &SM = Info.getSourceManager();
104104
FileID FID = SM.getMainFileID();
105105
if (!FID.isInvalid()) {
@@ -122,7 +122,7 @@ void LogDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
122122
// Set the location information.
123123
DE.Filename = "";
124124
DE.Line = DE.Column = 0;
125-
if (Info.getLocation().isValid()) {
125+
if (Info.getLocation().isValid() && Info.hasSourceManager()) {
126126
const SourceManager &SM = Info.getSourceManager();
127127
PresumedLoc PLoc = SM.getPresumedLoc(Info.getLocation());
128128

clang/test/Driver/cc-log-diagnostics.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
// RUN: rm -f %t.log
12
// RUN: env RC_DEBUG_OPTIONS=1 \
2-
// RUN: CC_LOG_DIAGNOSTICS=1 \
3-
// RUN: CC_LOG_DIAGNOSTICS_FILE=%t.log \
4-
// RUN: %clang -no-canonical-prefixes -ccc-host-triple x86_64-apple-darwin10 -fsyntax-only %s
3+
// RUN: CC_LOG_DIAGNOSTICS=1 CC_LOG_DIAGNOSTICS_FILE=%t.log \
4+
// RUN: %clang -Wfoobar -no-canonical-prefixes -ccc-host-triple x86_64-apple-darwin10 -fsyntax-only %s
55
// RUN: FileCheck %s < %t.log
66

77
int f0() {}
@@ -16,6 +16,12 @@ int f0() {}
1616
// CHECK: <dict>
1717
// CHECK: <key>level</key>
1818
// CHECK: <string>warning</string>
19+
// CHECK: <key>message</key>
20+
// CHECK: <string>unknown warning option '-Wfoobar'</string>
21+
// CHECK: </dict>
22+
// CHECK: <dict>
23+
// CHECK: <key>level</key>
24+
// CHECK: <string>warning</string>
1925
// CHECK: <key>filename</key>
2026
// CHECK: <string>{{.*}}cc-log-diagnostics.c</string>
2127
// CHECK: <key>line</key>

0 commit comments

Comments
 (0)