Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1513864rwi; Wed, 19 Oct 2022 11:33:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM796O0BBB9sG+FZxfXxoRkMkmTrdldg97iOr8IJKLaF2+bmUkSgkdhafhANb6wthKlyIFT/ X-Received: by 2002:a17:907:75d0:b0:78d:f246:109a with SMTP id jl16-20020a17090775d000b0078df246109amr7861598ejc.595.1666204411690; Wed, 19 Oct 2022 11:33:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666204411; cv=none; d=google.com; s=arc-20160816; b=s7mrS1cb5EmVsNa0bRKp24N7E3+wNPr6cZUy/0CmWytEY/sOfdlb61iNFH73sEfX99 GgnYaK4GaUOiXl2umyZVm0JoZznCieJ8hfyGKreOzc8bO2JhBEkZmq0VEpODI0mASthg LEsSRuPLzoty9EJFAi91t0RGoXuJ5J6KrwnjOwG9Tn800WVOC0P36ehdS2m9ZALwcUWx 4qdzXtc2nvAwSEzpJwI+DHo+a1JyF5jWexSMzWkaCgJBXreHr0SUVKo7+bv2F968IT/p zX7eCmpV5Zc9QCqRCg2LlPqBCXrtX9L5dnpv3tcOPn2CMRYdDeORomq4URxcO6WLA1QV Nd5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ZGR0rDpTW7xgTFS4grRDMvtr/PpXo8umrs2yrJ3UML4=; b=vlkm5B0whHEN/5RcPthKIIOo8/wv5sW2bnO2AfjtVcB9jh7XL6nb7e6+F1dymjTBgI /mlEcUTpdvHNQuiVfPvwuA1m1cW8YWj7mt2v22FztUbta6iohdSGrDbZLq2gkUI3DjgU 7+UIvgqAMNamaZ+akYbo3TNi88WYu9Pr6N1e3aWpcZj+xf3Qg99kgukbcqgSRBiLu9rx qfL8Fo1eJdg0Q0QyyFnKIREdsJYh/+jNSZXfXhmXo8SqRBVbAhQu5Dai/wFE9scce2Ws NEfwcpJiiT5+eZnENG66JU9i1uuv076Esj5sij3aFNVffL8ibZUvy+bOiIlRMsS6i4ma mVdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=f3558QuE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go30-20020a1709070d9e00b00791bcf8aa5esi2104724ejc.739.2022.10.19.11.33.03; Wed, 19 Oct 2022 11:33:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=f3558QuE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230172AbiJSSKu (ORCPT + 99 others); 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-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" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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