Bug 44298 - code addressed only by label with it's address taken is ignored
Summary: code addressed only by label with it's address taken is ignored
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 28581 29305 40115 54529 55468 55749 77329 77951 96956 112870 114366 115332 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-05-27 18:51 UTC by Yuri
Modified: 2024-06-03 16:32 UTC (History)
13 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri 2010-05-27 18:51:20 UTC
The testcase below passes the entry point to 'lll' call as an address of the label ll_def. printf line disappears completely.

Obviously people should only use such code when they really know what they are doing. But compilation result here is complately wrong and isn't usable in any way.

--- testcase ---
#include <stdio.h>
#include <stdlib.h>

__attribute__ ((noinline)) void lll(void*) {
}

void mainx() {
  lll(&&ll_def);
  return;
ll_def:
  printf("default\n");
  return;
}
Comment 1 Andrew Pinski 2010-05-27 18:57:28 UTC
Addresses of labels are only designed to work with computed gotos so if you don't have a computed goto in the function of mainx, then this will not work.  
See http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Labels-as-Values.html .

One thing which is documented is "You may not use this mechanism to jump to code in a different function."

It is not about using labels as value extension only when they know what they are doing but rather using them as they are correctly documented as being working.  They are only designed for computed gotos.  Any other use will cause undefined behavior.
Comment 2 Andrew Pinski 2024-03-16 17:55:31 UTC
*** Bug 114366 has been marked as a duplicate of this bug. ***
Comment 3 Andrew Pinski 2024-03-16 17:56:26 UTC
*** Bug 55468 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2024-03-16 17:57:17 UTC
*** Bug 55749 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Pinski 2024-03-16 17:58:05 UTC
*** Bug 40115 has been marked as a duplicate of this bug. ***
Comment 6 Andrew Pinski 2024-03-16 17:58:31 UTC
*** Bug 112870 has been marked as a duplicate of this bug. ***
Comment 7 Andrew Pinski 2024-03-16 17:58:45 UTC
*** Bug 96956 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Pinski 2024-03-16 17:59:13 UTC
*** Bug 77329 has been marked as a duplicate of this bug. ***
Comment 9 Andrew Pinski 2024-03-16 17:59:45 UTC
*** Bug 77951 has been marked as a duplicate of this bug. ***
Comment 10 Andrew Pinski 2024-03-16 18:06:12 UTC
*** Bug 54529 has been marked as a duplicate of this bug. ***
Comment 11 Andrew Pinski 2024-03-16 18:09:21 UTC
*** Bug 29305 has been marked as a duplicate of this bug. ***
Comment 12 Andrew Pinski 2024-03-16 18:09:58 UTC
*** Bug 28581 has been marked as a duplicate of this bug. ***
Comment 13 Jakub Jelinek 2024-06-03 16:32:55 UTC
*** Bug 115332 has been marked as a duplicate of this bug. ***