[1/3] gdb/testsuite: fix XPASSes when testing with clang

Message ID 20240502182549.1607075-2-blarsen@redhat.com
State New
Headers
Series clang inspired testsuite fixups. |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Guinevere Larsen May 2, 2024, 6:25 p.m. UTC
  Clang used to not add access specifiers for typedefs, and the tests
gdb.cp/ptype-flags.exp and gdb.cp/classes.exp both set XFAILs if clang
is being used to test. This was fixed on the clang 16.0.0 release,
generating many XPASSes. This current commit checks the clang version
used for testing, and only emits XFAIL on when a bad clang version is
used.

The testsuite didn't have a good way to check if a compiler is newer
than a given release, so this commit also adds a naive function that
does that, by assuming that major numbers trump the middle, which
trump the minor number.
---
 gdb/testsuite/gdb.cp/classes.exp     | 16 ++++++-----
 gdb/testsuite/gdb.cp/ptype-flags.exp | 11 ++++---
 gdb/testsuite/lib/gdb.exp            | 43 ++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 13 deletions(-)
  

Patch

diff --git a/gdb/testsuite/gdb.cp/classes.exp b/gdb/testsuite/gdb.cp/classes.exp
index 97dca292796..53a8ef1f1d2 100644
--- a/gdb/testsuite/gdb.cp/classes.exp
+++ b/gdb/testsuite/gdb.cp/classes.exp
@@ -25,9 +25,11 @@  load_lib "cp-support.exp"
 standard_testfile .cc
 
 set flags [list debug c++]
-set clang_used false
+set using_broken_clang false
 if { [test_compiler_info "clang-*" "c++"] } {
-    set clang_used true
+    if { [compiler_version_lower_than "16-0-0" "clang" "c++"] } {
+	set using_broken_clang true
+    }
     if { [gcc_major_version "clang-*" "c++"] >= 11} {
 	lappend flags additional_flags=-Wno-non-c-typedef-for-linkage
     }
@@ -330,7 +332,7 @@  proc test_ptype_class_objects {} {
 
     # Clang does not add access information for typedefs in classes.
     # More information on: https://github.com/llvm/llvm-project/issues/57608
-    if {$::clang_used} {
+    if {$::using_broken_clang} {
 	setup_xfail "clang 57608" *-*-*
     }
 
@@ -354,7 +356,7 @@  proc test_ptype_class_objects {} {
 	    { typedef private "typedef int private_int;" }
 	}
 
-    if {$::clang_used} {
+    if {$::using_broken_clang} {
 	setup_xfail "clang 57608" *-*-*
     }
 
@@ -366,7 +368,7 @@  proc test_ptype_class_objects {} {
 	    { typedef public "typedef int INT;" }
 	}
 
-    if {$::clang_used} {
+    if {$::using_broken_clang} {
 	setup_xfail "clang 57608" *-*-*
     }
 
@@ -378,7 +380,7 @@  proc test_ptype_class_objects {} {
 	    { typedef protected "typedef int INT;" }
 	}
 
-    if {$::clang_used} {
+    if {$::using_broken_clang} {
 	setup_xfail "clang 57608" *-*-*
     }
 
@@ -390,7 +392,7 @@  proc test_ptype_class_objects {} {
 	    { typedef protected "typedef int INT;" }
 	}
 
-    if {$::clang_used} {
+    if {$::using_broken_clang} {
 	setup_xfail "clang 57608" *-*-*
     }
 
diff --git a/gdb/testsuite/gdb.cp/ptype-flags.exp b/gdb/testsuite/gdb.cp/ptype-flags.exp
index bb92da6122a..8ac8e371fb2 100644
--- a/gdb/testsuite/gdb.cp/ptype-flags.exp
+++ b/gdb/testsuite/gdb.cp/ptype-flags.exp
@@ -29,10 +29,9 @@  if {![runto_main]} {
     return
 }
 
-if {[test_compiler_info {clang-*-*} c++]} {
-    set using_clang true
-} else {
-    set using_clang false
+set using_broken_clang false
+if {[compiler_version_lower_than "16-0-0" "clang" "c++"]} {
+    set using_broken_clang true
 }
 
 gdb_test_no_output "set language c++" ""
@@ -40,7 +39,7 @@  gdb_test_no_output "set width 0" ""
 
 proc do_check_holder {name {flags ""} {show_typedefs 1} {show_methods 1}
 		      {raw 0}} {
-    global using_clang
+    global using_broken_clang
 
     set contents {
 	{ base "public Base<T>" }
@@ -57,7 +56,7 @@  proc do_check_holder {name {flags ""} {show_typedefs 1} {show_methods 1}
     if {$show_typedefs} {
 	# Clang does not add accessibility information for typedefs:
 	# https://github.com/llvm/llvm-project/issues/57608
-	if {$using_clang} {
+	if {$using_broken_clang} {
 	    setup_xfail "clang 57608" *-*-*
 	}
 	lappend contents { typedef public "typedef Simple<Simple<T> > Z;" }
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index fe3f05c18df..67d5aef9343 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5001,6 +5001,49 @@  proc gcc_major_version { {compiler "gcc-*"} {language "c"} } {
     return $major.$minor
 }
 
+# Calculate if the compiler version is higer than VERSION.
+# If the proc can't tell (for instance, the provided compiler is clang
+# but the testssuite is running with gcc), it returns false.
+# VERSION must be in the form "0-0-0", with all 3 numbers.
+
+proc compiler_version_lower_than { version {compiler "gcc"} \
+				      {language "c"} } {
+    global decimal
+    
+    set res [regexp $compiler-($decimal)-($decimal)-($decimal) \
+		[test_compiler_info "" $language] dummy major mid minor]
+
+    regexp ($decimal)-($decimal)-($decimal) $version dummy \
+	prov_major prov_mid prov_minor
+    
+    # We either can't determine the compiler, or the compiler is
+    # different than provided
+    if { $res != 1} {
+	return false
+    }
+
+    if {$major != $prov_major} {
+	if {$major < $prov_major} {
+	    return true
+	} else {
+	    return false
+	}
+    }
+
+    if {$mid != $prov_mid} {
+	if {$mid < $prov_mid} {
+	    return true
+	} else {
+	    return false
+	}
+    }
+
+    if {$minor < $prov_mid} {
+	return true
+    }
+    return false
+}
+
 proc current_target_name { } {
     global target_info
     if [info exists target_info(target,name)] {