Commit Graph

19 Commits

Author SHA1 Message Date
Steven Wu
04f09d6d1d [Modules] Soft reset diagnostics when clang module import failed
Swift compiler can try to import clang modules which might fail to load.
In this case, the clang diagnostic engine is reset to ignore the errors,
but the hard reset also clears out the states, including the diagnostics
options and current states. This will affect the future clang module
imports and diagnostics. Use a soft reset that only clears the errors
but not the other states.

rdar://139723218
2024-12-03 10:32:36 -08:00
Artem Chikin
4e5b0548fb Update lib/ClangImporter/ClangDiagnosticConsumer.h
Co-authored-by: Allan Shortlidge <tshortli@gmail.com>
2023-09-21 12:46:03 -07:00
Artem Chikin
d840b88e14 [ClangImporter] On failing a module lookup, reset Clang's DiagnosticEngine, in addition to filtering out the "module not found" diagnostic
Even though 'ClangDiagnosticConsumer' filters out 'clang::diag::err_module_not_found' from being emitted by the Swift compiler, delegating to Swift's module-loading logic for error-handling, we must also ensure that we reset Clang's 'DiagnosticEngine''s error count. Otherwise, if we do not, final stages of IRGen will query Clang's code-gen to finalize its 'Module', which Clang will not do if its internal DiagnosticEngine contains errors. This will cause Swift's IRGen to fail, even though the only error emitted was one Swift intended to suppress.
2023-09-14 15:33:05 -07:00
Jordan Rose
e364552876 [ClangImporter] Pull buffer importing out of ClangDiagnosticConsumer
Emitting Swift diagnostics in Clang buffers requires making those
buffers valid places to put Swift SourceLocs, which means making a
mirror of those buffers in the Swift SourceManager. This isn't a copy;
instead, any Clang SourceManagers that are involved are kept alive
until the importer is torn down. (There might be more than one because
of diagnostics emitted during module building.)

For a long time we only emitted diagnostics in Clang buffers if the
diagnostics came from Clang, but then we added another case for custom
Swift names that fail to import. I'm about to add another such
diagnostic, so let's formalize this buffer mapping first.

No intended functionality change.
2019-10-28 22:08:26 -07:00
Michael Gottesman
af57a534cb [upstream-update] Include llvm/Support/MemoryBuffer.h directly to unbreak the master-next build.
rdar://36765072
2018-02-19 10:10:31 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Jordan Rose
77f6228542 [ClangImporter] Warn on and ignore invalid swift_name attributes.
...that Clang didn't catch for us. The Clang side of things is now looser so
that we don't have to mirror our import logic over there, but that means
invalid cases can slip through.

Part of rdar://problem/21091469

Swift SVN r29535
2015-06-20 18:55:13 +00:00
Jordan Rose
2cd2fe3418 [ClangImporter] Don't assume all memory buffers have unique identifiers.
In particular, the fake "<module-includes>" buffers all have that same name.
Use the buffer itself to provide identity. (We are already deliberately
keeping the buffers alive via their source managers.)

rdar://problem/19716081

Swift SVN r25200
2015-02-11 23:07:37 +00:00
Argyrios Kyrtzidis
b74feafdfd [ClangImporter] Make sure to use the right clang::SourceManager when resolving a diagnostic-related source location during clang module building.
Fixes crash in rdar://18464633

Swift SVN r22721
2014-10-14 03:37:00 +00:00
Jordan Rose
3d3c6fa730 [ClangImporter] Fix crash when a diagnostic is reported during module building.
This rare crash happens when
1. A diagnostic is reported when building a Clang module.
2. The diagnostic is mapped to a Swift diagnostic by mirroring the Clang
   source buffer as a Swift source buffer (via non-owning reference).
3. The Clang CompilerInstance used specifically to build the module is
   destroyed.
4. Some /new/ buffer is allocated in the same memory spot as the old buffer.
5. Some new Clang diagnostic occurs in the new buffer.
6. The Swift source manager asserts when trying to set up a virtual name
   for the diagnostic in the second imported buffer, because there's already
   a name for that region.

The fix, because we don't expect diagnostics from modules to appear very
often, is to keep any clang::SourceManagers alive if diagnostics are emitted
in their buffers. We can revisit this if/when Swift's source manager
(currently built on llvm::SourceMgr) has the ability to remove buffers.

Many thanks to Greg for noticing the problem, tracking it down, and providing
a diff to make it fail reproducibly under GuardMalloc. I've tried to preserve
the spirit of that diff in the new logic in ~SourceManager, which will also
fail reliably with GuardMalloc (and probably ASan).

rdar://problem/18285805

Swift SVN r21958
2014-09-15 22:26:48 +00:00
Jordan Rose
b682e0cf3d [ClangImporter] Don't try to recover if an Objective-C module can't be loaded.
This is already a fatal error, so it doesn't matter how many diagnostics we
dump after that. It's better not to lie to the rest of the compiler about
whether the load succeeds.

No immediate Radar, but this fixes a crash in the test case I'm about to
commit, and possibly some other mystery "dependency missing" crashes in
XREF resolution.

Swift SVN r20919
2014-08-01 21:44:36 +00:00
Jordan Rose
aae4a3d731 [ClangImporter] Pass through diagnostic locations for imports.
If importing a Clang module fails, we should report that at the location of
the import statement. This doesn't do that fully because it isn't transitive
(if Swift module Foo imports Swift module Bar, which fails to import Clang
module Baz, we don't get an error in user source), but it's a step forward
for the simple cases.

Swift SVN r20575
2014-07-25 23:01:51 +00:00
Jordan Rose
904d1b21c6 [ClangImporter] Drop the "current import" tracking for bridging headers.
Now that bridging headers from ASTs are always present and bridging headers
from the command line are checked in advance, we no longer need to worry
about the Clang instance failing to find the bridging header. That's good,
because this wasn't implemented correctly anyway: if a bridging header
imported a module, we could get an error.

Swift SVN r20129
2014-07-18 00:22:55 +00:00
Jordan Rose
0e8021b7f3 [ClangImporter] Add frontend option -dump-clang-diagnostics for debugging.
This option dumps Clang diagnostics to stderr as well as passing them along
to Swift's diagnostic machinery.

Swift SVN r19841
2014-07-11 00:36:55 +00:00
Jordan Rose
6d376f9627 [ClangImporter] Make a missing bridging header a fatal error.
<rdar://problem/16920163>

Swift SVN r18442
2014-05-20 02:13:32 +00:00
Jordan Rose
b581365785 [ClangImporter] If a Clang module fails to build, it's not missing.
...so don't report a second "module missing" error from Swift itself.

We do still treat the Clang module failing to build as a fatal error.

<rdar://problem/16175035>

Swift SVN r18231
2014-05-17 00:23:46 +00:00
Jordan Rose
a012602f62 [ClangImporter] Pass diagnostics through to Swift's diagnostic consumer.
We're not mapping source locations over correctly yet, so the file name
where an error occurs gets shoved into the diagnostic text, but that's
fine for now.

This also silences the "module 'Blah' not found" error coming from the
importer whenever Swift itself can be responsible for importing the module.

Still to do: if we can't build a Clang module, we shouldn't report that
error and then say it can't be found.

<rdar://problem/14509389>

Swift SVN r18230
2014-05-17 00:23:44 +00:00