aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2025-02-28 14:09:29 +0100
committerRichard Biener <rguenth@gcc.gnu.org>2025-02-28 15:18:07 +0100
commitbc34db5b12e008f6ec4fdf4ebd22263c8617e5e3 (patch)
treef4256f176d2480349e2b885e4e22cfaee4169227 /gcc
parente6037af6d5e5a43c437257580d75bc8b35a6dcfd (diff)
downloadgcc-bc34db5b12e008f6ec4fdf4ebd22263c8617e5e3.zip
gcc-bc34db5b12e008f6ec4fdf4ebd22263c8617e5e3.tar.gz
gcc-bc34db5b12e008f6ec4fdf4ebd22263c8617e5e3.tar.bz2
lto/91299 - weak definition inlined with LTO
The following fixes a thinko in the handling of interposed weak definitions which confused the interposition check in get_availability by setting DECL_EXTERNAL too early. PR lto/91299 gcc/lto/ * lto-symtab.cc (lto_symtab_merge_symbols): Set DECL_EXTERNAL only after calling get_availability. gcc/testsuite/ * gcc.dg/lto/pr91299_0.c: New testcase. * gcc.dg/lto/pr91299_1.c: Likewise.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/lto/lto-symtab.cc2
-rw-r--r--gcc/testsuite/gcc.dg/lto/pr91299_0.c16
-rw-r--r--gcc/testsuite/gcc.dg/lto/pr91299_1.c6
3 files changed, 23 insertions, 1 deletions
diff --git a/gcc/lto/lto-symtab.cc b/gcc/lto/lto-symtab.cc
index bc3c144..66674a4 100644
--- a/gcc/lto/lto-symtab.cc
+++ b/gcc/lto/lto-symtab.cc
@@ -1016,7 +1016,6 @@ lto_symtab_merge_symbols (void)
|| node->resolution == LDPR_RESOLVED_EXEC
|| node->resolution == LDPR_RESOLVED_DYN))
{
- DECL_EXTERNAL (node->decl) = 1;
/* If alias to local symbol was preempted by external definition,
we know it is not pointing to the local symbol. Remove it. */
if (node->alias
@@ -1042,6 +1041,7 @@ lto_symtab_merge_symbols (void)
node->remove_all_references ();
}
}
+ DECL_EXTERNAL (node->decl) = 1;
}
if (!(cnode = dyn_cast <cgraph_node *> (node))
diff --git a/gcc/testsuite/gcc.dg/lto/pr91299_0.c b/gcc/testsuite/gcc.dg/lto/pr91299_0.c
new file mode 100644
index 0000000..d9a8b21
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr91299_0.c
@@ -0,0 +1,16 @@
+/* { dg-lto-do run } */
+/* { dg-lto-options { { -O2 -flto } } } */
+
+__attribute__((weak)) int get_t(void)
+{
+ return 0;
+}
+
+int a;
+int main(void)
+{
+ a = get_t();
+ if (a != 1)
+ __builtin_abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/lto/pr91299_1.c b/gcc/testsuite/gcc.dg/lto/pr91299_1.c
new file mode 100644
index 0000000..29a2852
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr91299_1.c
@@ -0,0 +1,6 @@
+/* { dg-options "-fno-lto" } */
+
+int get_t(void)
+{
+ return 1;
+}