Bug 123553 - [patch] Prevent indent(1) from splitting unrecognized tokens
Summary: [patch] Prevent indent(1) from splitting unrecognized tokens
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 7.0-STABLE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-09 15:20 UTC by Romain Tartière
Modified: 2017-05-20 08:28 UTC (History)
1 user (show)

See Also:


Attachments
lexi.c.diff (1.98 KB, patch)
2008-05-09 15:20 UTC, Romain Tartière
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Romain Tartière 2008-05-09 15:20:04 UTC
When using indent(1) to indent source code, unrecognized tokens such as "0b00101010" are split (e.g. "0b 00101010").

Such constructs are however valid using avr-gcc from the ports, and upcoming releases of gcc will support this binary notation [1].

References:
  1. As noticed by Frank Behrens: http://lists.freebsd.org/pipermail/freebsd-hackers/2008-April/024343.html

Fix: The following patch attempt to detect numbers in different bases, assert it is valid, but avoid splitting tokens on unrecognized data:
How-To-Repeat: 
% echo "int x = 0b00101010 ;" > foo.c
% avr-gcc -c foo.c
% indent foo.c
% avr-gcc -c foo.c
foo.c:1: error: expected ',' or ';' before 'b00101010'
% cat foo.c
int             x = 0 b00101010;
Comment 1 Pedro F. Giffuni freebsd_committer freebsd_triage 2016-08-07 18:23:57 UTC
FWIW, Our base GCC 4.2 brought support for binary constants in r255107. Such constructs are used in Mesa.

With the patch as-is, indent would be able to break valid code as pointed out by Peter Jeremy in:

https://lists.freebsd.org/pipermail/freebsd-hackers/2008-April/024336.html

The fix doesn't look trivial.
Comment 2 commit-hook freebsd_committer freebsd_triage 2017-05-18 17:16:33 UTC
A commit references this bug:

Author: pstef
Date: Thu May 18 17:15:59 UTC 2017
New revision: 318471
URL: https://svnweb.freebsd.org/changeset/base/318471

Log:
  indent(1): Support binary integer literals.
  This was done by Romain Tarti?re for PR123553. I initially thought that it would break code like this:
  #define b00101010 -1
  if (0 b00101010)
  ...

  by joining 0 and b00101010 together. However, the real problem with that patch was that once it saw a 0, it assumed that the number was base r2, 8 or 16, ignoring base r10 floating point numbers. I fixed that.

  I didn't copy the diagnostic part of the original patch as it seems out of scope of implementing binary integer literals formatting.

  PR:		123553
  Submitted by:	romain (original version)
  Approved by:	pfg (mentor)

Changes:
  head/usr.bin/indent/lexi.c
  head/usr.bin/indent/tests/Makefile
  head/usr.bin/indent/tests/binary.0
  head/usr.bin/indent/tests/binary.0.stdout
Comment 3 Piotr Pawel Stefaniak freebsd_committer freebsd_triage 2017-05-20 08:28:10 UTC
Committed as r318471.