NetBSD Problem Report #30967

From dholland@eecs.harvard.edu  Wed Aug 10 23:21:37 2005
Return-Path: <dholland@eecs.harvard.edu>
Received: from tanaqui.eecs.harvard.edu (tanaqui.eecs.harvard.edu [140.247.60.239])
	by narn.netbsd.org (Postfix) with ESMTP id 61D8163B104
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 10 Aug 2005 23:21:37 +0000 (UTC)
Message-Id: <20050810231929.2A53AFBC4@tanaqui.eecs.harvard.edu>
Date: Wed, 10 Aug 2005 19:19:29 -0400 (EDT)
From: dholland@eecs.harvard.edu
Reply-To: dholland@eecs.harvard.edu
To: gnats-bugs@netbsd.org
Subject: obscure corner-case bug in conditional handling in make
X-Send-Pr-Version: 3.95

>Number:         30967
>Category:       bin
>Synopsis:       obscure corner-case bug in conditional handling in make
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Aug 10 23:22:00 +0000 2005
>Closed-Date:    Sun Dec 21 21:07:12 +0000 2008
>Last-Modified:  Sun Dec 21 21:10:02 +0000 2008
>Originator:     David A. Holland / dholland@eecs.harvard.edu
>Release:        NetBSD 3.99.7 (-20050718)
>Organization:
    Harvard EECS
>Environment:
System: NetBSD tanaqui 3.99.7 NetBSD 3.99.7 (TANAQUI) #1: Mon Jul 18 21:43:19 EDT 2005 dholland@tanaqui:/usr/src/sys/arch/i386/compile/TANAQUI i386
Architecture: i386
Machine: i386
>Description:

Conditionals of the form ".if A==A",  appear to be always false. This is
less than totally desirable behavior on the face of it, but also seems
to reflect a bug.

".if A!=A" is always false too.

The behavior when an unrecognized word appears in a conditional
expression is to run a default function on it. In the case of .if this
function is "defined". (*)

However, whether or not A is defined, applying defined() to both As
should still give an expression that's true -- either 0==0 or 1==1.
And any ordinary (even if wrong/unexpected) evaluation path should
still give opposite results for "A==A" and "A!=A", which isn't
happening.

It's not immediately clear to me what's going on, but something's
definitely wrong, probably in the parsing logic.


(*) This is not documented in the man page, either, which only
discusses this behavior in connection with .if(n)def and
.if(n)make. Patch below.

Alternatively, one could make unrecognized words in .if expressions
errors.

It's also not clear that sharing expression syntax between .if and
.ifdef is a good idea in the first place. I don't think it really
makes sense to allow
	.ifdef "$(A)"=="$(B)"
and have it behave the same as .if. But this is a different issue.

>How-To-Repeat:

Try the following makefile fragment. (Removing the assignment of A
doesn't change the behavior.)

A=6
foo:
.if A==A
	echo YES
.else
	echo NO
.endif

>Fix:

Fix for the man page (also includes a typo fix):

Index: make.1
===================================================================
RCS file: /cvsroot/src/usr.bin/make/make.1,v
retrieving revision 1.118
diff -u -r1.118 make.1
--- make.1	27 Jun 2005 09:51:09 -0000	1.118
+++ make.1	10 Aug 2005 22:38:49 -0000
@@ -1278,13 +1278,14 @@
 .Pp
 When
 .Nm
-is evaluating one of these conditional expression, and it encounters
+is evaluating one of these conditional expressions, and it encounters
 a word it doesn't recognize, either the ``make'' or ``defined''
 expression is applied to it, depending on the form of the conditional.
 If the form is
 .Ql Ic .ifdef
-or
 .Ql Ic .ifndef ,
+or
+.Ql Ic .if ,
 the ``defined'' expression
 is applied.
 Similarly, if the form is

>Release-Note:

>Audit-Trail:
From: David Laight <david@l8s.co.uk>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/30967 (obscure corner-case bug in conditional handling in make)
Date: Sat, 29 Nov 2008 15:03:43 +0000

 I've change make (cond.c 1.48) to treat .if A == A as a comparison.
 Without the whitespace it is all too hard!
 Makefile syntax rules are not well thought out.

 	David

 -- 
 David Laight: david@l8s.co.uk

State-Changed-From-To: open->closed
State-Changed-By: dsl@NetBSD.org
State-Changed-When: Sun, 21 Dec 2008 21:07:12 +0000
State-Changed-Why:
.if A==A is .if defined(A==A) and always will be!
make.1 updated as suggested.


From: David Laight <dsl@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/30967 CVS commit: src/usr.bin/make
Date: Sun, 21 Dec 2008 21:05:27 +0000 (UTC)

 Module Name:	src
 Committed By:	dsl
 Date:		Sun Dec 21 21:05:27 UTC 2008

 Modified Files:
 	src/usr.bin/make: make.1

 Log Message:
 Note that an unrecognised word in a .if is the same as in .ifdef and that
 such a word has to be white-space separated.
 From PR bin/30967 bin/37222 and maybe others!


 To generate a diff of this commit:
 cvs rdiff -r1.149 -r1.150 src/usr.bin/make/make.1

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.