From patchwork Mon Sep 17 07:47:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 184315 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]) by ozlabs.org (Postfix) with SMTP id 23A3E2C007E for ; Mon, 17 Sep 2012 17:48:26 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1348472907; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=kvvhwaO +6KcoFADNXiImwFaQ4j8=; b=N5VgeQLFwTEYPiT4vg8fxLuo5Rzfv2bSl8Ns7s0 qbsnTlLHYUgJRV3Q8AFAW9nIxi4+mqFL+nTsSY9uAKV3DFvWAE8eoDf/CZQmdpB8 y3nl/Kzyeb875/m4nvagdwu+0LXzhVfaYCMUvOiwCexJuQX21J/eXwGV0XWL5Ulw gwGE= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=I0EJdwboZMGCYfpZaQGerCFZHgUg0PGCNBcP71kCBuFOJ7fRqEFYqISfEFthIA Ttn0dKVe/7IIry3BsYgERH1U1RLzrl1AmsI+kUTTAE+bvRePZgpZOFRBiE+KW/jx +QzyIPn+2nC8YUOVtO5Rjcl2z18BI/hQJ2n5pmvIMYhg8=; Received: (qmail 16757 invoked by alias); 17 Sep 2012 07:48:11 -0000 Received: (qmail 16725 invoked by uid 22791); 17 Sep 2012 07:48:08 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 17 Sep 2012 07:47:53 +0000 Received: from [192.168.178.22] (port-92-204-67-8.dynamic.qsc.de [92.204.67.8]) by mx01.qsc.de (Postfix) with ESMTP id CA82D3CC02; Mon, 17 Sep 2012 09:47:44 +0200 (CEST) Message-ID: <5056D59E.7070303@net-b.de> Date: Mon, 17 Sep 2012 09:47:42 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120825 Thunderbird/15.0 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR54599 (4/n) FIx issues found by Coverity scann 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 This patch fixes some of the issues collected in the PR. Some remarks to the changed in the attached patch: - gcc_assert (*format++ == '$'); That code gets executed when "some error message with value %d for string %s" gets translated into "some error message for string %2$s with value %1$d" And without the ++ gfortran doesn't skip over the $ sign. + gcc_assert (derived1 && derived2); One of the many places where we first check for non-NULL - and then dereference the pointer unconditionally. - && ref->u.ar.as->lower && ref->u.ar.as->upper) "lower" is an array of pointers but not a pointer itself - thus, "lower" is always != NULL. Ditto for upper. - break; + continue; It makes sense to walk through the loop more than once ;-) + size = int_size_in_bytes (type); + gcc_assert (size >= 0); The function returns a HOST_WIDE_INT or -1 if it doesn't fit into that signed variable. To silence the warning, I now check the result and added an assert. Build and regtested on x86-64-linux. OK for the trunk? Tobias 2012-09-17 Tobias Burnus * error.c (error_print): Move increment out of the assert. * interface.c (gfc_compare_derived_types): Add assert. (get_expr_storage_size): Remove always-true logical condition. * resolve.c (resolve_allocate_expr): Fix looping logic. * target-memory.c (gfc_target_expr_size): Add assert. diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c index 64b9357..4b06156 100644 --- a/gcc/fortran/error.c +++ b/gcc/fortran/error.c @@ -536,23 +536,24 @@ error_print (const char *type, const char *format0, va_list argp) if (ISDIGIT (*format)) { /* This is a position specifier. For example, the number 12 in the format string "%12$d", which specifies the third argument of the va_list, formatted in %d format. For details, see "man 3 printf". */ pos = atoi(format) - 1; gcc_assert (pos >= 0); while (ISDIGIT(*format)) format++; - gcc_assert (*format++ == '$'); + gcc_assert (*format == '$'); + format++; } else pos++; c = *format++; if (pos > maxpos) maxpos = pos; switch (c) { diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c index b348856..88689aa 100644 --- a/gcc/fortran/interface.c +++ b/gcc/fortran/interface.c @@ -388,27 +388,28 @@ gfc_match_end_interface (void) /* Compare two derived types using the criteria in 4.4.2 of the standard, recursing through gfc_compare_types for the components. */ int gfc_compare_derived_types (gfc_symbol *derived1, gfc_symbol *derived2) { gfc_component *dt1, *dt2; if (derived1 == derived2) return 1; + gcc_assert (derived1 && derived2); + /* Special case for comparing derived types across namespaces. If the true names and module names are the same and the module name is nonnull, then they are equal. */ - if (derived1 != NULL && derived2 != NULL - && strcmp (derived1->name, derived2->name) == 0 + if (strcmp (derived1->name, derived2->name) == 0 && derived1->module != NULL && derived2->module != NULL && strcmp (derived1->module, derived2->module) == 0) return 1; /* Compare type via the rules of the standard. Both types must have the SEQUENCE or BIND(C) attribute to be equal. */ if (strcmp (derived1->name, derived2->name)) return 0; if (derived1->component_access == ACCESS_PRIVATE @@ -2259,24 +2260,23 @@ get_expr_storage_size (gfc_expr *e) else return 0; } else if (ref->u.ar.as->upper[i] && ref->u.ar.as->upper[i]->expr_type == EXPR_CONSTANT) end = mpz_get_si (ref->u.ar.as->upper[i]->value.integer); else return 0; elements *= (end - start)/stride + 1L; } - else if (ref->type == REF_ARRAY && ref->u.ar.type == AR_FULL - && ref->u.ar.as->lower && ref->u.ar.as->upper) + else if (ref->type == REF_ARRAY && ref->u.ar.type == AR_FULL) for (i = 0; i < ref->u.ar.as->rank; i++) { if (ref->u.ar.as->lower[i] && ref->u.ar.as->upper[i] && ref->u.ar.as->lower[i]->expr_type == EXPR_CONSTANT && ref->u.ar.as->upper[i]->expr_type == EXPR_CONSTANT) elements *= mpz_get_si (ref->u.ar.as->upper[i]->value.integer) - mpz_get_si (ref->u.ar.as->lower[i]->value.integer) + 1L; else return 0; } diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 6a7b6c9..f67c07f 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -7419,23 +7419,23 @@ check_symbols: for (i = ar->dimen; i < ar->codimen + ar->dimen; i++) { if (ar->dimen_type[i] == DIMEN_ELEMENT || ar->dimen_type[i] == DIMEN_RANGE) { if (i == (ar->dimen + ar->codimen - 1)) { gfc_error ("Expected '*' in coindex specification in ALLOCATE " "statement at %L", &e->where); goto failure; } - break; + continue; } if (ar->dimen_type[i] == DIMEN_STAR && i == (ar->dimen + ar->codimen - 1) && ar->stride[i] == NULL) break; gfc_error ("Bad coarray specification in ALLOCATE statement at %L", &e->where); goto failure; } diff --git a/gcc/fortran/target-memory.c b/gcc/fortran/target-memory.c index bedc668..7a55dcd 100644 --- a/gcc/fortran/target-memory.c +++ b/gcc/fortran/target-memory.c @@ -117,25 +117,28 @@ gfc_target_expr_size (gfc_expr *e) } else return 0; case BT_HOLLERITH: return e->representation.length; case BT_DERIVED: { /* Determine type size without clobbering the typespec for ISO C binding types. */ gfc_typespec ts; + HOST_WIDE_INT size; ts = e->ts; type = gfc_typenode_for_spec (&ts); - return int_size_in_bytes (type); + size = int_size_in_bytes (type); + gcc_assert (size >= 0); + return size; } default: gfc_internal_error ("Invalid expression in gfc_target_expr_size."); return 0; } } /* The encode_* functions export a value into a buffer, and return the number of bytes of the buffer that have been used. */