Skip to content

Commit f8658fc

Browse files
authored
Merge pull request #16373 from graydon/rdar-39801675-garbage-in-warning-message
2 parents 025f4dd + 27b2ddb commit f8658fc

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

lib/ClangImporter/ClangDiagnosticConsumer.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,18 @@ namespace {
6666
StringRef Message,
6767
ArrayRef<clang::CharSourceRange> Ranges,
6868
clang::DiagOrStoredDiag Info) override {
69-
if (shouldSuppressDiagInSwiftBuffers(Info) && isInSwiftBuffers(Loc))
70-
return;
69+
if (isInSwiftBuffers(Loc)) {
70+
// FIXME: Ideally, we'd report non-suppressed diagnostics on synthetic
71+
// buffers, printing their names (eg. <swift-imported-modules>:...) but
72+
// this risks printing _excerpts_ of those buffers to stderr too; at
73+
// present the synthetic buffers are "large blocks of null bytes" which
74+
// we definitely don't want to print out. So until we have some clever
75+
// way to print the name but suppress printing excerpts, we just replace
76+
// the Loc with an invalid one here, which suppresses both.
77+
Loc = clang::FullSourceLoc();
78+
if (shouldSuppressDiagInSwiftBuffers(Info))
79+
return;
80+
}
7181
callback(Loc, Level, Message);
7282
}
7383

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#ifdef WANT_FOO
2+
int foo();
3+
#endif

test/ClangImporter/Inputs/custom-modules/module.map

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,8 @@ module Warnings6 { header "Warnings6.h" }
212212
module Warnings7 { header "Warnings7.h" }
213213
module Warnings8 { header "Warnings8.h" }
214214
module Warnings9 { header "Warnings9.h" }
215+
216+
module ConditionallyFoo {
217+
header "ConditionallyFoo.h"
218+
config_macros [exhaustive] WANT_FOO
219+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define WANT_FOO
2+
@import ConditionallyFoo;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// REQUIRES: OS=macosx
2+
//
3+
// This triggers a warning about ignored configuration macros; the warning then
4+
// attempts to emit an excerpt from one of the clang importer's fake buffers
5+
// (<swift-imported-modules>) which is full of 250kb of nulls. We want to check
6+
// that we do not emit a gigantic block of nulls to stderr.
7+
//
8+
// RUN: %empty-directory(%t)
9+
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/custom-modules -import-objc-header %S/Inputs/no-fake-source-buffer-excerpts.h %s 2>%t/errors
10+
// RUN: od -a < %t/errors | %FileCheck %s
11+
// CHECK-NOT: nul nul nul nul

0 commit comments

Comments
 (0)