Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1086646pxb; Wed, 6 Apr 2022 08:23:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8y2Q/xTTIoJuDN2CCPwE6lx+XJ5LfGfupofizYM5lcufXWL4HB2FFd+7rsCZc7VL+LT58 X-Received: by 2002:a17:90a:da02:b0:1bf:3919:f2a with SMTP id e2-20020a17090ada0200b001bf39190f2amr10597058pjv.208.1649258637201; Wed, 06 Apr 2022 08:23:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649258637; cv=none; d=google.com; s=arc-20160816; b=GXmsJvBK9c3pUiyqiArqWkPYjjYS3AiNxs5Qn8ScnrQDMKJcsaKyojU0ek5Oa/VWP0 hNCVAEehkAq3VUyjXK64pwmylRBH8HeXHRg1pgO5eq0SV73L1lfPCZ5OJ1FndVIjn+ZP wEHBuvbid5kM5VPiKAhyTPn5Bs+qdT68fSsSVS8oW40YzFmOeVfU+tlVPGn7t23eAbog u7SYgI8EkEJRkdSLCvMn2JvmmxHC5b4J/wjE4ffYpMdLaWP6t+vQaZpHsYTs11/Cn8be ae97r0ALUfl4PQx5ZCUtfH2dOj4uvmU5dZ0vWjyu6KyZeIQDC9R9mheZmTTaFWtwyIk9 RxDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:reply-to:message-id :subject:to:from:date:dkim-signature; bh=0ZcKsEZ8qwBQThqWn9sE6S/H8YRw8IewVlhEa4ihZuo=; b=YJEkq0BkSveUEgyH286b6OZ0XZtio0ALAxcNrX2IMXZmjEFJacUgCryi736gwDpPDF dubnMWAZ+pUv2OZnwBWtABElacv+mEmIMfb528NIqE3M2jbznTPB1XIeSp8JsTDPtbjj PqAahnwbO3p+ixLONxaIfVRaeY6PdF5q7c1U77GcMw7Rmd9S3Re0aoCihzYHQD1G5ov6 2XgR1Fa/+1o0VPYonKut7cCx/zeXt2lr5b0sbH2GDzmjOZSDzpwuWlycF8nKM4Q87svB XkyufkrSCdBLI4cUl+cW3cK4HFcxYSMO8+ZEnVgZMkHSJWmz6YqvKM+JBV7Xj6u+EMQ0 aZ+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ckHTOObp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s8-20020a170902ea0800b00156a809ef6asi9911298plg.402.2022.04.06.08.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 08:23:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ckHTOObp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C875F36478B; Wed, 6 Apr 2022 06:27:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233194AbiDFN3F (ORCPT + 99 others); Wed, 6 Apr 2022 09:29:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234065AbiDFN2X (ORCPT ); Wed, 6 Apr 2022 09:28:23 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6D7C51BD99D for ; Wed, 6 Apr 2022 03:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649240771; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0ZcKsEZ8qwBQThqWn9sE6S/H8YRw8IewVlhEa4ihZuo=; b=ckHTOObpm3NtPtjw/vGjnhnar2pzf/NnzNlLFhPHYcWIcMDEi6a8PclrPNgH76U4BfghDR psSx4A7DlRtVyCDftr/Vd8RZ/xiLCsnoCXjLPRZEWshqdnk3ngDLgKtPhRQ7ECHXXGzGNF fpnWEs9+SuHRaqd0bRVpHqrOZeZjO1w= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-260-AIsMgtwZNIGqyAF5y3K81A-1; Wed, 06 Apr 2022 06:04:22 -0400 X-MC-Unique: AIsMgtwZNIGqyAF5y3K81A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B59E780346E; Wed, 6 Apr 2022 10:04:21 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7460040CF905; Wed, 6 Apr 2022 10:04:21 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 236A4IHC1580605 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 6 Apr 2022 12:04:19 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 236A4HPQ1580604; Wed, 6 Apr 2022 12:04:17 +0200 Date: Wed, 6 Apr 2022 12:04:17 +0200 From: Jakub Jelinek To: Borislav Petkov , Richard Biener , linux-toolchains@vger.kernel.org, Michael Matz , lkml Subject: Re: older gccs and case labels producing integer constants Message-ID: Reply-To: Jakub Jelinek References: <7o5nn52-nqn1-oo13-s6o9-59r85r91o768@fhfr.qr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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, Apr 06, 2022 at 11:53:17AM +0200, Jakub Jelinek wrote: > On Tue, Apr 05, 2022 at 12:36:58PM +0200, Borislav Petkov wrote: > > On Tue, Apr 05, 2022 at 12:06:45PM +0200, Richard Biener wrote: > > > Wird auch mit gcc 11 rejected. Kanns sein dass mit gcc 7 andere > > > compiler flags genommen werden? > > > > Found it: > > > > $ gcc -fsanitize=shift -c switch.c > > switch.c: In function ‘foo’: > > switch.c:10:7: error: case label does not reduce to an integer constant > > case (((0xfc08) << 16) | (0x0101)):; > > > > $ gcc --version > > gcc (SUSE Linux) 7.4.1 20190905 [gcc-7-branch revision 275407] > > Copyright (C) 2017 Free Software Foundation, Inc. > > > > Something not fully backported? > > That is rejected with -fsanitize=shift even on current trunk (in C, C++ is > fine). > C++ constexpr code has cases for ubsan builtins and internal functions, > but C just doesn't handle those apparently. But I think the error is actually correct. In C99 and later, for signed left shift the rule for x << y is that there is UB if (similarly to all C family) if y is negative or greater or equal to precision of promoted x, but for C99 also when ((unsigned_typeof_x) x >> (precision_of_x - 1 - y)) != 0. That is the case above, 0xfc08 is signed int and 0xfc08 << 16 is 0xfc080000 where (0xfc08 >> 15) is 1 and so it is UB. In C99 and later you need: case (int)(((0xfc08U) << 16) | (0x0101)):; or so. Note, C++ has different rules (and C++20 and later only has the y non-negative and less than precision requirement and nothing else). Jakub