From patchwork Wed Mar 22 13:59:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 742077 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 3vpBBM4X8Zz9s7b for ; Thu, 23 Mar 2017 00:59:22 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="coafL19A"; 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 :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=kjoxnnzhkgyaoepPDEXIM3FwrIM+TYklBe0nE2mW2fpEOh HKmlul2xPV/GlbDHhveJ0AmauHf7ZaFbZQLF3S6xzW8/wSWK90tRyHDx9FSQL91L 3bvxQvJ689mT3ljq94pcxHfKcp4GGLjl3+0I7HsV7tvYpcZ4XrEVGBD+45JAA= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=6KF0AjPnoZiIAdEiVQBAENaoyfQ=; b=coafL19AGlXlp+CPDeME WNYO7kE8e9hTl+iocYREBD7FKGs5VGTkcYUjfAElMdH2XabYvW6GYe7LFs9BlNKM T7Z/iR3wFRdnxw9gebIKtTYc4GVRBYr4ldZxvhR9t05hngWE0eEuAa/6+HGU912s i9t1PCzgnxBePlfAXxXAvBM= Received: (qmail 47818 invoked by alias); 22 Mar 2017 13:59:11 -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 45863 invoked by uid 89); 22 Mar 2017 13:59:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=17227 X-HELO: mail-ot0-f178.google.com Received: from mail-ot0-f178.google.com (HELO mail-ot0-f178.google.com) (74.125.82.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 Mar 2017 13:59:08 +0000 Received: by mail-ot0-f178.google.com with SMTP id y88so14275531ota.2 for ; Wed, 22 Mar 2017 06:59:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=IXBZY7M/vQUxFYJjvCvvkQQ/RNxh+bpirCh5TUseFaU=; b=UEwdWjnjbnpguhFRJ2MeW3MnA1+j81/NJ95FJej9HflvwWnpqH7qngJioXoT+dOJz1 hmTOaYFKmeCwtiNHRk6K01g646bCg06ZaO3Gy67NrjFwtSzhmqeJ8jCTWKqPx8tjv0E5 T00CW43es50WTFi5tjN2w8jGSALkZZ3ysIKt9dgVUgpD1d6jwfp9i7ZGUWvJAzr4NNcP FhtdlU4EjhO6MTiFKDNismT7+v/zdpfhvjn2DIJ7i9uxyYtqws6VD7Ow+vLetWssl5n3 2YEYbmxMwUlAEFHr/EE1l+G820eHUV16bKBajMY0NGz0+Ic6N0Th6zYr66FFESaSmV7P gScw== X-Gm-Message-State: AFeK/H1TQfmvtV2AnZZV96Zc3+PmmTlJQe+PR5nEPCOfoJcpulX1TzIRBoCSMNi/NliWac1YIIHEe93xexsiWg== X-Received: by 10.157.23.25 with SMTP id i25mr24628525ota.232.1490191147811; Wed, 22 Mar 2017 06:59:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.202.102.158 with HTTP; Wed, 22 Mar 2017 06:59:07 -0700 (PDT) From: Ian Lance Taylor Date: Wed, 22 Mar 2017 06:59:07 -0700 Message-ID: Subject: Go patch committed: check backend alignment for memequalNN functions To: gcc-patches , "gofrontend-dev@googlegroups.com" The Go frontend was assuming the usual required alignment for the memequalNN functions (16 bits for int16, 32 for int32, etc.). However, on m68k the required alignment of int32 is only 16 bits. Assuming the memequalNN alignment caused the compiler to incorrectly decide that int32 required a specially generated function rather than calling memequal32. This then crashed if the type descriptor were generated after type-specific functions had been written. Bootstrapped and ran Go tests on x86_64-pc-linux-gnu. Committed to mainline. This fixes GCC PR 80128. Ian Index: gcc/go/gofrontend/types.h =================================================================== --- gcc/go/gofrontend/types.h (revision 245745) +++ gcc/go/gofrontend/types.h (working copy) @@ -993,6 +993,9 @@ class Type const std::string& equal_name, Function_type* equal_fntype); + // Return the alignment required by the memequalN function. + static int64_t memequal_align(Gogo*, int size); + // Export the type. void export_type(Export* exp) const Index: gcc/go/gofrontend/types.cc =================================================================== --- gcc/go/gofrontend/types.cc (revision 245745) +++ gcc/go/gofrontend/types.cc (working copy) @@ -1580,6 +1580,42 @@ Type::make_type_descriptor_ptr_type() return ret; } +// Return the alignment required by the memequalN function. N is a +// type size: 16, 32, 64, or 128. The memequalN functions are defined +// in libgo/go/runtime/alg.go. + +int64_t +Type::memequal_align(Gogo* gogo, int size) +{ + const char* tn; + switch (size) + { + case 16: + tn = "int16"; + break; + case 32: + tn = "int32"; + break; + case 64: + tn = "int64"; + break; + case 128: + // The code uses [2]int64, which must have the same alignment as + // int64. + tn = "int64"; + break; + default: + go_unreachable(); + } + + Type* t = Type::lookup_integer_type(tn); + + int64_t ret; + if (!t->backend_type_align(gogo, &ret)) + go_unreachable(); + return ret; +} + // Return whether this type needs specially built type functions. // This returns true for types that are comparable and either can not // use an identity comparison, or are a non-standard size. @@ -1614,14 +1650,13 @@ Type::needs_specific_type_functions(Gogo case 0: case 1: case 2: - return align < 2; + return align < Type::memequal_align(gogo, 16); case 4: - return align < 4; + return align < Type::memequal_align(gogo, 32); case 8: - return align < 8; + return align < Type::memequal_align(gogo, 64); case 16: - // 8, not 16, because of how runtime.memequal128 is written. - return align < 8; + return align < Type::memequal_align(gogo, 128); default: return true; } @@ -1713,7 +1748,7 @@ Type::type_functions(Gogo* gogo, Named_t equal_fnname = "runtime.memequal8"; break; case 2: - if (align < 2) + if (align < Type::memequal_align(gogo, 16)) build_functions = true; else { @@ -1722,7 +1757,7 @@ Type::type_functions(Gogo* gogo, Named_t } break; case 4: - if (align < 4) + if (align < Type::memequal_align(gogo, 32)) build_functions = true; else { @@ -1731,7 +1766,7 @@ Type::type_functions(Gogo* gogo, Named_t } break; case 8: - if (align < 8) + if (align < Type::memequal_align(gogo, 64)) build_functions = true; else { @@ -1740,8 +1775,7 @@ Type::type_functions(Gogo* gogo, Named_t } break; case 16: - // 8, not 16, because of how runtime.memequal128 is written. - if (align < 8) + if (align < Type::memequal_align(gogo, 128)) build_functions = true; else {