From patchwork Wed Feb 19 15:47:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 321963 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 59D052C0078 for ; Thu, 20 Feb 2014 02:48:49 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=j2sn8nKVpPWD u9ZyvYpfmhD8DnScDUwKNTlsDdS0TQxpH7ulhHUWxPIY844PnnA/N7NNiHvS4A09 KwTfRqdbAtkioev9+1xhZo7FJNi5ErRrFF0tx2eC464rpMGeM+OqchWnDjoUKuOE Fzsl5zbXflFRVKXjETQOpmw335D+l8o= 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:from :to:cc:subject:date:message-id; s=default; bh=qupJt36co7pKFY7b9+ 6RjggvCmM=; b=FlDXU0vT6gvoB6n5JiYgq+e9CnxaqVMzQzQ+2dNngJCsKCevGE bP8zLcDsU1ztZp1rozSOaOL/2WZY0Myl7LmuZF0yP+o7UMNgNn/tD6+xwRPHIMBe CyjJ23LRdnPwlhoSfIAhPrtzwvrsN+jzmJedmyrRnePrC+wgyyCbNh9pA= Received: (qmail 27615 invoked by alias); 19 Feb 2014 15:48:42 -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 27592 invoked by uid 89); 19 Feb 2014 15:48:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Feb 2014 15:48:41 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1JFmdcC026802 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 19 Feb 2014 10:48:39 -0500 Received: from surprise.redhat.com (vpn-235-58.phx2.redhat.com [10.3.235.58]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s1JFmc0A005822; Wed, 19 Feb 2014 10:48:39 -0500 From: David Malcolm To: jit@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [jit] Add some type-checking to parameters requiring pointers Date: Wed, 19 Feb 2014 10:47:11 -0500 Message-Id: <1392824831-26586-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes Committed to branch dmalcolm/jit: gcc/jit/ * libgccjit.c (gcc_jit_context_new_rvalue_from_ptr): Verify that pointer_type is indeed a pointer type. (gcc_jit_context_null): Likewise. (gcc_jit_context_new_array_access): Verify that ptr is indeed a pointer. * TODO.rst: Update --- gcc/jit/ChangeLog.jit | 10 ++++++++++ gcc/jit/TODO.rst | 9 +-------- gcc/jit/libgccjit.c | 13 +++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit index 860bee6..0978a9c 100644 --- a/gcc/jit/ChangeLog.jit +++ b/gcc/jit/ChangeLog.jit @@ -1,3 +1,13 @@ +2014-02-19 David Malcolm + + * libgccjit.c (gcc_jit_context_new_rvalue_from_ptr): Verify that + pointer_type is indeed a pointer type. + (gcc_jit_context_null): Likewise. + (gcc_jit_context_new_array_access): Verify that ptr is indeed a + pointer. + + * TODO.rst: Update + 2014-02-18 David Malcolm * libgccjit.h (gcc_jit_struct): New. diff --git a/gcc/jit/TODO.rst b/gcc/jit/TODO.rst index 7288aef..51a3cc9 100644 --- a/gcc/jit/TODO.rst +++ b/gcc/jit/TODO.rst @@ -96,20 +96,15 @@ Initial Release * gcc_jit_context_one: must be a numeric type - * gcc_jit_context_null: must be a pointer type - * gcc_jit_context_new_rvalue_from_double: must be a numeric type - * gcc_jit_context_new_rvalue_from_ptr: must be a pointer type - * gcc_jit_context_new_unary_op: various checks needed * gcc_jit_context_new_binary_op: various checks needed * gcc_jit_context_new_comparison: must be numeric or pointer types - * gcc_jit_context_new_array_lookup: "ptr" must be of pointer type; - "index" must be of numeric type. + * gcc_jit_context_new_array_access: "index" must be of numeric type. * gcc_jit_lvalue_access_field: must be field of correct struct @@ -119,8 +114,6 @@ Initial Release * gcc_jit_function_add_assignment_op: check the types - * gcc_jit_function_add_conditional: boolval must be of numeric type - * gcc_jit_loop_end: verify that loops are validly nested? Bugs diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c index d089ad5..797785b 100644 --- a/gcc/jit/libgccjit.c +++ b/gcc/jit/libgccjit.c @@ -680,6 +680,10 @@ gcc_jit_context_new_rvalue_from_ptr (gcc_jit_context *ctxt, { RETURN_NULL_IF_FAIL (ctxt, NULL, "NULL context"); RETURN_NULL_IF_FAIL (pointer_type, ctxt, "NULL type"); + RETURN_NULL_IF_FAIL_PRINTF1 ( + pointer_type->dereference (), ctxt, + "not a pointer type (type: %s)", + pointer_type->get_debug_string ()); return (gcc_jit_rvalue *)ctxt->new_rvalue_from_ptr (pointer_type, value); } @@ -690,6 +694,10 @@ gcc_jit_context_null (gcc_jit_context *ctxt, { RETURN_NULL_IF_FAIL (ctxt, NULL, "NULL context"); RETURN_NULL_IF_FAIL (pointer_type, ctxt, "NULL type"); + RETURN_NULL_IF_FAIL_PRINTF1 ( + pointer_type->dereference (), ctxt, + "not a pointer type (type: %s)", + pointer_type->get_debug_string ()); return gcc_jit_context_new_rvalue_from_ptr (ctxt, pointer_type, NULL); } @@ -823,6 +831,11 @@ gcc_jit_context_new_array_access (gcc_jit_context *ctxt, RETURN_NULL_IF_FAIL (ctxt, NULL, "NULL context"); RETURN_NULL_IF_FAIL (ptr, ctxt, "NULL ptr"); RETURN_NULL_IF_FAIL (index, ctxt, "NULL index"); + RETURN_NULL_IF_FAIL_PRINTF2 ( + ptr->get_type ()->dereference (), ctxt, + "%s (type: %s) is not a pointer", + ptr->get_debug_string (), + ptr->get_type ()->get_debug_string ()); return (gcc_jit_lvalue *)ctxt->new_array_access (loc, ptr, index); }