wood@DG-RTP.DG.COM (Tom Wood) (01/19/90)
Enclosed is a set of tests and patches that deal with unterminated strings
and character constants in the preprocessor under traditional mode. I've
used the i386 cc (V.3 rcc) and the sun cc to validate the appropriate output.
These patches apply to 1.36.92.
# This is a shell archive.
# Remove everything above and including the cut line.
# Then run the rest of the file through sh.
-----cut here-----cut here-----cut here-----cut here-----
#!/bin/sh
# shar: Shell Archiver
# Run the following text with /bin/sh to create:
# 446.c Input
# 150.c Input
# Traditional-150.1 cpp -traditional 150.c
# Traditional-446F.1 cpp -traditional 446.c
# Traditional-446T.1 cpp -traditional -DT 446.c
# This archive created: Thu Jan 18 10:07:06 EST 1990
echo x - 446.c
cat << \SHAR_EOF > 446.c
/*
* Traditional preprocess test. Works with and wihout -DT
*/
#ifndef T
Do comments work on #endif? yes /*
#endif
*/
#endif
End first block.
#ifndef T
Are character constants processed? '/*' yes
#endif
End second block
#ifndef T
Are valid strings processed? "yes /* "
#endif
End third block.
#ifndef T
Are bad char constants taken? 'yep
Are bad strings taken? " (ditto)
#endif
End fourth block.
#ifndef T
Do bad char constants hide comments? 'yep /*
Are bad strings hide comments? " (ditto) /*
#endif
End fifth block.
#include "/dev/null"
SHAR_EOF
echo x - 150.c
cat << \SHAR_EOF > 150.c
#ifndef LIBDIR
#define LIBDIR "/usr/local/lib/xtrek
#endif /* LIBDIR */
#ifndef FONTDIR
#define FONTDIR LIBDIR"
#endif /* FONTDIR */
#define PFILE LIBDIR/.planets"
SHAR_EOF
echo x - Traditional-150.1
cat << \SHAR_EOF > Traditional-150.1
# 1 "../tests/150.c"
SHAR_EOF
echo x - Traditional-446F.1
cat << \SHAR_EOF > Traditional-446F.1
# 1 "../tests/446.c"
Do comments work on #endif? yes
End first block.
Are character constants processed? '/*' yes
End second block
Are valid strings processed? "yes /* "
End third block.
Are bad char constants taken? 'yep
Are bad strings taken? " (ditto)
End fourth block.
Do bad char constants hide comments? 'yep /*
Are bad strings hide comments? " (ditto) /*
End fifth block.
# 1 "/dev/null" 1
# 38 "../tests/446.c" 2
SHAR_EOF
echo x - Traditional-446T.1
cat << \SHAR_EOF > Traditional-446T.1
# 1 "../tests/446.c"
End first block.
End second block
End third block.
End fourth block.
End fifth block.
# 1 "/dev/null" 1
# 38 "../tests/446.c" 2
SHAR_EOF
# End of shell archive
exit 0
This patch fixes the output from
cpp -traditional 446.c Traditional-446F.1
*** cccp.c.orig Thu Jan 18 08:35:12 1990
--- cccp.c Thu Jan 18 08:59:21 1990
***************
*** 1453,1460 ****
case '\n':
++ip->lineno;
++op->lineno;
! if (traditional)
goto while2end;
if (pedantic || c == '\'') {
error_with_line (line_for_error (start_line),
"unterminated string or character constant");
--- 1453,1463 ----
case '\n':
++ip->lineno;
++op->lineno;
! if (traditional) {
! /* Terminate the string at the newline and announce the newline. */
! beg_of_line = ibp;
goto while2end;
+ }
if (pedantic || c == '\'') {
error_with_line (line_for_error (start_line),
"unterminated string or character constant");
This patch fixes the output from
cpp -traditional -DT 446.c Traditional-446T.1
The first patch avoids a regression in 150.c
*** cccp.c.orig Thu Jan 18 09:39:08 1990
--- cccp.c Thu Jan 18 09:46:01 1990
***************
*** 2141,2147 ****
if (unterminated) {
if (traditional) {
/* Traditional preprocessing permits unterminated strings. */
! --bp;
ip->bufp = bp;
goto endloop1;
}
--- 2141,2147 ----
if (unterminated) {
if (traditional) {
/* Traditional preprocessing permits unterminated strings. */
! /* --bp; This leaves the last character as output. */
ip->bufp = bp;
goto endloop1;
}
***************
*** 4020,4025 ****
--- 4020,4032 ----
}
bp++;
} else if (c == '\n') {
+ if (traditional) {
+ /* Unterminated strings and character constants are 'legal'. */
+ bp--; /* Don't consume the newline. */
+ if (eofp)
+ *eofp = 1;
+ break;
+ }
if (match == '\'') {
error_with_line (line_for_error (start_line),
"unterminated character constant");