Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4964158imc; Mon, 25 Feb 2019 14:35:48 -0800 (PST) X-Google-Smtp-Source: AHgI3IbRZq79m48ZLoVWm9U7nLbpdO1jW1/7Kj/czjmpJ8SyCb3Zvj32qpp83qgNDsMirTMPa3CF X-Received: by 2002:a63:da43:: with SMTP id l3mr3928839pgj.164.1551134148886; Mon, 25 Feb 2019 14:35:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551134148; cv=none; d=google.com; s=arc-20160816; b=hurRKU+L59TVkAeAZn0eIMMxaQBhqmDZb7ga5RVJh8YOwUyliiU7/U2Ho8HXnkclt8 w2ItPlvL7ZZbsZXH0UE0YkGt6dgqQ2hCJISHnTkgDtoJrRAQHXIA9u1Bb988I3j29EiC oI+8QIViWqy/KkznjwKMCXDPoKzjNd/oCKsZVEM0IQ7C5uOOeWZ0VKgAsHJ71sfqEqZb UU/pezzkqSUk+3ZU/NaZuMuqbrOZsMql3fE5A0UhJbqCnXzfzsd63405tCPt3c/ecZL9 TxL/2Q08c2DHch0l5SHxHG6lXgJBkagEighaJcOmcIaIlojefMzgQ3HkffwORiz3HGk2 BIOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=10FxPzwQCwaRNmZBCE5TERSl05BGdxracTAlmOVTnMk=; b=hMkRcYMpHQ22ioE5ghpsOYF95IUpoLc9fWw1H2WUVhKg8JeupxnQdzBbk0XN1r0Sxe QpQcmCmcyertS6j33A9VJnQUQzs70TM2oNr0W/wDykgDB2aD7gRw6ZNIE56DNfJnRz7d 0tFGLDRjJAtSh2WNDR6zaTHm4tDR5DL6DgEJWXhEvDMEVSMqDP/2vGYBvxbvuoZ6MFqt PM8Wmwq/tNgJ0SFo6dDhMvUzLa9zLaVvFDbJR3+Pgrl2Tdkg6g2K7w8opfrhJokK9IAh Hl9J0PIV+WKCPF5E5Oa4owMyxNcb/aG1tqnnRIr1ejngk9ifZ5B4mNcJFDItsic+hYTh cppg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=GwXzw7uz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si11194239plb.103.2019.02.25.14.35.33; Mon, 25 Feb 2019 14:35:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=GwXzw7uz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728736AbfBYWfL (ORCPT + 99 others); Mon, 25 Feb 2019 17:35:11 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:41495 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726919AbfBYWfK (ORCPT ); Mon, 25 Feb 2019 17:35:10 -0500 Received: by mail-lj1-f193.google.com with SMTP id z25so8942029ljk.8 for ; Mon, 25 Feb 2019 14:35:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=10FxPzwQCwaRNmZBCE5TERSl05BGdxracTAlmOVTnMk=; b=GwXzw7uz50GyEJOgXRBmQNvy9n/EkevMtfkKE1TOppZpk86TZGZs02JRG4gAU63ozw vHFJfB/Fv2rf95gccgoCS8l4SJi2cDJP8DcI+0rN6PHQUYqyyhp+2uATQZEL9EnyH/rk wQtqykh+sZec7f8oe1IeBJ4R+3Q5Jv5bwzhkE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=10FxPzwQCwaRNmZBCE5TERSl05BGdxracTAlmOVTnMk=; b=SikG2tsrQ5J47AZve+IJ1oxi6kSFa5N477DiaSXi7dP/oFBriYJ/v08Qh5CusQGDGi 64NsjGuZOArvj/lFqSvm+E/S3Dp8AuUloolfRLLk6SyizGNWzvurtO3F6e6WGpfQaGwl /aDI1mJcwuXx7KlV9KvKHyNqxN1y04msunwa1Z0IuGjtZyMin7pAVuBAqq4bSZQ3CGoN n/fHE3gmJZvPN06kcIHAmdDk/9LcPYz46pQWIAfcwdxFwUPQSaKvPAiKsxvMDNJGjABg ildn1pGol2Q7to4Lc9ry08zC42KWHwO1afjcpEBqfSLdcGwLVsUJSgy0cYHDUOrc0dD5 K1EQ== X-Gm-Message-State: AHQUAuZFwGTYiA5qOTViZIYQf7q8ZgFMHUPBf+UWoHRgF8pIfH9kwVLy WWw7Zf8WtmlMgl+IHbR6xdc0Qga3xXU= X-Received: by 2002:a2e:80cd:: with SMTP id r13mr5443830ljg.34.1551134107741; Mon, 25 Feb 2019 14:35:07 -0800 (PST) Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com. [209.85.208.179]) by smtp.gmail.com with ESMTPSA id l72sm2816764lfg.75.2019.02.25.14.35.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 14:35:04 -0800 (PST) Received: by mail-lj1-f179.google.com with SMTP id z7so8760198lji.0 for ; Mon, 25 Feb 2019 14:35:04 -0800 (PST) X-Received: by 2002:a2e:7a03:: with SMTP id v3mr11328630ljc.22.1551134103662; Mon, 25 Feb 2019 14:35:03 -0800 (PST) MIME-Version: 1.0 References: <20190221222123.GC6474@magnolia> In-Reply-To: From: Linus Torvalds Date: Mon, 25 Feb 2019 14:34:47 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] tmpfs: fix uninitialized return value in shmem_link To: Hugh Dickins , Jan Hubicka , rguenth@gcc.gnu.org Cc: "Darrick J. Wong" , Andrew Morton , Matej Kupljen , Al Viro , Dan Carpenter , Linux List Kernel Mailing , linux-fsdevel , Linux-MM Content-Type: multipart/mixed; boundary="0000000000003feded0582bf8d04" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --0000000000003feded0582bf8d04 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 25, 2019 at 12:34 PM Hugh Dickins wrote: > > Seems like a gcc bug? But I don't have a decent recent gcc to hand > to submit a proper report, hope someone else can shed light on it. I don't have a _very_ recent gcc either, but with gcc-8.2.1 the attached test-case gives me: [torvalds@i7 ~]$ gcc -O2 -S -Wall test.c with no warning, and then [torvalds@i7 ~]$ gcc -O2 -S -Wall -DHIDE_PROBLEM test.c test.c: In function =E2=80=98shmem_link=E2=80=99: test.c:60:9: warning: =E2=80=98ret=E2=80=99 may be used uninitialized in= this function [-Wmaybe-uninitialized] return ret; ^~~ *does* show the expected warning. So it is the presence of that if (ret) return ret; that suppresses the warning. What I *suspect* happens is (a) gcc sees that there is only one assignment to "ret" (b) in the same basic block as the assignment, there is a test against "ret" being nonzero that goes out. and what I think happens is that (a) causes gcc to consider that assignment to be the defining assignment (which makes all kinds of sense in an SSA world), and then (b) means that gcc decides that clearly "ret" has to be zero in any case that doesn't go out due to the if-test. In fact, if I then look at the code generation, gcc will actually do this (edited to be more legible): movl (%rbx), %eax <- load inode->i_nlink testl %eax, %eax je .L1 ... ... call d_instantiate xorl %eax, %eax <- explicitly zero 'ret'! .L1: popq %rbx popq %rbp popq %r12 ret so at least with my compiler, it *effectively* zeroed ret (in %rax) anyway, and it all just _happened_ to get the right result even though 'ret' wasn't actually initialized. Which is why it all worked just fine. And depending on how gcc works internally, it really may not just be a random mistake of register allocation, but really because gcc kind of _thought_ that 'ret' was zero-initialized due to the combination of the one single assigment and test for zero. So it turns out that the patch to initialize to zero doesn't do anything, probably for the same reason that gcc didn't warn about the missing initialization. Gcc kind of added an initialization of its own there. I'm not entirely sure if any gcc developer would be interested in this as a test-case, but I guess I can try to do a bugzilla. Adding a few gcc people who have been on previous kernel gcc bugzilla discussions, just in case they have something to add. The gcc bugzilla is this: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D89501 and I tried to make it be self-explanatory, but I wrote the bugzilla in parallel with this email, and maybe there's some missing context either there (or here). Linus --0000000000003feded0582bf8d04 Content-Type: text/x-c-code; charset="US-ASCII"; name="test.c" Content-Disposition: attachment; filename="test.c" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_jskwlqay0 LyoKICogTWluaW1hbCBmYWtlIGRlY2xhcmF0aW9ucyBvZiAia2VybmVsIiBkYXRhIHR5cGVzCiAq LwpzdHJ1Y3Qgc3VwZXJibG9jazsKCnN0cnVjdCBpbm9kZSB7CglpbnQgaV9ubGluazsKCWludCBp X3NpemU7CglpbnQgaV9jdGltZTsKCWludCBpX210aW1lOwoJc3RydWN0IHN1cGVyYmxvY2sgKmlf c2I7Cn07CgpzdHJ1Y3QgZGVudHJ5IHsKCXN0cnVjdCBpbm9kZSAqZF9pbm9kZTsKfTsKCiNkZWZp bmUgZF9pbm9kZShkZW50cnkpICgoZGVudHJ5KS0+ZF9pbm9kZSkKCmV4dGVybiBpbnQgY3VycmVu dF90aW1lKHN0cnVjdCBpbm9kZSAqKTsKZXh0ZXJuIHZvaWQgaW5jX25saW5rKHN0cnVjdCBpbm9k ZSAqKTsKZXh0ZXJuIHZvaWQgaWhvbGQoc3RydWN0IGlub2RlICopOwpleHRlcm4gdm9pZCBkZ2V0 KHN0cnVjdCBkZW50cnkgKik7CmV4dGVybiB2b2lkIGRfaW5zdGFudGlhdGUo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