]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Pass alignment when using GCC_C_FE_VERSION_2
authorTom Tromey <tom@tromey.com>
Wed, 21 Feb 2024 15:22:01 +0000 (08:22 -0700)
committerTom Tromey <tom@tromey.com>
Thu, 14 Mar 2024 15:13:53 +0000 (09:13 -0600)
When the GCC compiler plugin responds with GCC_C_FE_VERSION_2, gdb can
use the new 'finish_record_with_alignment' method.  This lets gdb pass
alignment information to the compiler, which in turn fixes the test
case included in this patch.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31397

gdb/compile/compile-c-types.c
gdb/testsuite/gdb.compile/compile.c
gdb/testsuite/gdb.compile/compile.exp

index 1bfaefc4933ed14707fdf0117c7ed55c844063a7..1243be369f83da56ca24994d458c1044906e487c 100644 (file)
@@ -118,7 +118,11 @@ convert_struct_or_union (compile_c_instance *context, struct type *type)
                                          type->field (i).loc_bitpos ());
     }
 
-  context->plugin ().finish_record_or_union (result, type->length ());
+  if (context->plugin ().version () >= GCC_C_FE_VERSION_2)
+    context->plugin ().finish_record_with_alignment (result, type->length (),
+                                                    type_align (type));
+  else
+    context->plugin ().finish_record_or_union (result, type->length ());
   return result;
 }
 
index 8170a3af5ab85c104a016ec774905c21fb228f71..04beae823c800c122e836d76bd8c2599d2aaf482 100644 (file)
@@ -100,6 +100,13 @@ int globalshadow = 10;
 static int staticshadow = 20;
 int externed = 7;
 
+struct struct_with_array
+{
+  char val[7];
+};
+
+static struct struct_with_array swa;
+
 int
 main (void)
 {
index fed7b04a4c3f3e8ad8593e2defd1822acea50248..f522a84d5dde8b86fdb10eacaf7fdc044deb1ab9 100644 (file)
@@ -397,3 +397,6 @@ gdb_test "p globalvar" " = 1" "expect 1"
 
 gdb_test_no_output "compile code shlibvar += 5;" "modify shared library variable"
 gdb_test "p shlibvar" " = 15" "expect 15"
+
+# This used to fail due to alignment.  PR compile/31397.
+gdb_test_no_output "compile code swa.val\[0\] = 1"