Skip to content
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

Undefined reference to global variable defined in the same file (in MSVC mode) #63618

Closed
adalisk-emikhaylov opened this issue Jun 30, 2023 · 4 comments

Comments

@adalisk-emikhaylov
Copy link

struct A
{
    ~A() {}
};

struct B
{
    int b = 0;
    B(A) {}
};

struct C : public B
{
    using B::B;
};

C var = A{};

int main()
{
    return var.b;
}

Building this on Windows produces following error:

lld-link: error: undefined symbol: struct C var
>>> referenced by C:\msys2\tmp\1-93d998.o:(main)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

The compiler invocation is clang++ 1.cpp -fuse-ld=lld (similar error without LLD, using it to show a non-localized message).

Clang version is:

$ clang++ --version
clang version 16.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix

This doesn't happen on Linux or in MinGW-compatibility mode.

Making the variable static doesn't change the result. Making it inline ICEs the compiler:

fatal error: error in backend: Associative COMDAT symbol '?var@@3UC@@A' is not a key for its COMDAT.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: D:\\Tools\\LLVM_16\\bin\\clang++.exe -cc1 -triple x86_64-pc-windows-msvc19.29.30136 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name 1.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -fcoverage-compilation-dir=D:\\Repos\\sandbox -resource-dir D:\\Tools\\LLVM_16\\lib\\clang\\16 -internal-isystem D:\\Tools\\LLVM_16\\lib\\clang\\16\\include -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\atlmfc\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\cppwinrt" -fdeprecated-macro -fdebug-compilation-dir=D:\\Repos\\sandbox -ferror-limit 19 -fmessage-length=251 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.29.30136 -std=c++14 -fdelayed-template-parsing -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -o C:\\msys2\\tmp\\1-cc1f29.o -x c++ 1.cpp
1.      <eof> parser at end of file
2.      Code generation
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
# Crash reproducer for clang version 16.0.0
# Driver args: "--driver-mode=g++" "1.cpp" "-fuse-ld=lld"
# Original command:  "D:\\Tools\\LLVM_16\\bin\\clang++.exe" "-cc1" "-triple" "x86_64-pc-windows-msvc19.29.30136" "-emit-obj" "-mrelax-all" "-mincremental-linker-compatible" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "1.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=none" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-fcoverage-compilation-dir=D:\\Repos\\sandbox" "-resource-dir" "D:\\Tools\\LLVM_16\\lib\\clang\\16" "-internal-isystem" "D:\\Tools\\LLVM_16\\lib\\clang\\16\\include" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\atlmfc\\include" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\ucrt" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\shared" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\um" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\winrt" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\cppwinrt" "-fdeprecated-macro" "-fdebug-compilation-dir=D:\\Repos\\sandbox" "-ferror-limit" "19" "-fmessage-length=251" "-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.29.30136" "-std=c++14" "-fdelayed-template-parsing" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-faddrsig" "-o" "C:\\msys2\\tmp\\1-cc1f29.o" "-x" "c++" "1.cpp"
 "D:\\Tools\\LLVM_16\\bin\\clang++.exe" "-cc1" "-triple" "x86_64-pc-windows-msvc19.29.30136" "-emit-obj" "-mrelax-all" "-mincremental-linker-compatible" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "1.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=none" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-fcoverage-compilation-dir=D:\\Repos\\sandbox" "-fdeprecated-macro" "-fdebug-compilation-dir=D:\\Repos\\sandbox" "-ferror-limit" "19" "-fmessage-length=251" "-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.29.30136" "-std=c++14" "-fdelayed-template-parsing" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-faddrsig" "-x" "c++" "1-df2247.cpp"
@llvmbot
Copy link
Collaborator

llvmbot commented Jun 30, 2023

@llvm/issue-subscribers-clang-codegen

@efriedma-quic
Copy link
Collaborator

The following reproduces on all targets:

struct B
{
    B(int,...) {}
};

struct C : public B
{
    using B::B;
};

C var = 3;

It looks like EmitInlinedInheritingCXXConstructorCall is accidentally changing the name of the global variable to "this".

@efriedma-quic
Copy link
Collaborator

Arg.getAnyValue()->setName(D.getName());

@efriedma-quic
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants