public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/26371]  New: dead variable attributes
@ 2006-02-19 21:20 acahalan at gmail dot com
  2006-02-20  2:02 ` [Bug c/26371] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: acahalan at gmail dot com @ 2006-02-19 21:20 UTC (permalink / raw)
  To: gcc-bugs

A large project may have a configurable build to allow optional features. Fully
eliminating a feature may require #ifdef all over the place, making the code
ugly and unmaintainable. Example: you want an OS kernel to support an embedded
systems build that lacks the normal user ID handling.

If members of a struct could be marked as being useless, then the compiler's
dead code elimination could often take the place of adding #ifdef all over the
place.

Useful attributes would be something like this:

a. readas(x)   When used as an rvalue, you get x.
b. nomem(x)    Does not take up space. Address reads as x.
c. writeas(x)  When used as an lvalue, store x.
d. nowrite     Don't bother storing to this location.

(you'd never use more than one of the last three)


-- 
           Summary: dead variable attributes
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: acahalan at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26371


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/26371] dead variable attributes
  2006-02-19 21:20 [Bug c/26371] New: dead variable attributes acahalan at gmail dot com
@ 2006-02-20  2:02 ` pinskia at gcc dot gnu dot org
  2006-02-20  3:18 ` acahalan at gmail dot com
  2006-02-21 10:14 ` rguenth at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-20  2:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-02-20 02:02 -------
Can you show an example how to use these variables?  I don't understand why you
cannot use if(TARGET_WANTS_XXX)
instead of #if TARGET_WANTS_XXX.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26371


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/26371] dead variable attributes
  2006-02-19 21:20 [Bug c/26371] New: dead variable attributes acahalan at gmail dot com
  2006-02-20  2:02 ` [Bug c/26371] " pinskia at gcc dot gnu dot org
@ 2006-02-20  3:18 ` acahalan at gmail dot com
  2006-02-21 10:14 ` rguenth at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: acahalan at gmail dot com @ 2006-02-20  3:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from acahalan at gmail dot com  2006-02-20 03:18 -------
For variables that are commonly used in a large project, you sure wouldn't want
to be putting conditional code all over the place if you could avoid it. The
choice could be something like:

a. put #if TARGET_WANTS_XXX in 12345 locations
b. put if(TARGET_WANTS_XXX) in 12345 locations
c. just live with lots of bloat
d. make use of this proposed feature in 1 location


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26371


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/26371] dead variable attributes
  2006-02-19 21:20 [Bug c/26371] New: dead variable attributes acahalan at gmail dot com
  2006-02-20  2:02 ` [Bug c/26371] " pinskia at gcc dot gnu dot org
  2006-02-20  3:18 ` acahalan at gmail dot com
@ 2006-02-21 10:14 ` rguenth at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-02-21 10:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2006-02-21 10:14 -------
So you want

typedef struct {
  int bar;
  void *foobar
#if !NEEDED_BY_ARCH
  __attribute__((readas(0)))
#endif
  ;
} Foo;

so Foo.foobar is NULL for !NEEDED_BY_ARCH?  Why not do the proper thing
and provide accessors like f.i. int the LK:

#define foo_foo(x) (x).bar
#if !NEEDED_BY_ARCH
#define foo_foobar(x) NULL
#else
#define foo_foobar(x) (x).foobar
#endif

no need to invent funny attributes for this.  And #defines are properly
localized in some header.  OO makes you happy.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26371


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-02-21 10:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-19 21:20 [Bug c/26371] New: dead variable attributes acahalan at gmail dot com
2006-02-20  2:02 ` [Bug c/26371] " pinskia at gcc dot gnu dot org
2006-02-20  3:18 ` acahalan at gmail dot com
2006-02-21 10:14 ` rguenth at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).