Bug 19423 - __int128 conversion towards "const __int128 &" should be allowed
Summary: __int128 conversion towards "const __int128 &" should be allowed
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 7.10
: P2 enhancement
Target Milestone: 15.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 20991
  Show dependency treegraph
 
Reported: 2016-01-02 19:33 UTC by Claude
Modified: 2024-03-20 17:26 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Claude 2016-01-02 19:33:42 UTC
If a method has an argument of type "const __int128 &", then calling it with an argument of type __int128 produces the error:

  That operation is not available on integers of more than 8 bytes.

I understand that integer expressions (except direct printing) are limited to 64 bits integers at most, but converting an __int128 towards a constant __int128 reference should be allowed.

Copy-pasted example:

(gdb) ptype ::my_function
type = void (const __int128 &)
(gdb) ptype working_argument
type = const __int128 &
(gdb) ptype broken_argument
type = __int128
(gdb) call ::my_function(working_argument)
....XX....
...XXX...X
...XXX...X
.XXX.XXXXX
..X..XX.X.
...XX.XX..
....XXX.X.
.....XX...
...XX..X..
...XXXXXX.
(gdb) call ::my_function(broken_argument)
That operation is not available on integers of more than 8 bytes.
Comment 1 Sourceware Commits 2024-03-20 17:25:24 UTC
The master branch has been updated by Hannes Domani <ssbssa@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d391f3721e20d160909a3afae7fee647ea5575a2

commit d391f3721e20d160909a3afae7fee647ea5575a2
Author: Hannes Domani <ssbssa@yahoo.de>
Date:   Wed Mar 20 18:23:40 2024 +0100

    Fix casting in-memory values of primitive types to const reference
    
    It's currently not possible to cast an in-memory value of a primitive
    type to const reference:
    ```
    (gdb) p Q.id
    $1 = 42
    (gdb) p (int&)Q.id
    $2 = (int &) @0x22fd0c: 42
    (gdb) p (const int&)Q.id
    Attempt to take address of value not located in memory.
    ```
    
    And if in a function call an argument needs the same kind of casting,
    it also doesn't work:
    ```
    (gdb) l f3
    39      int f3(const int &i)
    40      {
    41        return i;
    42      }
    (gdb) p f3(Q.id)
    Attempt to take address of value not located in memory.
    ```
    
    It's because when the constness of the type changes in a call to
    value_cast, a new not_lval value is allocated, which doesn't exist
    in the target memory.
    
    Fixed by ignoring const/volatile/restrict qualifications in
    value_cast when comparing cast type to original type, so the new
    value will point to the same location as the original value:
    ```
    (gdb) p (int&)i
    $2 = (int &) @0x39f72c: 1
    (gdb) p (const int&)i
    $3 = (const int &) @0x39f72c: 1
    (gdb) p f3(Q.id)
    $4 = 42
    ```
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19423
    Approved-By: Tom Tromey <tom@tromey.com>
Comment 2 Hannes Domani 2024-03-20 17:26:38 UTC
Fixed.