]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Allow Python to create const+volatile types
authorTom Tromey <tom@tromey.com>
Tue, 28 Oct 2025 23:30:03 +0000 (17:30 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 11 Nov 2025 21:40:03 +0000 (14:40 -0700)
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 <tankut.baris.aktemur@intel.com>
gdb/python/py-type.c
gdb/testsuite/gdb.python/py-type.exp

index 1251c1586a9be1dc6823e6fbce94e5cca3d0056f..5a57df41a954e7cb67c42191f8584d6561d1b1dc 100644 (file)
@@ -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;
            }
        }
index c32a5bdf947b5e18d3e0968d3749c45a9240ba55..7a64ed3b0566029f9e47431812e99a2a14bf8c2b 100644 (file)
@@ -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.