From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15548 invoked by alias); 8 May 2013 12:55:34 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 15531 invoked by uid 48); 8 May 2013 12:55:31 -0000 From: "ppluzhnikov at google dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/57199] [4.8/4.9 Regression] Bogus warning: iteration NNNN invokes undefined behavior -Waggressive-loop-optimizations Date: Wed, 08 May 2013 12:55:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ppluzhnikov at google dot com X-Bugzilla-Status: REOPENED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Status Resolution Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 X-SW-Source: 2013-05/txt/msg00522.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57199 Paul Pluzhnikov changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|INVALID | --- Comment #2 from Paul Pluzhnikov 2013-05-08 12:55:31 UTC --- > Thus, the warning, while not 100% helpful, points at a real problem. There is no real problem in the original source, which reads: size_t s = size(); if (n < s) DestroyElements(mutable_array() + n, s - n); else ... and produces the same warning. Here is updated test with above condition; confirmed to still show the warning with trunk @r198709. typedef decltype(sizeof(0)) size_t; struct Foo { ~Foo(); // comment out -> problem disappears int x[20]; }; template struct InlinedVector { inline InlinedVector() : size_(0) { } inline size_t size() const { return size_; } T* mutable_array(); void resize(size_t n) { size_t s = size(); if (n < s) DestroyElements(mutable_array() + n, s - n); } static void DestroyElements(T* ptr, size_t num) { for (size_t i = 0; i < num; i++) { ptr[i].~T(); } } size_t size_; }; struct CP { void Add(); InlinedVector foo_; }; void CP::Add() { foo_.resize(foo_.size() + 1); }