public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/114643] New: Call to a template function emitted but without the code for the template function itself
@ 2024-04-08 17:13 abbeyj+gcc at gmail dot com
2024-04-08 17:17 ` [Bug ipa/114643] " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: abbeyj+gcc at gmail dot com @ 2024-04-08 17:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114643
Bug ID: 114643
Summary: Call to a template function emitted but without the
code for the template function itself
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: abbeyj+gcc at gmail dot com
Target Milestone: ---
When building the following example, a linker error is produced.
```
void foo();
template <class> class DynArray {
public:
virtual void SetAlloc(unsigned);
int *m_pElems;
unsigned m_nNumElems;
unsigned m_nNumAlloc;
long m_nChunkSize;
};
void *DoRealloc(void *, long);
template <class T> void DynArray<T>::SetAlloc(unsigned new_size) {
if (m_nChunkSize)
new_size = m_nChunkSize * m_nChunkSize - 1 / m_nChunkSize;
else if (m_nNumAlloc)
if (new_size > m_nNumAlloc / 2)
new_size = new_size > m_nNumAlloc + 1 ? new_size : m_nNumAlloc * 1.5 + 1;
if (m_nNumElems && m_nNumAlloc && (new_size || m_pElems))
m_pElems = (T *)DoRealloc(m_pElems, 0);
}
struct object {
DynArray<int> d;
void f(int size);
};
template <typename T> void deser(int size, T &x) {
x.SetAlloc(0);
if (size) {
x.SetAlloc(size);
foo();
}
}
void object::f(int size) {
deser(size, d);
}
```
Build with:
$ g++ -fPIC -O3 -Wall -Werror -fvisibility=hidden reloc.cxx -shared
Output:
> /usr/bin/ld: /tmp/ccLaKma6.o: relocation R_X86_64_PC32 against undefined symbol `_ZN8DynArrayIiE8SetAllocEj' can not be used when making a shared object; recompile with -fPIC
> /usr/bin/ld: final link failed: Bad value
> collect2: error: ld returned 1 exit status
The symbol in the above error message demangles to
`DynArray<int>::SetAlloc(unsigned int)`.
The error message suggests to compile with `-fPIC` but this is already being
compiled with `-fPIC`. The issue seems to be that GCC emits a call to
`DynArray<int>::SetAlloc` but doesn't emit code for `DynArray<int>::SetAlloc`
itself.
The reproducer was minimized with the help of C-Reduce. Very minor changes to
the code result in the problem not reproducing anymore. This is the smallest
that I could manage to get it.
Godbolt link: https://godbolt.org/z/1Ynz1Khac
This appears to have started sometime around GCC 8.1 and still happens on the
trunk version that's currently available on Godbolt.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug ipa/114643] Call to a template function emitted but without the code for the template function itself 2024-04-08 17:13 [Bug c++/114643] New: Call to a template function emitted but without the code for the template function itself abbeyj+gcc at gmail dot com @ 2024-04-08 17:17 ` pinskia at gcc dot gnu.org 2024-04-08 17:24 ` pinskia at gcc dot gnu.org ` (4 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-04-08 17:17 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114643 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- This is a devirtualization issue ... Let me find the dup. ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug ipa/114643] Call to a template function emitted but without the code for the template function itself 2024-04-08 17:13 [Bug c++/114643] New: Call to a template function emitted but without the code for the template function itself abbeyj+gcc at gmail dot com 2024-04-08 17:17 ` [Bug ipa/114643] " pinskia at gcc dot gnu.org @ 2024-04-08 17:24 ` pinskia at gcc dot gnu.org 2024-04-08 21:13 ` pinskia at gcc dot gnu.org ` (3 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-04-08 17:24 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114643 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |62051 --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- I think this is a dup of bug 62051. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62051 [Bug 62051] [11/12/13/14 Regression] Undefined reference to vtable with -O2 and -fdevirtualize-speculatively ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug ipa/114643] Call to a template function emitted but without the code for the template function itself 2024-04-08 17:13 [Bug c++/114643] New: Call to a template function emitted but without the code for the template function itself abbeyj+gcc at gmail dot com 2024-04-08 17:17 ` [Bug ipa/114643] " pinskia at gcc dot gnu.org 2024-04-08 17:24 ` pinskia at gcc dot gnu.org @ 2024-04-08 21:13 ` pinskia at gcc dot gnu.org 2024-04-08 21:16 ` [Bug ipa/114643] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org ` (2 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-04-08 21:13 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114643 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |93115 --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Maybe PR 93115 . Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93115 [Bug 93115] gcc fails to emit inline function on llvm-roc project: -O1 -fPIC -fdevirtualize -fdevirtualize-speculatively -fipa-cp -fipa-cp-clone -fvisibility-inlines-hidden ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug ipa/114643] [11/12/13/14 Regression] Call to a template function emitted but without the code for the template function itself 2024-04-08 17:13 [Bug c++/114643] New: Call to a template function emitted but without the code for the template function itself abbeyj+gcc at gmail dot com ` (2 preceding siblings ...) 2024-04-08 21:13 ` pinskia at gcc dot gnu.org @ 2024-04-08 21:16 ` pinskia at gcc dot gnu.org 2024-04-22 12:40 ` jakub at gcc dot gnu.org 2024-04-22 23:00 ` pinskia at gcc dot gnu.org 5 siblings, 0 replies; 7+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-04-08 21:16 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114643 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=67650, | |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=80916 Known to fail| |8.1.0 Summary|Call to a template function |[11/12/13/14 Regression] |emitted but without the |Call to a template function |code for the template |emitted but without the |function itself |code for the template | |function itself Target Milestone|--- |11.5 Known to work| |7.5.0 Depends on|62051, 93115 | --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Actually it more closely related to PR 67650 (and PR 80916) but both of those were fixed. Looks like even though the function is not static, we are thinking we can still refer to it. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62051 [Bug 62051] [11/12/13/14 Regression] Undefined reference to vtable with -O2 and -fdevirtualize-speculatively https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93115 [Bug 93115] gcc fails to emit inline function on llvm-roc project: -O1 -fPIC -fdevirtualize -fdevirtualize-speculatively -fipa-cp -fipa-cp-clone -fvisibility-inlines-hidden ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug ipa/114643] [11/12/13/14 Regression] Call to a template function emitted but without the code for the template function itself 2024-04-08 17:13 [Bug c++/114643] New: Call to a template function emitted but without the code for the template function itself abbeyj+gcc at gmail dot com ` (3 preceding siblings ...) 2024-04-08 21:16 ` [Bug ipa/114643] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org @ 2024-04-22 12:40 ` jakub at gcc dot gnu.org 2024-04-22 23:00 ` pinskia at gcc dot gnu.org 5 siblings, 0 replies; 7+ messages in thread From: jakub at gcc dot gnu.org @ 2024-04-22 12:40 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114643 Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org Last reconfirmed| |2024-04-22 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Priority|P3 |P2 --- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Started with r8-6709-gb9aba9fde536dc3e0293653509f530322ee2753e ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug ipa/114643] [11/12/13/14 Regression] Call to a template function emitted but without the code for the template function itself 2024-04-08 17:13 [Bug c++/114643] New: Call to a template function emitted but without the code for the template function itself abbeyj+gcc at gmail dot com ` (4 preceding siblings ...) 2024-04-22 12:40 ` jakub at gcc dot gnu.org @ 2024-04-22 23:00 ` pinskia at gcc dot gnu.org 5 siblings, 0 replies; 7+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-04-22 23:00 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114643 --- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Jakub Jelinek from comment #5) > Started with r8-6709-gb9aba9fde536dc3e0293653509f530322ee2753e That is almost definitely just exposed the bug I have not looked to see if changing the params on the command line allows to expose it further back though. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-04-22 23:00 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-04-08 17:13 [Bug c++/114643] New: Call to a template function emitted but without the code for the template function itself abbeyj+gcc at gmail dot com 2024-04-08 17:17 ` [Bug ipa/114643] " pinskia at gcc dot gnu.org 2024-04-08 17:24 ` pinskia at gcc dot gnu.org 2024-04-08 21:13 ` pinskia at gcc dot gnu.org 2024-04-08 21:16 ` [Bug ipa/114643] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org 2024-04-22 12:40 ` jakub at gcc dot gnu.org 2024-04-22 23:00 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).