From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29163 invoked by alias); 18 Mar 2014 06:05:15 -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 29089 invoked by uid 48); 18 Mar 2014 06:05:09 -0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/60546] [4.8/4.9] O2 & asan enable generates wrong insns Date: Tue, 18 Mar 2014 06:05:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-03/txt/msg01508.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60546 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #21 from Jakub Jelinek --- What is not satisfying? struct QualifiedNameComponents { StringImpl* m_prefix; StringImpl* m_localName; StringImpl* m_namespace; }; ... template static inline unsigned computeHash(const T* data, unsigned length) { StringHasher hasher; bool rem = length & 1; length >>= 1; while (length--) { hasher.addCharacters(Converter(data[0]), Converter(data[1])); data += 2; } if (rem) hasher.addCharacter(Converter(*data)); return hasher.hash(); } ... template static inline unsigned hashMemory(const void* data) { typedef int dummylength_must_be_a_multible_of_four [(!(length % 4)) ? 1 : -1]; return computeHash(static_cast(data), length / sizeof(UChar)); } ... inline unsigned hashComponents(const QualifiedNameComponents& buf) { return StringHasher::hashMemory(&buf); } struct QualifiedNameHash { static unsigned hash(const QualifiedName& name) { return hash(name.impl()); } static unsigned hash(const QualifiedName::QualifiedNameImpl* name) { QualifiedNameComponents c = { name->m_prefix.impl(), name->m_localName.impl(), name->m_namespace.impl() }; return hashComponents(c); } static bool equal(const QualifiedName& a, const QualifiedName& b) { return a == b; } static bool equal(const QualifiedName::QualifiedNameImpl* a, const QualifiedName::QualifiedNameImpl* b) { return a == b; } static const bool safeToCompareToEmptyOrDeleted = false; }; is a clear aliasing violation and thus undefined behavior when called. The `c' object has object type QualifiedNameComponents, whose subobjects have type pointer to StringImpl. In computeHash you are then reading the object using the UChar (unsigned short) effective type, only char or unsigned char types can be used for that, see e.g. [basic.types]/2, or read -fstrict-aliasing documentation in info gcc. For g++, you could read the object through say typedef UChar UCharMayAlias __attribute__((__may_alias__));, or you can say std::memcpy the object into an correspondigly sized array of UChar and hash that rather than the original object, etc.