From patchwork Mon Nov 19 21:37:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1000112 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-490459-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="hYSvOrxQ"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42zMdZ6QLRz9s0n for ; Tue, 20 Nov 2018 08:38:10 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=DHGpYcJkgTRSL5N8vvQAnHxzgtQcwB6OXwaAX8wMEmKIR4lNhO K5Lea+0dJKXcPCYBl9oAsFkw3EBgqT3HFNdrs2NGrHqi19Jjy1DQql6H/OIyl+N5 ZGPABOc15lXxVDl61UCoPTkGCwztQSr73KdrJjMBHnxMVlqPOgw/2W2lo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=SSTLs8pzjx4q6C8wgoc13JNpTls=; b=hYSvOrxQ/NfmS5McSncf hP+ZKqzmF4qPStw+5SG2pNjxwqmm0jFEudE3VgtqiGCFQ+UEvQxv4vKMf/YuvpW8 rRKaY0sBQCjT4X024ZjoBivgJrHuxLpyhNGqYahtl3SJnDa2tGkRvZUCye8NHv/9 y5M+4p6S8B5vrvvZD8LoAMs= Received: (qmail 105630 invoked by alias); 19 Nov 2018 21:38:03 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 105618 invoked by uid 89); 19 Nov 2018 21:38:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=outstanding, unusual, harness, 88104 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 19 Nov 2018 21:38:01 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F82A307D866 for ; Mon, 19 Nov 2018 21:38:00 +0000 (UTC) Received: from localhost.localdomain (ovpn-117-105.phx2.redhat.com [10.3.117.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2092160153 for ; Mon, 19 Nov 2018 21:38:00 +0000 (UTC) To: Gcc Patch List From: Martin Sebor Subject: [PATCH] handle unusual targets in -Wbuiltin-declaration-mismatch (PR 88098) Message-ID: Date: Mon, 19 Nov 2018 14:37:59 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 The gcc.dg/Wbuiltin-declaration-mismatch-4.c test added with the recent -Wbuiltin-declaration-mismatch enhancement to detect calls with incompatible arguments to built-ins declared without a prototype fails on a few targets due to incorrect assumptions hardcoded into the test. Besides removing those assumptions (or adding appropriate { target } attributes, the attached patch also adjusts the implementation of the warning to avoid triggering for enum promotion to int on short_enums targets. Since the fix is trivial I plan to commit it tomorrow if there are no concerns. Tested on x86_64-linux and with an arm-none-eabi cross-compiler. I also did a little bit of testing with sparc-solaris2.11 cross compiler but there the test harness fails due to the -m32 option so the Wbuiltin-declaration-mismatch-4.c still has unexpected FAILs. I've raised bug 88104 for the outstanding problem on sparc-solaris2.11. Martin PR testsuite/88098 - FAIL: gcc.dg/Wbuiltin-declaration-mismatch-4.c (test for warnings gcc/c/ChangeLog: PR testsuite/88098 * c-typeck.c (maybe_warn_builtin_no_proto_arg): Handle short enum to int promotion. gcc/testsuite/ChangeLog: PR testsuite/88098 * gcc.dg/Wbuiltin-declaration-mismatch-4.c: Adjust. * gcc.dg/Wbuiltin-declaration-mismatch-5.c: New test. Index: gcc/c/c-typeck.c =================================================================== --- gcc/c/c-typeck.c (revision 266284) +++ gcc/c/c-typeck.c (working copy) @@ -6461,7 +6461,9 @@ maybe_warn_builtin_no_proto_arg (location_t loc, t && TYPE_MODE (parmtype) == TYPE_MODE (argtype)) return; - if (parmcode == argcode + if ((parmcode == argcode + || (parmcode == INTEGER_TYPE + && argcode == ENUMERAL_TYPE)) && TYPE_MAIN_VARIANT (parmtype) == TYPE_MAIN_VARIANT (promoted)) return; Index: gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-4.c =================================================================== --- gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-4.c (revision 266284) +++ gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-4.c (working copy) @@ -77,9 +77,9 @@ void test_integer_conversion_memset (void *d) /* Passing a ptrdiff_t where size_t is expected may not be unsafe but because GCC may emits suboptimal code for such calls warning for them helps improve efficiency. */ - memset (d, 0, diffi); /* { dg-warning ".memset. argument 3 promotes to .ptrdiff_t. {aka .long int.} where .long unsigned int. is expected" } */ + memset (d, 0, diffi); /* { dg-warning ".memset. argument 3 promotes to .ptrdiff_t. {aka .\(long \)?int.} where .\(long \)?unsigned int. is expected" } */ - memset (d, 0, 2.0); /* { dg-warning ".memset. argument 3 type is .double. where 'long unsigned int' is expected" } */ + memset (d, 0, 2.0); /* { dg-warning ".memset. argument 3 type is .double. where '\(long \)?unsigned int' is expected" } */ /* Verify that the same call as above but to the built-in doesn't trigger a warning. */ @@ -95,7 +95,7 @@ double fabs (); /* { dg-message "built-i /* Expect a warning for fabsf below because even a float argument promotes to double. Unfortunately, invalid calls to fabsf() are not diagnosed. */ float fabsf (); /* { dg-warning "conflicting types for built-in function .fabsf.; expected .float\\\(float\\\)." } */ -long double fabsl (); /* { dg-message "built-in .fabsl. declared here" } */ +long double fabsl (); /* { dg-message "built-in .fabsl. declared here" "large long double" { target large_long_double } } */ void test_real_conversion_fabs (void) { @@ -108,7 +108,8 @@ void test_real_conversion_fabs (void) /* In C, the type of an enumeration constant is int. */ d = fabs (e0); /* { dg-warning ".fabs. argument 1 type is .int. where .double. is expected in a call to built-in function declared without prototype" } */ - d = fabs (e); /* { dg-warning ".fabs. argument 1 type is .enum E. where .double. is expected in a call to built-in function declared without prototype" } */ + d = fabs (e); /* { dg-warning ".fabs. argument 1 type is .enum E. where .double. is expected in a call to built-in function declared without prototype" "ordinary enum" { target { ! short_enums } } } */ + /* { dg-warning ".fabs. argument 1 promotes to .int. where .double. is expected in a call to built-in function declared without prototype" "size 1 enum" { target short_enums } .-1 } */ /* No warning here since float is promoted to double. */ d = fabs (f); @@ -117,9 +118,9 @@ void test_real_conversion_fabs (void) d = fabsf (c); /* { dg-warning ".fabsf. argument 1 promotes to .int. where .float. is expected in a call to built-in function declared without prototype" "pr87890" { xfail *-*-* } } */ - d = fabsl (c); /* { dg-warning ".fabsl. argument 1 promotes to .int. where .long double. is expected in a call to built-in function declared without prototype" } */ + d = fabsl (c); /* { dg-warning ".fabsl. argument 1 promotes to .int. where .long double. is expected in a call to built-in function declared without prototype" "large long double" { target large_long_double } } */ - d = fabsl (f); /* { dg-warning ".fabsl. argument 1 promotes to .double. where .long double. is expected in a call to built-in function declared without prototype" } */ + d = fabsl (f); /* { dg-warning ".fabsl. argument 1 promotes to .double. where .long double. is expected in a call to built-in function declared without prototype" "large long double" { target large_long_double } } */ /* Verify that the same call as above but to the built-in doesn't trigger a warning. */ Index: gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-5.c =================================================================== --- gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-5.c (nonexistent) +++ gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-5.c (working copy) @@ -0,0 +1,19 @@ +/* PR testsuite/88098 - FAIL: gcc.dg/Wbuiltin-declaration-mismatch-4.c + { dg-do compile } + { dg-options "-Wbuiltin-declaration-mismatch -fshort-enums" } */ + +int abs (); +double fabs (); /* { dg-message "built-in .fabs. declared here" } */ + +enum E { e0 } e; + +int i; +double d; + +void test_short_enums (void) +{ + /* enum e promotes to int. */ + i = abs (e); + + d = fabs (e); /* { dg-warning ".fabs. argument 1 promotes to .int. where .double. is expected in a call to built-in function declared without prototype" } */ +}