From patchwork Tue May 17 08:27:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 54087 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 091FB385742E for ; Tue, 17 May 2022 08:54:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 091FB385742E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652777682; bh=XKGVx0kUE/mm2eH5Ua2EBgB3jypYqaiggv9viAvmASo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=YY9O/tf53v279dAOFx0pDm05WgwLe2Co0K5Kgm+s9kyLze9q2vod67ILQt7AnJwDj T3FYEm3Y8vllYYmjgwqP9Ru6qqf1bSS9JG51MDW3P2QZ9m4TyVvhPOlIgPehpdZm5G jpJPgm4G02rlb29PrcFkjHOr+1Nh9dWvVhBc40ug= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 0CFA53857343 for ; Tue, 17 May 2022 08:27:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0CFA53857343 Received: by mail-wm1-x335.google.com with SMTP id n6so2279609wms.0 for ; Tue, 17 May 2022 01:27:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=XKGVx0kUE/mm2eH5Ua2EBgB3jypYqaiggv9viAvmASo=; b=rAZMaGZOYSHFYf8mSteZUCR718tqpSLVdy1/MjHw9+diaB2/BAq51GhfMVwvTQBprL aNovUxps09S6WLZ3IpsXrghsY+Nz93xjmLwygEtE06FUnhApyQCO+QojKYI+IoKJSZq+ VV9uaBvwmnVLMp+qYr13ozInL/HsUDrnpWmwtogZAVwjbovB/4Dtqpt/8oG8AtOTfkC1 Uf2DexqLypAJj7m7iHiINVrNkGtEVNSA7vqnUnxSrNLJKn5AECP7UEKazHsC9Wumh92m MN5F9yHSGa+9X1kjbeZZYZpLCLOzxtg9d5XyxOj5oPZsD8YC9Aw0ZYpyKs6o0HhZ2w3p S0Zg== X-Gm-Message-State: AOAM532iGLwq4B52L76i8U2+jJTwA7J8vGL203aW9kOweSADyKmrOB77 i3SwTAitD3iReEVRT73dEN0wIUb9pUE68shU X-Google-Smtp-Source: ABdhPJwTUHDIBKGlIK0ulUEkaan5iTFaToNflKt/uGWgiPqWQSfkmIF2HLp3RGCDUFnP7rGRmZr/xA== X-Received: by 2002:a05:600c:4f8d:b0:394:939f:bd2f with SMTP id n13-20020a05600c4f8d00b00394939fbd2fmr30217095wmq.16.1652776076561; Tue, 17 May 2022 01:27:56 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id h12-20020adf9ccc000000b0020adc114136sm14236337wre.0.2022.05.17.01.27.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:27:56 -0700 (PDT) Date: Tue, 17 May 2022 08:27:55 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Enhance the warning on C enum with size clause for size /= 32 Message-ID: <20220517082755.GA1092368@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Etienne Servais Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Improve the warning message and silence warning when size > 32, this is likely intentional and does not warrant a warning. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * freeze.adb (Freeze_Enumeration_Type): Fix comment, enhance message and silence warning for size > 32. diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -7968,15 +7968,17 @@ package body Freeze is else -- If the enumeration type interfaces to C, and it has a size clause - -- that specifies less than int size, it warrants a warning. The - -- user may intend the C type to be an enum or a char, so this is + -- that is smaller than the size of int, it warrants a warning. The + -- user may intend the C type to be a boolean or a char, so this is -- not by itself an error that the Ada compiler can detect, but it - -- it is a worth a heads-up. For Boolean and Character types we + -- is worth a heads-up. For Boolean and Character types we -- assume that the programmer has the proper C type in mind. + -- For explicit sizes larger than int, assume the user knows what + -- he is doing and that the code is intentional. if Convention (Typ) = Convention_C and then Has_Size_Clause (Typ) - and then Esize (Typ) /= Esize (Standard_Integer) + and then Esize (Typ) < Standard_Integer_Size and then not Is_Boolean_Type (Typ) and then not Is_Character_Type (Typ) @@ -7985,7 +7987,12 @@ package body Freeze is and then not Target_Short_Enums then Error_Msg_N - ("C enum types have the size of a C int??", Size_Clause (Typ)); + ("??the size of enums in C is implementation-defined", + Size_Clause (Typ)); + Error_Msg_N + ("\??check that the C counterpart has size of " & + UI_Image (Esize (Typ)), + Size_Clause (Typ)); end if; Adjust_Esize_For_Alignment (Typ);