Skip to content

[SR-14069] Symbol not in TBD file when initializing a static member variable with an inline function #56458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
swift-ci opened this issue Jan 19, 2021 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ compiler The Swift compiler itself

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-14069
Radar rdar://problem/83405989
Original Reporter scentini (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CxxInterop
Assignee None
Priority Medium

md5: 0bf3fb4aec12d9cfe2a92ea0cc046d58

Issue Description:

inline int increment(int t) { return t + 1; }

struct Incrementor { static int incrementee; };

int Incrementor::incrementee = increment(41);

inline int initializeStaticVar() { return Incrementor::incrementee; }

When using the initializeStaticVar() function from Swift, we get an error:

<unknown>:0: error: symbol '_ZN11Incrementor11incrementeeE' (_ZN11Incrementor11incrementeeE) is in generated IR file, but not in TBD file

<unknown>:0: error: please submit a bug report and include the project, and add '-Xfrontend -validate-tbd-against-ir=none' to squash the errors

The issue arises when using an inline function to initialize the static member variable.

@zoecarver
Copy link
Contributor

@swift-ci create

@swift-ci
Copy link
Contributor Author

swift-ci commented Oct 9, 2021

Comment by Puyan Lotfi (JIRA)

I've added the repro steps to a branch here:

https://github.com/plotfi/cxx-interop-test/tree/tbd-SR-14069

@swift-ci
Copy link
Contributor Author

Comment by Puyan Lotfi (JIRA)

I think in SwiftDeclConverter::VisitVarDecl in ImportDecl.cpp we may want to record somewhere that the var_decl isStatic. Later in swift::validateTBD we can know that specific externally visible symbol encountered in validateSymbols() in TBD.cpp comes from an inline definition or a static class variable definition. The cause of the verifier error here is that Incrementor::incrementee is not being added to the symbols list passed to validateSymbols because the TBDGenVisitor::visitFile does not encounter it as a top level Decl.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@zoecarver zoecarver added c++ interop Feature: Interoperability with C++ and removed CxxInterop labels Apr 25, 2022
@plotfi plotfi pinned this issue May 17, 2022
@plotfi
Copy link
Contributor

plotfi commented May 17, 2022

@drodriguez @bulbazord

@drodriguez
Copy link
Contributor

Initially it was unrelated to C++, but #40414 did fix a small bug in which the TBD validation was performed more than needed and was surfacing some of these errors incorrectly (in the case of that PR, when optimizations were enabled, but also -enable-testing, IIRC). It does not fix the problem, if there was one, it just does the validation only when it is supposed to happen.

@shahmishal shahmishal unpinned this issue May 19, 2022
egorzhdan added a commit that referenced this issue Apr 1, 2023
This disables TBD validation when C++ interop is enabled, unless an explicit `-validate-tbd-against-ir=` flag was passed.

rdar://83405989 / #56458
egorzhdan added a commit that referenced this issue Apr 5, 2023
This disables TBD validation when C++ interop is enabled, unless an explicit `-validate-tbd-against-ir=` flag was passed.

rdar://83405989 / #56458
egorzhdan added a commit that referenced this issue Apr 5, 2023
This disables TBD validation when C++ interop is enabled, unless an explicit `-validate-tbd-against-ir=` flag was passed.

rdar://83405989 / #56458
egorzhdan added a commit that referenced this issue Apr 7, 2023
This disables TBD validation when C++ interop is enabled, unless an explicit `-validate-tbd-against-ir=` flag was passed.

rdar://83405989 / #56458
(cherry picked from commit 8f58eaf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ compiler The Swift compiler itself
Projects
None yet
Development

No branches or pull requests

4 participants