From patchwork Wed Mar 6 18:15:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 31745 Received: (qmail 35743 invoked by alias); 6 Mar 2019 18:15:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 34994 invoked by uid 89); 6 Mar 2019 18:15:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.2 required=5.0 tests=BAYES_00, DNS_FROM_AHBL_RHSBL, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.1 spammy= X-HELO: mail-wr1-f47.google.com Received: from mail-wr1-f47.google.com (HELO mail-wr1-f47.google.com) (209.85.221.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 06 Mar 2019 18:15:27 +0000 Received: by mail-wr1-f47.google.com with SMTP id w17so14496840wrn.12 for ; Wed, 06 Mar 2019 10:15:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=Dsc6c6NkxchKz3Vu+kArAW0IipfLglFe9+IYSWnfy3k=; b=Nv7aCaAjnkts+hFKUL0Z6NZ7B8f36rt26ean2w0mVHxufJpPrlNS0UvjAO60sS+ArQ hII0uGYqHZy8OX7AvuQ/ENjiZkGhjU1hKt5F5HzDBNobh91xY82V3DiU9qXTUgPAuSjF VSQJa6fCigQuCT0mSS8VF+VQc5K7rmcrEg1baOXK1RGLUFzjpshSnruW87Xxq/SsdyN2 Brf4zY493wz6ktAt6xC4Sukw+F/ghAB7G3ECrqUNVqXWICbHxbO+uGnpyT8C2R2HkUSa 49GEg2uT96ps3jgngN+W6vmjAbXDbcqgdpaTzaHZRAjP+KIokyLGvmaMpE1XgtcivI6M /+6A== Return-Path: Received: from localhost (host86-142-70-198.range86-142.btcentralplus.com. [86.142.70.198]) by smtp.gmail.com with ESMTPSA id f13sm1591323wmj.29.2019.03.06.10.15.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Mar 2019 10:15:18 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PUSHED 07/11] gdb/fortran: Expand the set of types that support (kind=N) Date: Wed, 6 Mar 2019 18:15:00 +0000 Message-Id: In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes Expand the number of types that can be adjusted with a (kind=N) type extension. gdb/ChangeLog: * f-exp.y (convert_to_kind_type): Handle more type kinds. gdb/testsuite/ChangeLog: * gdb.fortran/type-kinds.exp (test_cast_1_to_type_kind): New function. (test_basic_parsing_of_type_kinds): Expand types tested. (test_parsing_invalid_type_kinds): New function. --- gdb/ChangeLog | 4 ++++ gdb/f-exp.y | 36 ++++++++++++++++++++++++++++ gdb/testsuite/ChangeLog | 7 ++++++ gdb/testsuite/gdb.fortran/type-kinds.exp | 41 +++++++++++++++++++++++++++++++- 4 files changed, 87 insertions(+), 1 deletion(-) diff --git a/gdb/f-exp.y b/gdb/f-exp.y index 327f13736bd..980ee4b4adb 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -830,6 +830,42 @@ convert_to_kind_type (struct type *basetype, int kind) if (kind == 1) return parse_f_type (pstate)->builtin_character; } + else if (basetype == parse_f_type (pstate)->builtin_complex_s8) + { + if (kind == 4) + return parse_f_type (pstate)->builtin_complex_s8; + else if (kind == 8) + return parse_f_type (pstate)->builtin_complex_s16; + else if (kind == 16) + return parse_f_type (pstate)->builtin_complex_s32; + } + else if (basetype == parse_f_type (pstate)->builtin_real) + { + if (kind == 4) + return parse_f_type (pstate)->builtin_real; + else if (kind == 8) + return parse_f_type (pstate)->builtin_real_s8; + else if (kind == 16) + return parse_f_type (pstate)->builtin_real_s16; + } + else if (basetype == parse_f_type (pstate)->builtin_logical) + { + if (kind == 1) + return parse_f_type (pstate)->builtin_logical_s1; + else if (kind == 2) + return parse_f_type (pstate)->builtin_logical_s2; + else if (kind == 4) + return parse_f_type (pstate)->builtin_logical; + else if (kind == 8) + return parse_f_type (pstate)->builtin_logical_s8; + } + else if (basetype == parse_f_type (pstate)->builtin_integer) + { + if (kind == 2) + return parse_f_type (pstate)->builtin_integer_s2; + else if (kind == 4) + return parse_f_type (pstate)->builtin_integer; + } error (_("unsupported kind %d for type %s"), kind, TYPE_SAFE_NAME (basetype)); diff --git a/gdb/testsuite/gdb.fortran/type-kinds.exp b/gdb/testsuite/gdb.fortran/type-kinds.exp index b60b8044110..c679bc504f9 100644 --- a/gdb/testsuite/gdb.fortran/type-kinds.exp +++ b/gdb/testsuite/gdb.fortran/type-kinds.exp @@ -21,15 +21,54 @@ load_lib "fortran.exp" if { [skip_fortran_tests] } { continue } +# Cast the value 1 to the type 'BASE_TYPE (kind=TYPE_KIND)'. The +# expected result of the cast is CAST_RESULT, and the size of the +# value returned by the cast should be SIZE_RESULT. +proc test_cast_1_to_type_kind {base_type type_kind cast_result size_result} { + set type_string "$base_type (kind=$type_kind)" + gdb_test "p (($type_string) 1)" " = $cast_result" + + if {($base_type == "real" || $base_type == "complex") + && $type_kind == 16} { + setup_kfail gdb/18644 "*-*-*" + } + + gdb_test "p sizeof (($type_string) 1)" " = $size_result" +} + # Test parsing of `(kind=N)` type modifiers. proc test_basic_parsing_of_type_kinds {} { - gdb_test "p ((character (kind=1)) 1)" " = 1" + test_cast_1_to_type_kind "character" "1" "1" "1" + + test_cast_1_to_type_kind "complex" "4" "\\(1,0\\)" "8" + test_cast_1_to_type_kind "complex" "8" "\\(1,0\\)" "16" + test_cast_1_to_type_kind "complex" "16" "\\(1,0\\)" "32" + + test_cast_1_to_type_kind "real" "4" "1" "4" + test_cast_1_to_type_kind "real" "8" "1" "8" + test_cast_1_to_type_kind "real" "16" "1" "16" + + test_cast_1_to_type_kind "logical" "1" "\\.TRUE\\." "1" + test_cast_1_to_type_kind "logical" "4" "\\.TRUE\\." "4" + test_cast_1_to_type_kind "logical" "8" "\\.TRUE\\." "8" + + test_cast_1_to_type_kind "integer" "2" "1" "2" + test_cast_1_to_type_kind "integer" "4" "1" "4" +} + +proc test_parsing_invalid_type_kinds {} { + foreach typename {complex real logical integer} { + foreach typesize {3 5 7 9} { + gdb_test "p (($typename (kind=$typesize)) 1)" "unsupported kind $typesize for type $typename.*" + } + } } clean_restart if [set_lang_fortran] then { test_basic_parsing_of_type_kinds + test_parsing_invalid_type_kinds } else { warning "$test_name tests suppressed." 0 }