From: Phil Muldoon Date: Fri, 20 Jan 2017 15:34:28 +0000 (+0000) Subject: Fix pointer decay in compile print. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa9d0e041115f05379f31904ec82d3be0cb59d3a;p=thirdparty%2Fbinutils-gdb.git Fix pointer decay in compile print. Right now the assignment for an "auto" generated variable decays in cases where auto is a pointer. This renders further operations on it, like sizeof, or decltype inoperable. Revert back to using decltype directly on the input over the "auto" variable. Also, fix up some compile print cases in the testsuite that pass a ;. This will cause a syntax error in decltype. This commit also breaks string literals as they are declared as lvalues. --- diff --git a/gdb/compile/compile-c-support.c b/gdb/compile/compile-c-support.c index de2a67548af..3a3ed45d7e3 100644 --- a/gdb/compile/compile-c-support.c +++ b/gdb/compile/compile-c-support.c @@ -490,13 +490,13 @@ struct cplus_add_input fprintf_unfiltered (buf, "auto " COMPILE_I_EXPR_VAL " = %s;\n" - "decltype (" COMPILE_I_EXPR_VAL ") *" COMPILE_I_EXPR_PTR_TYPE ";\n" + "decltype ( %s ) *" COMPILE_I_EXPR_PTR_TYPE ";\n" "std::memcpy (" COMPILE_I_PRINT_OUT_ARG ", %s (" COMPILE_I_EXPR_VAL "),\n" - "sizeof (" COMPILE_I_EXPR_VAL "));\n" - ,input, + "sizeof (decltype(%s)));\n" + ,input, input, (type == COMPILE_I_PRINT_ADDRESS_SCOPE - ? "std::__addressof" : "")); + ? "std::__addressof" : ""), input); break; default: diff --git a/gdb/testsuite/gdb.compile/cp-simple-inherit.exp b/gdb/testsuite/gdb.compile/cp-simple-inherit.exp index 8293ccbe853..f4561bc09dd 100644 --- a/gdb/testsuite/gdb.compile/cp-simple-inherit.exp +++ b/gdb/testsuite/gdb.compile/cp-simple-inherit.exp @@ -1,4 +1,4 @@ -# Copyright 2015, 2016 Free Software Foundation, Inc. +# Copyright 2015, 2016, 2017 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -47,6 +47,6 @@ CompileExpression::test "d.a_" 1 CompileExpression::test "d.b_" 2 CompileExpression::test "d.c_" 3 CompileExpression::test "d.d_" 4 -CompileExpression::test "d.A::do_it (1);" 2 -CompileExpression::test "d.B::do_it (1);" 1 -CompileExpression::test "d.C::do_it (1);" 3 +CompileExpression::test "d.A::do_it (1)" 2 +CompileExpression::test "d.B::do_it (1)" 1 +CompileExpression::test "d.C::do_it (1)" 3 diff --git a/gdb/testsuite/gdb.compile/cp-simple-method.exp b/gdb/testsuite/gdb.compile/cp-simple-method.exp index 9387c8fb980..506dca605bd 100644 --- a/gdb/testsuite/gdb.compile/cp-simple-method.exp +++ b/gdb/testsuite/gdb.compile/cp-simple-method.exp @@ -1,4 +1,4 @@ -# Copyright 2015-2016 Free Software Foundation, Inc. +# Copyright 2015-2017 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -43,20 +43,20 @@ gdb_breakpoint [gdb_get_line_number "break here" $srcfile] gdb_continue_to_breakpoint "testing location" CompileExpression::new "var" -CompileExpression::test "a->get_var ();" 21 -CompileExpression::test "a->get_var (static_cast (1));" 100 -CompileExpression::test "a->get_var (static_cast (1));" 101 -CompileExpression::test "a->get_var (static_cast (1));" 102 -CompileExpression::test "a->get_var (static_cast (a));" 103 -CompileExpression::test "a->get_var (*a);" 104 -CompileExpression::test "a->get_var (*ac);" 105 -CompileExpression::test "a->get_var1 (1);" 42 -CompileExpression::test "a->get_var2 (1, 2);" 88 -CompileExpression::test "A::get_1 (1);" 2 -CompileExpression::test "A::get_2 (1, 2);" 5 -CompileExpression::test "A::get_1 (a->get_var ());" 22 -CompileExpression::test "a->get_var1 (a->get_var () - 16);" 672 -CompileExpression::test "a->get_var2 (a->get_var (), A::get_1 (2));" 336 +CompileExpression::test "a->get_var ()" 21 +CompileExpression::test "a->get_var (static_cast (1))" 100 +CompileExpression::test "a->get_var (static_cast (1))" 101 +CompileExpression::test "a->get_var (static_cast (1))" 102 +CompileExpression::test "a->get_var (static_cast (a))" 103 +CompileExpression::test "a->get_var (*a)" 104 +CompileExpression::test "a->get_var (*ac)" 105 +CompileExpression::test "a->get_var1 (1)" 42 +CompileExpression::test "a->get_var2 (1, 2)" 88 +CompileExpression::test "A::get_1 (1)" 2 +CompileExpression::test "A::get_2 (1, 2)" 5 +CompileExpression::test "A::get_1 (a->get_var ())" 22 +CompileExpression::test "a->get_var1 (a->get_var () - 16)" 672 +CompileExpression::test "a->get_var2 (a->get_var (), A::get_1 (2))" 336 CompileExpression::test "get_value ()" 200 CompileExpression::test "get_value (a)" 21 CompileExpression::test "get_value (get_value ())" 200 diff --git a/gdb/testsuite/gdb.compile/cp-simple-ns.exp b/gdb/testsuite/gdb.compile/cp-simple-ns.exp index 0c5ff1d0e7f..216621bd136 100644 --- a/gdb/testsuite/gdb.compile/cp-simple-ns.exp +++ b/gdb/testsuite/gdb.compile/cp-simple-ns.exp @@ -1,4 +1,4 @@ -# Copyright 2015, 2016 Free Software Foundation, Inc. +# Copyright 2015, 2016, 2017 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -41,8 +41,8 @@ gdb_breakpoint [gdb_get_line_number "break here" $srcfile] gdb_continue_to_breakpoint "testing location" CompileExpression::new "var" -CompileExpression::test "N1::N2::N3::N4::n4static;" 400 -CompileExpression::test "N1::N2::N3::N4::S4::s4static;" 40 -CompileExpression::test "s.s4int_;" 4 -CompileExpression::test "N1::N2::N3::N4::S4::get_svar ();" 40 -CompileExpression::test "s.get_var ();" 4 +CompileExpression::test "N1::N2::N3::N4::n4static" 400 +CompileExpression::test "N1::N2::N3::N4::S4::s4static" 40 +CompileExpression::test "s.s4int_" 4 +CompileExpression::test "N1::N2::N3::N4::S4::get_svar ()" 40 +CompileExpression::test "s.get_var ()" 4