mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
emitClangDecl interacts with clang and LLVM to achieve C interop. On the LLVM side, CodeGenModule::EmitGlobal asserts if the decl eventually passed to it is not a "file scoped" via VarDecl::isFileVarDecl. LLVM currently asserts on local extern variables in C headers passed to Swift when the definition exists outside that header. To fix this, we need to ensure that we are only passing Decls that do not trip the assertion but not unduly limit local extern variables when the corresponding definition exists inside that header. We can do that fairly simply by checking for isFileVarDecl just before we hand-off to clang. When the definition for the local extern variable exists inside the header, isFileVarDecl is true, and if it exists elsewhere, it is false. This matches up with the assert expectation on the LLVM side exactly. This indirectly addresses #28968, since that contains the only part of the Swift stdlib that uses a local extern variable, but any header that is used with Swift that contains a local extern variable will cause the compiler to assert when built with assertions enabled.
22 lines
386 B
C
22 lines
386 B
C
static inline int _no_prior_var() {
|
|
extern int var;
|
|
return var;
|
|
}
|
|
|
|
static inline int _no_prior_func() {
|
|
extern int func();
|
|
return func();
|
|
}
|
|
|
|
static int prior_var = 1;
|
|
static inline int _prior_var() {
|
|
extern int prior_var;
|
|
return prior_var;
|
|
}
|
|
|
|
static inline int prior_func() { return 1; }
|
|
static inline int _prior_func() {
|
|
extern int prior_func();
|
|
return prior_func();
|
|
}
|