From 98a89b14ff34e87c4d48f7fee662eb2388534921 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 28 Oct 2025 17:30:03 -0600 Subject: [PATCH] Allow Python to create const+volatile types A user pointed out that the Python API can't create a type that is both const and volatile. The bug is that the calls to make_cv_type did not preserve the "other" flag. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33585 Reviewed-By: Tankut Baris Aktemur --- gdb/python/py-type.c | 8 ++++---- gdb/testsuite/gdb.python/py-type.exp | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 1251c1586a9..5a57df41a95 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -719,7 +719,7 @@ typy_const (PyObject *self, PyObject *args) try { - type = make_cv_type (1, 0, type, NULL); + type = make_cv_type (1, TYPE_VOLATILE (type), type, NULL); } catch (const gdb_exception &except) { @@ -737,7 +737,7 @@ typy_volatile (PyObject *self, PyObject *args) try { - type = make_cv_type (0, 1, type, NULL); + type = make_cv_type (TYPE_CONST (type), 1, type, NULL); } catch (const gdb_exception &except) { @@ -895,10 +895,10 @@ typy_lookup_type (struct demangle_component *demangled, rtype = lookup_pointer_type (type); break; case DEMANGLE_COMPONENT_CONST: - rtype = make_cv_type (1, 0, type, NULL); + rtype = make_cv_type (1, TYPE_VOLATILE (type), type, NULL); break; case DEMANGLE_COMPONENT_VOLATILE: - rtype = make_cv_type (0, 1, type, NULL); + rtype = make_cv_type (TYPE_CONST (type), 1, type, NULL); break; } } diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp index c32a5bdf947..7a64ed3b056 100644 --- a/gdb/testsuite/gdb.python/py-type.exp +++ b/gdb/testsuite/gdb.python/py-type.exp @@ -392,6 +392,12 @@ if { [build_inferior "${binfile}" "c"] == 0 } { test_type_equality test_type_identity } + + gdb_test "python print(gdb.lookup_type('int').const().volatile())" \ + "const volatile int" + gdb_test "python print(gdb.lookup_type('int').volatile().const())" \ + "const volatile int" \ + "volatile const int" } # Perform C++ Tests. -- 2.47.3