Bug 19341 - [4.0 Regression] DCE eliminating non-dead code
Summary: [4.0 Regression] DCE eliminating non-dead code
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.0.0
: P1 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
Keywords: alias, wrong-code
Depends on:
Reported: 2005-01-09 01:29 UTC by Serge Belyshev
Modified: 2005-09-30 14:04 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2005-01-12 06:08:11


Note You need to log in before you can comment on or make changes to this bug.
Description Serge Belyshev 2005-01-09 01:29:05 UTC
void abort (void);

void __attribute__((regparm(1))) g (int *p)
  if (*p != 1)
    abort ();

int main ()
  int k;
  k = 1;
  asm volatile ("call g" :: "a" (&k));
  return 0;
Comment 1 Andrew Pinski 2005-01-09 01:37:59 UTC
This code is invalid, for one you should not do a call in inline-asm.
Second the store to k is dead as the inline-asm is not told that k is accessed.

asm volatile ("call g" :: "a" (&k), "m" (k)); will fix the DCE issue but the code is still invalid because 
control flow 
Comment 2 Andrew Pinski 2005-01-09 01:54:02 UTC
Another way to fix this is to add that this inline-asm clobers memory, aka:
  asm volatile ("call g" :: "a" (&k):"memory");
Comment 3 Richard Henderson 2005-01-12 05:41:12 UTC
Not invalid.  The asm is a pointer escape point.
Comment 4 Richard Henderson 2005-01-12 05:41:34 UTC
Comment 5 Steven Bosscher 2005-01-12 10:37:40 UTC
Is an asm a pointer escape point even if it does not have a memory clobber 
Comment 6 Richard Henderson 2005-02-02 07:15:15 UTC
Good point.  You've got to indicate that you touch memory in some way in order
to force the compiler to make memory consistent before the asm.
Comment 7 Andrew Pinski 2005-09-30 14:04:20 UTC
*** Bug 24146 has been marked as a duplicate of this bug. ***