Skip to content

Commit 1b18ad3

Browse files
committed
[ClangImporter] <rdar://39801675> Treat fake-buffer locs as invalid, avoid nulls in diags.
1 parent 1e07724 commit 1b18ad3

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,7 @@ module Warnings9 { header "Warnings9.h" }
216216
module ForwardDeclarationsHelper {
217217
header "ForwardDeclarationsHelper.h"
218218
}
219+
module ConditionallyFoo {
220+
header "ConditionallyFoo.h"
221+
config_macros [exhaustive] WANT_FOO
222+
}
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)