Files
swift-mirror/lib/ClangImporter/ClangAdapter.cpp
Jordan Rose 0c785c07bd [ClangImporter] Don't use local scope decls to find a function's home (#27440)
In C, a function can be declared at local scope:

    void aFunctionInBase(void) {
      void theFunctionInQuestion(int);
    }

and then again in a different header at top-level scope:

    void theFunctionInQuestion(int);

If the first one appears first, it becomes what Clang considers the
"canonical" declaration, which (up until now) Swift has been using to
decide what module to import a function into. (Since a C function can
be redeclared arbitrarily many times, we have to pick one.) This is
important for diagnostics and anything else that might ask "where did
this Swift declaration come from". Instead of the very first
redeclaration, use the first non-local one to determine the "home"
module.

(The standard library wants a guarantee that forward declarations they
put in SwiftShims won't interfere with declarations found elsewhere. I
don't think Clang can /ever/ provide that, so if there's ever a
mismatch between the standard library's forward declarations and the
"real" declarations the standard library's might win out at the LLVM
level---say, in terms of attributes. But this at least removes a place
where that could be visible to users even when it isn't otherwise a
problem.)
2019-11-20 20:41:08 -08:00

24 KiB