From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,461d464a39a7a30a X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 X-Received: by 10.180.38.73 with SMTP id e9mr2923923wik.2.1367665796673; Sat, 04 May 2013 04:09:56 -0700 (PDT) Path: hg5ni66829wib.1!nntp.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!85.12.40.139.MISMATCH!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newspeer1.nac.net!news.astraweb.com!border2.newsrouter.astraweb.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeed.news.ucla.edu!nrc-news.nrc.ca!News.Dal.Ca!citadel.nobulus.com!goblin1!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: Erroneous code generation from GNAT or GCC? Date: Mon, 29 Apr 2013 01:52:22 +0200 Organization: Ada @ Home Message-ID: References: NNTP-Posting-Host: ZXqOjp+NNxswgqXUj66j5g.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.15 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable Date: 2013-04-29T01:52:22+02:00 List-Id: Le Mon, 29 Apr 2013 00:35:03 +0200, Yannick Duch=C3=AAne (Hibou57) = a =C3=A9crit: > Element : Character :=3D Item; -- <<< Copy of argument If this, is changed into: Element : Character :=3D Item with Volatile =3D> True; The issue is solved. Here is the generated code: library__write__2: .LFB7: .cfi_startproc pushl %ebx # .cfi_def_cfa_offset 8 .cfi_offset 3, -8 subl $24, %esp #, .cfi_def_cfa_offset 32 movl 32(%esp), %eax # item, item movb %al, 15(%esp) # item, element movl $1, %edx #, tmp65 leal 15(%esp), %ecx #, element.19 movl $4, %eax #, tmp64 movl %edx, %ebx # tmp65, tmp65 It is still reading at a non=E2=80=9132 bits aligned address even if the= re is only = one character at that address (well, why not, Intel 32 bits CPU does not= = triggers exceptions for this), but now it is at least making a copy of = `Item`, which is fetched from [esp+32] as I expected in the previous = message, then store it at [esp+15], so the address stored in ecx is now = an = address which really correspond to an initialized memory area. The = system=E2=80=91call invocation succeed. I wonder if this is normal or not. What's your opinion? Here is what the RM says: http://www.ada-auth.org/standards/12rm/html/RM-C-6.html#p20 > The external effect of a program (see 1.1.3) is definedto include each= = > read and update of a volatile or atomicobject. The implementation shal= l = > not generate any memoryreads or updates of atomic or volatile objects = = > other thanthose specified by the program. This is quoted from =E2=80=9CC.6 Shared Variable Control=E2=80=9D. But t= his is a local = variable, not a shared object, and I don't intuitively agree with GNAT o= r = GCC optimization here. Unless I'm wrong, in which case I welcome any = rationale relevant to explain why. The parameters passed to a sub=E2=80=91program may also be used or not, = and GNAT = does not dropped them all. As it can be noticed, it did not dropped = parameter passing, and the parameter is not declared as being of a = volatile type. Seems less care is taken by the compiler, with foreign machine=E2=80=91c= ode = insertion, even if via some level of indirection, than with it's own = generated code, while it should be the opposite. Until now, I though the volatile aspect was typically to be used with = object which may be updated as a non=E2=80=91visible side effect, like w= ith a = peripheral writing at some memory area, asynchronously (or not, that's = still not directly visible anyway). But here, that's a local variable, = which is explicitly referred to and explicitly assigned. If the address = is = passed, that should implies the address means something, especially if t= he = address is an input parameter as it is here. And what means the address = of = an uninitialised area when that area was directed to be explicitly = initialized by the source? Isn't GNAT of GCC lacking some semantic = dependency tracking here? May be I should make parameter types of the system=E2=80=91call's generi= c = declaration, all volatile? If so, this would implies that can be said of= = all machine=E2=80=91code insertions? But then, why isn't it automatic so? -- = =E2=80=9CSyntactic sugar causes cancer of the semi-colons.=E2=80=9D [1] =E2=80=9CStructured Programming supports the law of the excluded muddle.= =E2=80=9D [1] [1]: Epigrams on Programming =E2=80=94 Alan J. =E2=80=94 P. Yale Univers= ity