Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 253504 - sane-backends-1.0.19-r2 has "dereferencing type-punned pointer" warnings with gcc 4.1.2
Summary: sane-backends-1.0.19-r2 has "dereferencing type-punned pointer" warnings with...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: High minor
Assignee: Patrick Kursawe (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-03 00:19 UTC by John Whitlock
Modified: 2009-02-07 19:57 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
New ebuild that applies patch (sane-backends-1.0.19-r3.ebuild,4.39 KB, text/plain)
2009-01-03 00:20 UTC, John Whitlock
Details
Patch to cast to (void *) and eliminate warning (sanei-type-punning-1.0.19.patch,1.44 KB, patch)
2009-01-03 00:20 UTC, John Whitlock
Details | Diff
adds -fno-strict-aliasing cflag to build (sane-backends-1.0.19-r3.ebuild,4.39 KB, text/plain)
2009-01-03 01:48 UTC, John Whitlock
Details

Note You need to log in before you can comment on or make changes to this bug.
Description John Whitlock 2009-01-03 00:19:29 UTC
Compiling generates these warnings:

sanei_net.c: In function 'sanei_w_option_descriptor_array':
sanei_net.c:131: warning: dereferencing type-punned pointer will break strict-aliasing rules

sanei_wire.c: In function 'sanei_w_option_descriptor':
sanei_wire.c:518: warning: dereferencing type-punned pointer will break strict-aliasing rules
sanei_wire.c:525: warning: dereferencing type-punned pointer will break strict-aliasing rules
sanei_wire.c:535: warning: dereferencing type-punned pointer will break strict-aliasing rules

The solution is to cast to (void *) before casting to (void **).


Reproducible: Always

Steps to Reproduce:
1. FEATURES="stricter" emerge media-gfx/sane-backends-1.0.19-r2

Actual Results:  
die "poor code kills airplanes"

Expected Results:  
compiles, installs

Bug is filed upstream at https://alioth.debian.org/tracker/index.php?func=detail&aid=311334&group_id=30186&atid=410366
Comment 1 John Whitlock 2009-01-03 00:20:24 UTC
Created attachment 177169 [details]
New ebuild that applies patch
Comment 2 John Whitlock 2009-01-03 00:20:59 UTC
Created attachment 177170 [details, diff]
Patch to cast to (void *) and eliminate warning
Comment 3 Harald van Dijk (RETIRED) gentoo-dev 2009-01-03 01:00:24 UTC
> The solution is to cast to (void *) before casting to (void **).

No, absolutely not. That extra cast does nothing whatsoever to fix the problem. It merely tells gcc "shut up, I know what I'm doing", and should be used only when you really do.
Comment 4 John Whitlock 2009-01-03 01:48:10 UTC
Created attachment 177177 [details]
adds -fno-strict-aliasing cflag to build

Reading the gcc manual and the code, I think this is a case where masking the warning is the right thing.  They are using a union to save memory, setting an enumeration to set which union member was written to, etc.  In other words, all the things you do to try to simulate C++ polymorphism in C.

However, it is upstream's job to decide if they want to mask the warning or write code that gcc is more comfortable with, so I'm removing the patch.  I've replaced it with an ebuild that sets the -fno-strict-aliasing flag instead.
Comment 5 Harald van Dijk (RETIRED) gentoo-dev 2009-01-03 05:26:21 UTC
(In reply to comment #4)
> Reading the gcc manual and the code, I think this is a case where masking the
> warning is the right thing.  They are using a union to save memory, setting an
> enumeration to set which union member was written to, etc. In other words, all
> the things you do to try to simulate C++ polymorphism in C.

That's not what the warning is about. If you look at the first hunk, referring to a->desc, that's declared in sane_net.h as

typedef struct
  {
    SANE_Word num_options;
    SANE_Option_Descriptor **desc;
  }
SANE_Option_Descriptor_Array;

A SANE_Option_Descriptor ** is not a void *, and you cannot access it as if it were. Reading from and writing to *(void **) &a->desc means about as much as reading from *(long **) &i, where i is an int: it makes no sense on some systems if they are represented differently, because of that it's just plain not allowed by C, and because of that gcc will optimise on the assumption that you don't do that.

> However, it is upstream's job to decide if they want to mask the warning or
> write code that gcc is more comfortable with, so I'm removing the patch.  I've
> replaced it with an ebuild that sets the -fno-strict-aliasing flag instead.

Thank you. -fno-strict-aliasing is one of the right possible answers here.
Comment 6 Patrick Kursawe (RETIRED) gentoo-dev 2009-02-07 19:57:14 UTC
Since this seems to be more a potential problem than real breakage I have fixed it silently for all current ebuilds. Thanks guys!