From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dibyendu Majumdar Subject: Re: Potential incorrect simplification Date: Tue, 28 Mar 2017 23:22:50 +0100 Message-ID: References: <20170328141113.kbrwdva6ttsrokts@macpro.local> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from mail-it0-f54.google.com ([209.85.214.54]:36506 "EHLO mail-it0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752323AbdC1WW6 (ORCPT ); Tue, 28 Mar 2017 18:22:58 -0400 Received: by mail-it0-f54.google.com with SMTP id e75so73082814itd.1 for ; Tue, 28 Mar 2017 15:22:52 -0700 (PDT) In-Reply-To: Sender: linux-sparse-owner@vger.kernel.org List-Id: linux-sparse@vger.kernel.org To: Linus Torvalds Cc: Luc Van Oostenryck , Linux-Sparse Hi Linus, On 28 March 2017 at 17:20, Linus Torvalds wrote: > On Tue, Mar 28, 2017 at 7:19 AM, Dibyendu Majumdar > wrote: >> >> Well the unsimplified output is correct. The problem appears after >> simplification. > > No. The unsimplified output has the exact same bug: > > main: > .L0: > > load.32 %r1 <- 0[s3] > shl.32 %r2 <- $1, $6 > and.32 %r3 <- %r1, $-65 > > That "load.32" loads an uninitialized value from the stack. > > The simplification then just simplifies the uninitialized load to just > be an uninitialized pseudo instead. Exact same code. > > And arguably both unsimplified and simplified code is "correct" in the > sense that it's exactly what the original source code does: > > s3.onebit = 1; > I think that the unsimplified output is correct in that it is doing what the C code says. Because if you look at the C code, the code is only accessing a field that has been initialized prior to access - so I do not think this counts as undefined behaviour. I am unable to find the wording in the C standard that would make this clear one way or another, but my reading of the standard is that the C code is legal. I understand that to the simplification phase the first load looks like load of undefined value - but that is not the semantic of the C code that led to it. I checked that clang generates the same sequence of instructions as sparse when optimization is switched off - but turning on optimization gets rid of all the code except for the return. Thanks and Regards Dibyendu