From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 78815 invoked by alias); 29 May 2017 14:02:15 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 78793 invoked by uid 89); 29 May 2017 14:02:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=According X-HELO: mail-qk0-f178.google.com Received: from mail-qk0-f178.google.com (HELO mail-qk0-f178.google.com) (209.85.220.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 29 May 2017 14:02:07 +0000 Received: by mail-qk0-f178.google.com with SMTP id y201so48693345qka.0 for ; Mon, 29 May 2017 07:02:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=EgCk46j+vm4SmeFXF9Y7vAYOE1LwifsTeZ3a0kaDedQ=; b=Bg590GH/30nlpbZ0DkVVEMKB/s4pm9YoqGT2d/yUuTXqNbgccXh9lMZRkaCXVS2AYY vcA9HCpZRS8IKVFj/pK8LkOB+mg/OEXxxHX95gkPJpbUXMldvldGYj/D8EsJMCmbDG+5 S72aBHM23XFS2sFAbDPoEoDSCPgoS9lRxKXMiJeIuFd8isaBf/OLkVDxvb5kg6xSr/pG oG9fvqz9d+nQi2avqyljFcNiTw4NNIcBSSCMezLr42QtmMS2gwzz26j/WdDZbdR8mwsx VbrhuYiDGPKac76iaqMxfGSex+dMMVv9vIUO3hr6HUPgSu5NYJS1NXCv+llZvLWdDvyl aNLw== X-Gm-Message-State: AODbwcDB1cFoyW3iPfuxO/aN8I/ngh3B+C+Erso4d1m+N9kUkph6xQgt D+Fgpw6kV0VNaZsOlosYGTvTJKcG1ypq X-Received: by 10.55.43.142 with SMTP id r14mr9465160qkr.78.1496066529293; Mon, 29 May 2017 07:02:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.104.111 with HTTP; Mon, 29 May 2017 07:02:08 -0700 (PDT) In-Reply-To: <0d62c57d-60d7-214b-6dca-e89af56e9139@gmail.com> References: <315bf6c8-04e5-01ac-7278-d93c04f83b0e@gmail.com> <0d62c57d-60d7-214b-6dca-e89af56e9139@gmail.com> From: Christophe Lyon Date: Mon, 29 May 2017 14:06:00 -0000 Message-ID: Subject: Re: [PATCH] add more detail to -Wconversion and -Woverflow (PR 80731) To: Martin Sebor Cc: Joseph Myers , Gcc Patch List Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2017-05/txt/msg02188.txt.bz2 On 25 May 2017 at 00:16, Martin Sebor wrote: > On 05/24/2017 11:08 AM, Joseph Myers wrote: >> >> On Wed, 17 May 2017, Martin Sebor wrote: >> >>> @@ -1036,31 +1079,76 @@ warnings_for_convert_and_check (location_t loc, >>> tree type, tree expr, >>> /* This detects cases like converting -129 or 256 to >>> unsigned char. */ >>> if (!int_fits_type_p (expr, c_common_signed_type (type))) >>> - warning_at (loc, OPT_Woverflow, >>> - "large integer implicitly truncated to unsigned >>> type"); >>> + { >>> + if (cst) >>> + warning_at (loc, OPT_Woverflow, >>> + (TYPE_UNSIGNED (exprtype) >>> + ? "conversion from %qT to %qT " >>> + "changes value from %qE to %qE" >>> + : "unsigned conversion from %qT to %qT " >>> + "changes value from %qE to %qE"), >>> + exprtype, type, expr, result); >>> + else >>> + warning_at (loc, OPT_Woverflow, >>> + (TYPE_UNSIGNED (exprtype) >>> + ? "conversion from %qT to %qT " >>> + "changes the value of %qE" >>> + : "unsigned conversion from %qT to %qT " >>> + "changes the value of %qE"), >>> + exprtype, type, expr); >>> + } >> >> >> You need to use G_() around both arguments to ?:, otherwise only one will >> get extracted for translation. >> >>> diff --git a/gcc/testsuite/c-c++-common/pr68657-1.c >>> b/gcc/testsuite/c-c++-common/pr68657-1.c >>> index 84f3e54..33fdf86 100644 >>> --- a/gcc/testsuite/c-c++-common/pr68657-1.c >>> +++ b/gcc/testsuite/c-c++-common/pr68657-1.c >>> @@ -5,14 +5,14 @@ >>> void >>> f1 (void) >>> { >>> - unsigned int a = -5; /* { dg-error "negative integer implicitly >>> converted to unsigned type" } */ >>> + unsigned int a = -5; /* { dg-error "unsigned conversion from .int. to >>> .unsigned int. changes value from .-5. to .4294967291." } */ >> >> >> The more specific match would fail for targets with 16-bit int. You need >> to keep it less specific in this test (if you want to test the more >> specific text as well, another test could be added for that, restricted to >> the int32 effective-target). >> >> (The changes to Wconversion-real-integer-3.C and >> Wconversion-real-integer2.C are OK in that those tests are restricted to >> int32plus, although in theory 64-bit int would be an issue there.) >> >>> + /* According to 6.3.1.3 of C11: >>> + -3- Otherwise, the new type is signed and the value cannot be >>> + represented in it; either the result is implementation-defined >>> + or an implementation-defined signal is raised. >>> + >>> + In GCC such conversios wrap and diagnosed by mentioning "overflow" >>> + if the absolut value of the operand is in excess of the maximum of >>> + the destination of type, and "conversion" otherwise, as follows: >>> */ >> >> >> s/conversios/conversions/; s/absolut/absolute/ >> >> OK with those changes. > > > Thanks for the careful review! Done and committed in r248431. > Hi, I have noticed failures on arm*: Executed from: gcc.dg/fixed-point/fixed-point.exp gcc.dg/fixed-point/int-warning.c (test for warnings, line 12) gcc.dg/fixed-point/int-warning.c (test for warnings, line 13) gcc.dg/fixed-point/int-warning.c (test for warnings, line 14) gcc.dg/fixed-point/int-warning.c (test for warnings, line 15) gcc.dg/fixed-point/int-warning.c (test for warnings, line 16) gcc.dg/fixed-point/int-warning.c (test for warnings, line 17) gcc.dg/fixed-point/int-warning.c (test for warnings, line 18) gcc.dg/fixed-point/int-warning.c (test for warnings, line 19) gcc.dg/fixed-point/int-warning.c (test for warnings, line 20) gcc.dg/fixed-point/int-warning.c (test for warnings, line 21) gcc.dg/fixed-point/int-warning.c (test for warnings, line 22) gcc.dg/fixed-point/int-warning.c (test for warnings, line 23) gcc.dg/fixed-point/int-warning.c (test for excess errors) Excess errors: /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/fixed-point/int-warning.c:12:8: warning: overflow in conversion from '_Accum' to 'signed char' chages value from '5.0e+2' to '-12' [-Woverflow] /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/fixed-point/int-warning.c:13:8: warning: overflow in conversion from '_Accum' to 'signed char' chages value from '-5.0e+2' to '12' [-Woverflow] /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/fixed-point/int-warning.c:14:8: warning: overflow in conversion from 'long _Accum' to 'signed char' chages value from '5.0e+2' to '-12' [-Woverflow] /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/fixed-point/int-warning.c:15:8: warning: overflow in conversion from 'long _Accum' to 'signed char' chages value from '-5.0e+2' to '12' [-Woverflow] /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/fixed-point/int-warning.c:16:8: warning: overflow in conversion from 'long long _Accum' to 'signed char' chages value from '5.0e+2' to '-12' [-Woverflow] /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/fixed-point/int-warning.c:17:8: warning: overflow in conversion from 'long long _Accum' to 'signed char' chages value from '-5.0e+2' to '12' [-Woverflow] /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/fixed-point/int-warning.c:18:8: warning: overflow in conversion from '_Accum' to 'unsigned char' chages value from '5.0e+2' to '244' [-Woverflow] /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/fixed-point/int-warning.c:19:8: warning: overflow in conversion from '_Accum' to 'unsigned char' chages value from '-5.0e+2' to '12' [-Woverflow] /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/fixed-point/int-warning.c:20:8: warning: overflow in conversion from 'long _Accum' to 'unsigned char' chages value from '5.0e+2' to '244' [-Woverflow] /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/fixed-point/int-warning.c:21:8: warning: overflow in conversion from 'long _Accum' to 'unsigned char' chages value from '-5.0e+2' to '12' [-Woverflow] /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/fixed-point/int-warning.c:22:8: warning: overflow in conversion from 'long long _Accum' to 'unsigned char' chages value from '5.0e+2' to '244' [-Woverflow] /aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/testsuite/gcc.dg/fixed-point/int-warning.c:23:8: warning: overflow in conversion from 'long long _Accum' to 'unsigned char' chages value from '-5.0e+2' to '12' [-Woverflow] Still present at r248552. Thanks, Christophe > Martin >