mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: Re: broken gcc optimization for facilitynames
Date: Sat, 21 Jun 2014 00:51:14 +0200	[thread overview]
Message-ID: <20140620225114.GP23102@port70.net> (raw)
In-Reply-To: <lo2bed$2vm$1@ger.gmane.org>

* Cl?ment Vasseur <clement.vasseur@gmail.com> [2014-06-20 22:09:17 +0000]:
> 
> I made some progress towards a standalone test case. Here it is:
> 
> struct s1 { int v; };
> struct s2 { int v; };
> 
> #define a ((struct s2 *)(struct s1 []){{ 42 }})
> 
> int main(void)
> {
> 	for (int i = 0; a[i].v; i++)
> 		if (a[i].v)
> 			return a[i].v;
> }
> 
> I also found out which optimization flag causes the broken output, it's
> -fstrict-aliasing. I guess the issue here is whether casting `struct s1
> []` to `struct s2 *` violates the strict aliasing rules or not. Indeed,
> compiling with -Wstrict-aliasing=1 shows a warning at this location.
> 
> Can someone pinpoint the exact location in the ISO C spec where there is
> an explanation about the aliasing rules with this kind of pointer
> compatibility?

http://port70.net/~nsz/c/c11/n1570.html#6.5p7

different structs are not compatible types and
object with s1 effective type is accessed through
an expression with s2 type

(if a union of s1 and s2 were used then it would
be ok, because of the "common initial sequence"
rule, or if the first member of s1 had type s2,
because aggregate member can be aliased that way)

so yes this is an aliasing violation and syslog.h
should be fixed


  reply	other threads:[~2014-06-20 22:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-18 16:31 Clément Vasseur
2014-06-19  3:34 ` Rich Felker
2014-06-20 10:14   ` Christopher Meng
2014-06-20 22:13     ` Clément Vasseur
2014-06-20 22:09   ` Clément Vasseur
2014-06-20 22:51     ` Szabolcs Nagy [this message]
2014-06-21  0:34     ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140620225114.GP23102@port70.net \
    --to=nsz@port70.net \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).