From patchwork Tue Jun 4 16:09:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 1109996 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-502317-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="GKQuEpWi"; 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 45JH294jdDz9sCJ for ; Wed, 5 Jun 2019 02:10:07 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:date:mime-version:message-id:content-type :content-transfer-encoding; q=dns; s=default; b=rbY7C0XbvUbqhffS mIai1bBo8bW0FYBuoUfDarvkQslGqUdyw1zaPyRor6ASXiwJ0RHGO4/w8tqRHmlj KzaxTZZ3fjPW3O2IR8xxcYf36D8K1qKmqR+u+KfnzFEbPYbkB9+SRLm6SdaT0XEt cXskui5p6N+cyDa616OVz/L5LBg= 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:cc :from:subject:date:mime-version:message-id:content-type :content-transfer-encoding; s=default; bh=pyx0iX057ypijiF4saOlAI TKQQA=; b=GKQuEpWiXaze6B5DpDBkEiibIo3Mr1hXKyS7TQ4upr5yp07fC3+Bmn eixbwIhy+sj2kZ+J7w6y2bUuext0xfTy4K+oJJHCJYazKbXSEpb7Sn/upJ7xpI7I ewMcZh+WeUrhGr3q45hdNqOebPKFLv86Feh5P2zjJ9gIhrQzSJkHE= Received: (qmail 39015 invoked by alias); 4 Jun 2019 16:10:00 -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 38996 invoked by uid 89); 4 Jun 2019 16:09:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=pixel, compliance, pedantic-errors, dgexp X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Jun 2019 16:09:57 +0000 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x54Fvx6u125012 for ; Tue, 4 Jun 2019 12:09:50 -0400 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0b-001b2d01.pphosted.com with ESMTP id 2swu2qtmnk-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 04 Jun 2019 12:09:49 -0400 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 4 Jun 2019 17:09:48 +0100 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 4 Jun 2019 17:09:47 +0100 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x54G9kgi12386424 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 4 Jun 2019 16:09:46 GMT Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D7DF6E058; Tue, 4 Jun 2019 16:09:46 +0000 (GMT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CBD5E6E052; Tue, 4 Jun 2019 16:09:45 +0000 (GMT) Received: from BigMac.local (unknown [9.85.150.87]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 4 Jun 2019 16:09:45 +0000 (GMT) To: GCC Patches Cc: Segher Boessenkool From: Bill Schmidt Subject: [PATCH] rs6000: Fix PR78263: Don't #define vector, pixel, bool for C++ with strict ANSI Date: Tue, 4 Jun 2019 11:09:44 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 x-cbid: 19060416-0016-0000-0000-000009BDFE08 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00011214; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000286; SDB=6.01213175; UDB=6.00637611; IPR=6.00994243; MB=3.00027182; MTD=3.00000008; XFM=3.00000015; UTC=2019-06-04 16:09:48 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19060416-0017-0000-0000-0000437E0601 Message-Id: <33503db2-15a3-b10e-e852-fca53aa2d096@linux.ibm.com> Hi, We've had a long-standing issue (PR78263) with altivec.h wherein the #define of bool causes difficulties with C++ code with strict ANSI requirements (-std=c++11 versus -std=gnu+11, for example). This patch disables the AltiVec keywords from being #define'd under those circumstances. There is some small potential for fallout in package builds where is included, strict ANSI is required, the C++ "bool" keyword is not otherwise used, and the AltiVec "vector" or "pixel" keywords appear in source. This is regrettable but necessary for language compliance. In such cases, the correct fix to the source code is to replace "vector" by "__vector", "bool" by "__bool", and "pixel" by "__pixel". I've added a target-specific C++ test to ensure the #define's are disabled. This is the first target-specific C++ test for Power, so I created the new g++.target/powerpc directory and added powerpc.exp there, based on the existing aarch64.exp in a sister directory. Bootstrapped and tested on powerpc64le-unknown-linux-gnu with no regressions. Is this okay for trunk? Thanks, Bill [gcc] 2019-06-04 Bill Schmidt PR target/78263 * config/rs6000/altivec.h: Don't #define vector, pixel, bool for C++ with strict ANSI requirements. [gcc/testsuite] 2019-06-04 Bill Schmidt PR target/78263 * g++.target/powerpc: New directory. * g++.target/powerpc/powerpc.exp: New test driver. * g++.target/powerpc/undef-bool-3.C: New. Index: gcc/config/rs6000/altivec.h =================================================================== --- gcc/config/rs6000/altivec.h (revision 271907) +++ gcc/config/rs6000/altivec.h (working copy) @@ -37,10 +37,12 @@ /* If __APPLE_ALTIVEC__ is defined, the compiler supports 'vector', 'pixel' and 'bool' as context-sensitive AltiVec keywords (in non-AltiVec contexts, they revert to their original meanings, - if any), so we do not need to define them as macros. */ + if any), so we do not need to define them as macros. Also, + avoid defining them as macros for C++ with strict ANSI, as + this is not compatible. */ -#if !defined(__APPLE_ALTIVEC__) -/* You are allowed to undef these for C++ compatibility. */ +#if !defined(__APPLE_ALTIVEC__) && (!defined(__STRICT_ANSI__) \ + || !defined(__cplusplus)) #define vector __vector #define pixel __pixel #define bool __bool Index: gcc/testsuite/g++.target/powerpc/powerpc.exp =================================================================== --- gcc/testsuite/g++.target/powerpc/powerpc.exp (nonexistent) +++ gcc/testsuite/g++.target/powerpc/powerpc.exp (working copy) @@ -0,0 +1,44 @@ +# Specific regression driver for PowerPC. +# Copyright (C) 2019 Free Software Foundation, Inc. +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GCC is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . */ + +# GCC testsuite that uses the `dg.exp' driver. + +# Exit immediately if this isn't a PowerPC target. +if {![istarget powerpc64*-*-*] } then { + return +} + +# Load support procs. +load_lib g++-dg.exp + +global DEFAULT_CXXFLAGS +if ![info exists DEFAULT_CXXFLAGS] then { + set DEFAULT_CXXFLAGS " -pedantic-errors" +} + +# Initialize `dg'. +dg-init + +# Main loop. +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C]] \ + "" $DEFAULT_CXXFLAGS + +# All done. +dg-finish + Index: gcc/testsuite/g++.target/powerpc/undef-bool-3.C =================================================================== --- gcc/testsuite/g++.target/powerpc/undef-bool-3.C (nonexistent) +++ gcc/testsuite/g++.target/powerpc/undef-bool-3.C (working copy) @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -std=c++11" } */ + +/* Test to ensure that "bool" is not #define'd in altivec.h for C++ when + we require strict ANSI. We should compile without errors. */ + +#include + +bool foo (int x) +{ + return x == 2; +} +