[v3,1/1] gdb, testsuite: Handle unused compiler option fdiagnostics-color=never.

Message ID 20240515203128.3186-1-abdul.b.ijaz@intel.com
State New
Headers
Series gdb, testsuite: Handle unused compiler option fdiagnostics-color=never. |

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

Abdul Basit Ijaz May 15, 2024, 8:31 p.m. UTC
  From: "Ijaz, Abdul B" <abdul.b.ijaz@intel.com>

The 'univeral_compile_options' in gdb.exp file only verifies the support
of '-fdiagnostics-color=never' for the "C" source file.  So while running
tests with assembly source file (.s), many of them are not able to run
on icx/clang compilers because '-fdiagnostics-color=never' option is not
supported.  This problem is not seen for the ".S" assembly source files so
these files are not handled separately.  After this change, this function
is split into multiple functions to check the support for different type
of sources individually.

Before this change, in the case of clang and ICX compiler, this error is
shown for assembly source files (.s):

'''
icx -fdiagnostics-color=never -Wno-unknown-warning-option -fno-pie -c -O0 -o
amd64-entry-value0.o gdb/testsuite/gdb.arch/amd64-entry-value.s (timeout = 300)

icx: warning: argument unused during compilation: '-fdiagnostics-color=never'
[-Wunused-command-line-argument]

gdb compile failed, icx: warning: argument unused during compilation:
'-fdiagnostics-color=never' [-Wunused-command-line-argument]

UNTESTED: gdb.arch/amd64-entry-value.exp: failed to prepare
'''

Similarly this error is shown for the clang compiler:

'''
clang  -fdiagnostics-color=never -Wno-unknown-warning-option -fno-pie -c -O0
-o amd64-entry-value0.o gdb/testsuite/gdb.arch/amd64-entry-value.s

clang: warning: argument unused during compilation:
 '-fdiagnostics-color=never' [-Wunused-command-line-argument]
'''
---
 gdb/testsuite/lib/gdb.exp | 54 +++++++++++++++++++++++++++++++--------
 1 file changed, 44 insertions(+), 10 deletions(-)
  

Comments

Tom Tromey May 16, 2024, 4:10 p.m. UTC | #1
>>>>> Abdul Basit Ijaz <abdul.b.ijaz@intel.com> writes:

> The 'univeral_compile_options' in gdb.exp file only verifies the support
> of '-fdiagnostics-color=never' for the "C" source file.  So while running
> tests with assembly source file (.s), many of them are not able to run
> on icx/clang compilers because '-fdiagnostics-color=never' option is not
> supported.

Thank you.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
  

Patch

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 0d78691c381..aea0ba599c7 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5046,17 +5046,9 @@  proc gdb_wrapper_init { args } {
 }
 
 # Determine options that we always want to pass to the compiler.
-gdb_caching_proc universal_compile_options {} {
-    set me "universal_compile_options"
+proc universal_compile_options {src obj} {
     set options {}
 
-    set src [standard_temp_file ccopts.c]
-    set obj [standard_temp_file ccopts.o]
-
-    gdb_produce_source $src {
-	int foo(void) { return 0; }
-    }
-
     # Try an option for disabling colored diagnostics.  Some compilers
     # yield colored diagnostics by default (when run from a tty) unless
     # such an option is specified.
@@ -5066,6 +5058,23 @@  gdb_caching_proc universal_compile_options {} {
 	# Seems to have worked; use the option.
 	lappend options $opt
     }
+
+    return $options
+}
+
+# Determine options that we always want to pass to the C compiler.
+gdb_caching_proc universal_compile_options_c {} {
+    set me "universal_compile_options_c"
+
+    set src [standard_temp_file ccopts.c]
+    set obj [standard_temp_file ccopts.o]
+
+    gdb_produce_source $src {
+	int foo(void) { return 0; }
+    }
+
+    set options [universal_compile_options $src $obj]
+
     file delete $src
     file delete $obj
 
@@ -5073,6 +5082,25 @@  gdb_caching_proc universal_compile_options {} {
     return $options
 }
 
+# Determine options that we always want to pass to the compiler for
+# assembly source files with the extension ".s".
+gdb_caching_proc universal_compile_options_assembly {} {
+    set me "universal_compile_options_assembly"
+
+    set src [standard_temp_file ccopts.s]
+    set obj [standard_temp_file csymbol.o]
+
+    gdb_produce_source $src {
+	main:
+    }
+
+    set options [universal_compile_options $src $obj]
+    file delete $obj
+
+    verbose "$me:  returning $options" 2
+    return $options
+}
+
 # Compile the code in $code to a file based on $name, using the flags
 # $compile_flag as well as debug, nowarning and quiet  (unless otherwise
 # specified in default_compile_flags).
@@ -5252,7 +5280,13 @@  proc gdb_compile {source dest type options} {
     if {[lsearch -exact $options rust] != -1} {
 	# -fdiagnostics-color is not a rustcc option.
     } else {
-	set new_options [universal_compile_options]
+	# icx/clang compilers support the -fdiagnostics-color option for
+	# ".S" files and only it is not supported for ".s" files.
+	if {[string match *.s $source] != 0} {
+	    set new_options [universal_compile_options_assembly]
+	} else {
+	    set new_options [universal_compile_options_c]
+	}
     }
 
     # C/C++ specific settings.