diff mbox series

[1/2] Introduce dg-require-target-object-format

Message ID 1573060894-16490-2-git-send-email-egeyar.bagcioglu@oracle.com
State New
Headers show
Series Introduce a new GCC option, --record-gcc-command-line | expand

Commit Message

Egeyar Bagcioglu Nov. 6, 2019, 5:21 p.m. UTC
gcc/testsuite/ChangeLog:
2019-11-06  Egeyar Bagcioglu  <egeyar.bagcioglu@oracle.com>

        * lib/target-supports-dg.exp: Define dg-require-target-object-format.

---
 gcc/testsuite/lib/target-supports-dg.exp | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Segher Boessenkool Nov. 7, 2019, 7:47 a.m. UTC | #1
Hi!

On Wed, Nov 06, 2019 at 06:21:33PM +0100, Egeyar Bagcioglu wrote:
> gcc/testsuite/ChangeLog:
> 2019-11-06  Egeyar Bagcioglu  <egeyar.bagcioglu@oracle.com>
> 
>         * lib/target-supports-dg.exp: Define dg-require-target-object-format.

* lib/target-supports-dg.exp (dg-require-target-object-format): New.

> +proc dg-require-target-object-format { args } {
> +    if { [gcc_target_object_format] == [lindex $args 1] } {
> +	return
> +    }

"==" for strings is dangerous.  Use "eq" or "string equal"?


Segher
Egeyar Bagcioglu Nov. 7, 2019, 4:30 p.m. UTC | #2
Hi Segher!


On 11/7/19 8:47 AM, Segher Boessenkool wrote:
> Hi!
>
> On Wed, Nov 06, 2019 at 06:21:33PM +0100, Egeyar Bagcioglu wrote:
>> gcc/testsuite/ChangeLog:
>> 2019-11-06  Egeyar Bagcioglu  <egeyar.bagcioglu@oracle.com>
>>
>>          * lib/target-supports-dg.exp: Define dg-require-target-object-format.
> * lib/target-supports-dg.exp (dg-require-target-object-format): New.

Right, thanks for the correction!

>> +proc dg-require-target-object-format { args } {
>> +    if { [gcc_target_object_format] == [lindex $args 1] } {
>> +	return
>> +    }
> "==" for strings is dangerous.  Use "eq" or "string equal"?

I see many "string match"es. I will make the change.

Just as a note, though: Why is it dangerous? In C, for example, this 
would be a pointer comparison and consistently fail. In many other 
languages, it is indeed a string comparison and works well.

I am asking also because I see "==" for variable vs literal strings in 
gcc/testsuite/lib. As opposed to C-like languages that consistently fail 
them, these seem to work. If you still think this is dangerous, I'd love 
to know why. Also, if so, someone might want to check the library.

Thanks for the review!

Egeyar
Jose E. Marchesi Nov. 7, 2019, 5:17 p.m. UTC | #3
On 11/7/19 8:47 AM, Segher Boessenkool wrote:
    > Hi!
    >
    > On Wed, Nov 06, 2019 at 06:21:33PM +0100, Egeyar Bagcioglu wrote:
    >> gcc/testsuite/ChangeLog:
    >> 2019-11-06  Egeyar Bagcioglu  <egeyar.bagcioglu@oracle.com>
    >>
    >>          * lib/target-supports-dg.exp: Define dg-require-target-object-format.
    > * lib/target-supports-dg.exp (dg-require-target-object-format): New.
    
    Right, thanks for the correction!
    
    >> +proc dg-require-target-object-format { args } {
    >> +    if { [gcc_target_object_format] == [lindex $args 1] } {
    >> +	return
    >> +    }
    > "==" for strings is dangerous.  Use "eq" or "string equal"?
    
    I see many "string match"es. I will make the change.
    
    Just as a note, though: Why is it dangerous? In C, for example, this
    would be a pointer comparison and consistently fail. In many other
    languages, it is indeed a string comparison and works well.
    
    I am asking also because I see "==" for variable vs literal strings in
    gcc/testsuite/lib. As opposed to C-like languages that consistently
    fail them, these seem to work. If you still think this is dangerous,
    I'd love to know why. Also, if so, someone might want to check the
    library.

Because if the string happens to look like a number Tcl will perform
arithmetic comparison instead of lexicographic comparison, i.e. "01" ==
"1" evaluates to true :)
Egeyar Bagcioglu Nov. 7, 2019, 5:20 p.m. UTC | #4
On 11/7/19 6:17 PM, jose.marchesi@oracle.com wrote:
>      
>      On 11/7/19 8:47 AM, Segher Boessenkool wrote:
>      > Hi!
>      >
>      > On Wed, Nov 06, 2019 at 06:21:33PM +0100, Egeyar Bagcioglu wrote:
>      >> gcc/testsuite/ChangeLog:
>      >> 2019-11-06  Egeyar Bagcioglu  <egeyar.bagcioglu@oracle.com>
>      >>
>      >>          * lib/target-supports-dg.exp: Define dg-require-target-object-format.
>      > * lib/target-supports-dg.exp (dg-require-target-object-format): New.
>      
>      Right, thanks for the correction!
>      
>      >> +proc dg-require-target-object-format { args } {
>      >> +    if { [gcc_target_object_format] == [lindex $args 1] } {
>      >> +	return
>      >> +    }
>      > "==" for strings is dangerous.  Use "eq" or "string equal"?
>      
>      I see many "string match"es. I will make the change.
>      
>      Just as a note, though: Why is it dangerous? In C, for example, this
>      would be a pointer comparison and consistently fail. In many other
>      languages, it is indeed a string comparison and works well.
>      
>      I am asking also because I see "==" for variable vs literal strings in
>      gcc/testsuite/lib. As opposed to C-like languages that consistently
>      fail them, these seem to work. If you still think this is dangerous,
>      I'd love to know why. Also, if so, someone might want to check the
>      library.
>
> Because if the string happens to look like a number Tcl will perform
> arithmetic comparison instead of lexicographic comparison, i.e. "01" ==
> "1" evaluates to true :)

Oh lovely indeed! I am glad I asked.
Thanks Jose!
Hans-Peter Nilsson Nov. 14, 2019, 2:51 a.m. UTC | #5
On Thu, 7 Nov 2019, Egeyar Bagcioglu wrote:
> On 11/7/19 8:47 AM, Segher Boessenkool wrote:
> > On Wed, Nov 06, 2019 at 06:21:33PM +0100, Egeyar Bagcioglu wrote:
> > > +proc dg-require-target-object-format { args } {
> > > +    if { [gcc_target_object_format] == [lindex $args 1] } {
> > > +	return
> > > +    }
> > "==" for strings is dangerous.  Use "eq" or "string equal"?
>
> I see many "string match"es. I will make the change.

Please instead use "string equal".

Code in target-supports-dg.exp is not a trustworthy reference.
I suggest RTFM <http://www.tcl.tk/>, where you can see that
"string match" does a glob compare.

brgds, H-P
Egeyar Bagcioglu Nov. 18, 2019, 7:41 p.m. UTC | #6
On 11/14/19 3:51 AM, Hans-Peter Nilsson wrote:
> On Thu, 7 Nov 2019, Egeyar Bagcioglu wrote:
>> On 11/7/19 8:47 AM, Segher Boessenkool wrote:
>>> On Wed, Nov 06, 2019 at 06:21:33PM +0100, Egeyar Bagcioglu wrote:
>>>> +proc dg-require-target-object-format { args } {
>>>> +    if { [gcc_target_object_format] == [lindex $args 1] } {
>>>> +	return
>>>> +    }
>>> "==" for strings is dangerous.  Use "eq" or "string equal"?
>> I see many "string match"es. I will make the change.
> Please instead use "string equal".
>
> Code in target-supports-dg.exp is not a trustworthy reference.
> I suggest RTFM <http://www.tcl.tk/>, where you can see that
> "string match" does a glob compare.
>
> brgds, H-P

I added the change to my local copy. Thanks for the correction and for 
the reasoning.

Regards
Egeyar
diff mbox series

Patch

diff --git a/gcc/testsuite/lib/target-supports-dg.exp b/gcc/testsuite/lib/target-supports-dg.exp
index e1da57a..e923754 100644
--- a/gcc/testsuite/lib/target-supports-dg.exp
+++ b/gcc/testsuite/lib/target-supports-dg.exp
@@ -164,6 +164,17 @@  proc dg-require-dll { args } {
     set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
 }
 
+# If this target does not produce the given object format skip this test.
+
+proc dg-require-target-object-format { args } {
+    if { [gcc_target_object_format] == [lindex $args 1] } {
+	return
+    }
+
+    upvar dg-do-what dg-do-what
+    set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+}
+
 # If this host does not support an ASCII locale, skip this test.
 
 proc dg-require-ascii-locale { args } {