Bug 90347 - [UBSAN] __attribute__((weak))__ results in "declared weak after being used" error
Summary: [UBSAN] __attribute__((weak))__ results in "declared weak after being used" e...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: sanitizer (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: 10.4
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-04 18:37 UTC by Dmitry G. Dyachenko
Modified: 2022-04-28 23:23 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-05-06 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry G. Dyachenko 2019-05-04 18:37:17 UTC
$ cat x.cpp
struct s { };
extern s var;
// __attribute__ ((weak)) s var; // no error

extern void foo(s&);
void bar()
{
    foo(var);
}

__attribute__ ((weak)) s var; // error


$ /usr/local/gcc_current/bin/g++ -fsanitize=undefined -Wall -c x.cpp
x.cpp:2:10: error: 'var' declared weak after being used
    2 | extern s var;
      |          ^~~


$ /usr/local/gcc_current/bin/g++ -Wall -c x.cpp


$ $ /usr/local/gcc_current/bin/g++ -v            
Using built-in specs.
COLLECT_GCC=/usr/local/gcc_current/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/gcc_current/libexec/gcc/x86_64-pc-linux-gnu/10.0.0/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
Target: x86_64-pc-linux-gnu
Configured with: /home/dimhen/src/gcc_current/configure --prefix=/usr/local/gcc_current --enable-checking=yes,df,fold,rtl,extra --enable-languages=c,c++,lto --disable-multilib --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --with-tune=native
Thread model: posix
gcc version 10.0.0 20190503 (experimental) [trunk revision 270859] (GCC)
Comment 1 Martin Liška 2019-05-06 09:10:57 UTC
Confirmed.
@Marek can you please take a look?
Comment 2 Marek Polacek 2019-05-06 17:12:15 UTC
Caused by -fsanitize=null.
Comment 3 Marek Polacek 2019-05-06 17:20:08 UTC
ubsan_maybe_instrument_reference_or_call sets
flag_delete_null_pointer_checks = 1;
and then we call tree_single_nonzero_warnv_p -> maybe_nonzero_address -> symtab_node::nonzero_address

1979   if (!DECL_WEAK (decl)
1980       && flag_delete_null_pointer_checks)
1981     {
1982       refuse_visibility_changes = true;
1983       return true;
1984     }
Comment 4 Jakub Jelinek 2020-05-07 11:56:24 UTC
GCC 10.1 has been released.
Comment 5 Richard Biener 2020-07-23 06:51:50 UTC
GCC 10.2 is released, adjusting target milestone.
Comment 6 Richard Biener 2021-04-08 12:02:30 UTC
GCC 10.3 is being released, retargeting bugs to GCC 10.4.
Comment 7 Dmitry G. Dyachenko 2021-12-03 09:21:39 UTC
r12-5761 PASS for me

r12-5648 FAIL
r12-5761 PASS
Comment 8 Andrew Pinski 2021-12-03 09:30:12 UTC
(In reply to Dmitry G. Dyachenko from comment #7)
> r12-5761 PASS for me
> 
> r12-5648 FAIL
> r12-5761 PASS

Most likely r12-5696-g53caa4723d8de .
Comment 9 Martin Liška 2021-12-08 17:22:59 UTC
Yes, fixed with r12-5696-g53caa4723d8de73f.
Comment 10 Marek Polacek 2022-04-28 23:23:32 UTC
Fixed.