From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6FE7C433FE for ; Wed, 19 Oct 2022 18:10:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230268AbiJSSKu (ORCPT ); Wed, 19 Oct 2022 14:10:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230060AbiJSSKs (ORCPT ); Wed, 19 Oct 2022 14:10:48 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 815FA167263 for ; Wed, 19 Oct 2022 11:10:47 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id g8-20020a17090a128800b0020c79f987ceso843500pja.5 for ; Wed, 19 Oct 2022 11:10:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ZGR0rDpTW7xgTFS4grRDMvtr/PpXo8umrs2yrJ3UML4=; b=f3558QuEtp4oWAGxzHD+nDzX3s6SI6mqk07d4unwH/uZPll67kvPzY5AlfzYZxg+X6 zTvnWZUR0E1tCYrtFi8p6tx/eQUaR2VTkJl/mvo2YuQvLCirD1YWJB+uMQf8JMGXKP2W aSE+S294zj9djVP4FNih8XJ1S1uIJi++YZ+5HcWgOVKJgWDE5yCARXTCgtR/KOlGbhbw 1NhjRBzW2Z973G/YIF7Bkxhfyd1R4ltMyZk1UPVJ7daouoWbA5/MQhDb0MSgOwsymsd1 Mpqg/WMXHG8MhM6u6vKyBivd8kgGCyhxnJD2YGfEq4797fki4azwmj016iMI484UoGo2 cPcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZGR0rDpTW7xgTFS4grRDMvtr/PpXo8umrs2yrJ3UML4=; b=htFO2JD5L01IyS7iGukc68CIx/4ym9qylDi7m1oAo+OXJPvq/N2Ex5I+vUUOhEbw6g 2AYm/XyOFCvaMxyE/mknyH2b0Xm+0oWfjFOXUD0cUYpZbXnNiSrRo3NhBz+Vx4juQ2rl IBdAm5/UN0x3oCoUE2JaQKZS6DDYKNKnpOUMsJ/6AZ7+/e7OBvs52ebiMTvPCy2giMxC nNuwRRPZrpr+dGs+FeX0piVAueCKonb5bG92YiotKf0483gvQU5j4GPTKmFDZP1FtLqZ hKmRHvvBTgCtpJw7Ma9aSvNsNjdCEr8l74h5fJEwsIObINdkq7nZRgSctvPf7sCvYe6X V8Mg== X-Gm-Message-State: ACrzQf2K37NHLFlisJQinjPjdkR7BFnNRuKiAZO7WZhwVDxUYrFX2fiY wEWjUdkaXm5NBJCNAHPOcSxeQfOnWhLw+kh1e6DbN4gzEs7B8w== X-Google-Smtp-Source: AMsMyM7MuUj4C35EpdRK3az+tECYwbYHlpD6xn0OX0sCzW4tLI+w8FIXQovOYVJg+ChLDWtMvTKNoWMI0kE/hHHzMJY= X-Received: by 2002:a17:90b:1a8d:b0:20d:be0b:a320 with SMTP id ng13-20020a17090b1a8d00b0020dbe0ba320mr32474975pjb.107.1666203046751; Wed, 19 Oct 2022 11:10:46 -0700 (PDT) MIME-Version: 1.0 References: <20221019162648.3557490-1-Jason@zx2c4.com> <20221019165455.GL25951@gate.crashing.org> In-Reply-To: From: Nick Desaulniers Date: Wed, 19 Oct 2022 11:10:34 -0700 Message-ID: Subject: Re: [PATCH] kbuild: treat char as always signed To: Linus Torvalds Cc: Segher Boessenkool , "Jason A. Donenfeld" , linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-arch@vger.kernel.org, linux-toolchains@vger.kernel.org, Masahiro Yamada , Kees Cook , Andrew Morton , Andy Shevchenko , Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 19, 2022 at 10:26 AM Linus Torvalds wrote: > > On Wed, Oct 19, 2022 at 10:14 AM Linus Torvalds > wrote: > > > > The pointer-sign thing doesn't actually help (ie it won't find places > > where you actually compare a char), and it causes untold damage in > > doing completely insane things. > > Side note: several years ago I tried to make up some sane rules to > have 'sparse' actually be able to warn when a 'char' was used in a > context where the sign mattered. Do you have examples? Maybe we could turn this into a compiler feature request. Having prior art on the problem would be a boon. > > I failed miserably. > > You actually can see some signs (heh) of that in the sparse sources, > in that the type system actually has a bit for explicitly signed types > ("MOD_EXPLICITLY_SIGNED"), but it ends up being almost entirely > unused. > > That bit does still have one particular use: the "bitfield is > dubiously signed" thing where sparse will complain about bitfields > that are implicitly (but not explicitly) signed. Because people really > expect 'int a:1' to have values 0/1, not 0/-1. Clang's -Wbitfield-constant-conversion can catch that. commit 5c5c2baad2b5 ("ASoC: mchp-spdiftx: Fix clang -Wbitfield-constant-conversion") commit eab9100d9898 ("ASoC: mchp-spdiftx: Fix clang -Wbitfield-constant-conversion") commit 37209783c73a ("thunderbolt: Make priority unsigned in struct tb_path") > > But the original intent was to find code where people used a 'char' > that wasn't explicitly signed, and that then had architecture-defined > behavior. > > I just could not come up with any even remotely sane warning > heuristics that didn't have a metric buttload of false positives. > > I still have this feeling that it *should* be possible to warn about > the situation where you end up doing an implicit type widening (ie the > normal C "arithmetic is always done in at least 'int'") that then does > not get narrowed down again without the upper bits ever mattering. > > But it needs somebody smarter than me, I'm afraid. > > And the fact that I don't think any other compiler has that warning > either makes me just wonder if my feeling that it should be possible > is just wrong. > > Linus -- Thanks, ~Nick Desaulniers