[PATCH v3] Don't compare types of enum fields
Simon Marchi
simon.marchi@polymtl.ca
Fri Dec 18 22:44:29 GMT 2020
On 2020-12-18 5:34 p.m., Hannes Domani via Gdb-patches wrote:
> Comparing types of enum fields results in a crash, because they don't
> have a type.
>
> It can be reproduced by comparing the types of 2 instances of the same
> enum type in different objects:
>
> enum.h:
> enum e
> {
> zero,
> one,
> };
>
> enum-1.c:
> int func();
> enum e e1;
> int main()
> {
> return e1 + func();
> }
>
> enum-2.c:
> enum e e2;
> int func()
> {
> return e2;
> }
Watch out, git has eaten the #include lines above, because it treats them
as comments (yeah, annoying). I suggest you indent the code with 4 spaces,
like this:
enum.h:
#include <foo>
blah blah blah
enum.c:
#include <bar>
blah blah blah
That makes the code visually easier to read and separate from the rest of the
text, it avoids git eating your #include lines, and it makes it so interfaces
that format the git commits as Markdown show the code with a monospace font.
So, three birds one stone.
The patch LGTM with this little fixup applied to the test:
diff --git a/gdb/testsuite/gdb.python/compare-enum-type.exp b/gdb/testsuite/gdb.python/compare-enum-type.exp
index 33df58b0089a..f05dcfe15b5a 100644
--- a/gdb/testsuite/gdb.python/compare-enum-type.exp
+++ b/gdb/testsuite/gdb.python/compare-enum-type.exp
@@ -15,7 +15,10 @@
# Test if enum type comparison succeeds (PR exp/27070).
-if {[prepare_for_testing "failed to prepare" "compare-enum-type" {compare-enum-type-a.c compare-enum-type-b.c}]} {
+standard_testfile -a.c -b.c
+
+if { [prepare_for_testing "failed to prepare" "compare-enum-type" \
+ [list $srcfile $srcfile2]] } {
return
}
More information about the Gdb-patches
mailing list