From patchwork Wed Jul 12 08:45:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 787079 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3x6sxK6SwSz9s78 for ; Wed, 12 Jul 2017 18:46:12 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="mFBUPKrH"; dkim-atps=neutral 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:message-id:date:mime-version:content-type; q=dns; s=default; b=bQBklismQI96k/2o1CabHzrFNaYvFXzcq7HzYWEl5h2TeHX9Ab RMNHDnsfkJJW1mNiZpCS6htI9VstjqnJBpcdEbosUpk1jBIh1CYJO1/Q10tixuQV fHx/qHy3Ihn6w9YSAehyScEA8PFybwm4cN44VbVPu6uADvZVVlQwiyOPk= 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:message-id:date:mime-version:content-type; s= default; bh=YU53MqC3N1R0OGggOrVlbWXmNeE=; b=mFBUPKrHU1SjfwHu9j7S DcWC2k4lQTHy5C0fKnYDrCPRzH85Xt0CTxNkpoXdHFpkk0eRTZpKA5lRajEF6sAQ ctWLw1IZR/4LAjbsQ1ZAwXcjzC9Sv4FWGJl3XDJTP4k6oXJbEFMKh4C8qLvARJkS h5tNhIzo9/0nWFY8EgPR1Ik= Received: (qmail 84315 invoked by alias); 12 Jul 2017 08:45:46 -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 84106 invoked by uid 89); 12 Jul 2017 08:45:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy= X-HELO: mo4-p00-ob.smtp.rzone.de Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.217) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 12 Jul 2017 08:45:35 +0000 X-RZG-AUTH: :LXoWVUeid/7A29J/hMvvT3ol15ykJcYwR/bcHRirORRW3yMcVao= X-RZG-CLASS-ID: mo00 Received: from [192.168.0.123] (mail.hightec-rt.com [213.135.1.215]) by smtp.strato.de (RZmta 41.1 DYNA|AUTH) with ESMTPSA id e084b6t6C8jPHBT (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Wed, 12 Jul 2017 10:45:25 +0200 (CEST) To: gcc-patches Cc: Denis Chertykov From: Georg-Johann Lay Subject: [patch,avr] PR81407: Error if progmem variable needs constructing. Message-ID: Date: Wed, 12 Jul 2017 10:45:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi, if the C++ front-end decides that something will need constructing, it will silently put the stuff into .rodata so that according pgm_read_xxx will read garbage from .progmem. As proposed by Jason, this patch diagnoses such situations. Ok to commit? Johann PR target/81407 * config/avr/avr.c (avr_encode_section_info) [progmem && !TREE_READONLY]: Error if progmem object needs constructing. Index: config/avr/avr.c =================================================================== --- config/avr/avr.c (revision 250093) +++ config/avr/avr.c (working copy) @@ -10380,14 +10380,22 @@ avr_encode_section_info (tree decl, rtx && !DECL_EXTERNAL (decl) && avr_progmem_p (decl, DECL_ATTRIBUTES (decl))) { - // Don't warn for (implicit) aliases like in PR80462. tree asmname = DECL_ASSEMBLER_NAME (decl); varpool_node *node = varpool_node::get_for_asmname (asmname); bool alias_p = node && node->alias; - if (!alias_p) - warning (OPT_Wuninitialized, "uninitialized variable %q+D put into " - "program memory area", decl); + if (!TREE_READONLY (decl)) + { + // This might happen with C++ if stuff needs constructing. + error ("variable %q+D with dynamic initialization put " + "into program memory area", decl); + } + else if (!alias_p) + { + // Don't warn for (implicit) aliases like in PR80462. + warning (OPT_Wuninitialized, "uninitialized variable %q+D put " + "into program memory area", decl); + } } default_encode_section_info (decl, rtl, new_decl_p);