This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/68334] New: combination of weak and noreturn attributes
- From: "chantry.xavier at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 13 Nov 2015 12:44:43 +0000
- Subject: [Bug c/68334] New: combination of weak and noreturn attributes
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68334
Bug ID: 68334
Summary: combination of weak and noreturn attributes
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: chantry.xavier at gmail dot com
Target Milestone: ---
It's probably more a nonsense than a bug, and all compilers behave the same way
(from gcc 4.4 to 5.2 and clang too).
If a function definition has both weak and noreturn, then it looks like the
noreturn optimization is applied anyway in the local compilation unit, even
though the function can be overriden by another one at link time.
main.c
---
#include <assert.h>
#include "test.h"
__attribute__((weak)) __attribute__((noreturn))
void test(void)
{
assert (0);
}
int main(void)
{
test();
return 0;
}
---
test.c
---
#include <stdio.h>
#include "test.h"
void test(void)
{
printf("toto\n");
}
---
test.h
---
void test(void);
---
$CC -Wall -Wextra -c test.c -o test.o
$CC -Wall -Wextra -c main.c -o main.o
$CC -Wall -Wextra main.o test.o -o test
Running ./test produces the following output which shows that the function was
overriden but the code is executed twice and then segfaults:
---
toto
toto
zsh: segmentation fault (core dumped) ./test
---
I thought that noreturn optim shouldn't be applied in this case (it could maybe
still be done at linking time when using lto).
Otherwise I might have missed something in the doc which explains what's wrong.