Bug 28079 - #line range not verified without -pedantic
Summary: #line range not verified without -pedantic
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2006-06-19 05:52 UTC by Chris Lattner
Modified: 2008-07-22 09:48 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-05-13 19:52:30


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2006-06-19 05:52:44 UTC
Preprocessing this:
#line 12312312312435

produces:

# 2936042099 ".../foo.c"

C99 specifies that the argument to #line shall be > 0 and < 2^31-1, and even if it didn't, truncation like this should at least be warned about.

-Chris
Comment 1 Andrew Pinski 2006-06-21 05:07:59 UTC
[kudzu:~] pinskia% gcc t.c -pedantic-errors -std=c99
t.c:1:7: error: line number out of range
t.c:-1358925197: error: ISO C forbids an empty source file

With -pedantic we just get a warning.

I don't know if we should warn even with -pedantic.
Comment 2 Manuel López-Ibáñez 2008-02-10 15:52:46 UTC
Tom, as the libcpp maintainer, could you give your opinion about this? I personally think a warning could be useful, it may point out some bug in an auto-generated file. Moreover, I think that the standard also require us to warn (with -pedantic) for the wrapping case.
Comment 3 Manuel López-Ibáñez 2008-02-10 16:12:32 UTC
Also, I noticed that there is an implicit conversion from ulong to uint when calling _cpp_do_file_change in do_linemarker. That is the point where the truncation takes place.
Comment 4 Tom Tromey 2008-02-25 21:10:33 UTC
Sorry for the delay on this.

I never remember our rules about when to emit pedantic warnings
and the like.  I think libcpp should follow the overall gcc approach
here, whatever that is.

I agree that warning about truncation is a good idea.
Silently doing the wrong thing is unfriendly.
Comment 5 Tom Tromey 2008-05-13 19:52:30 UTC
I don't see why this should be marked "wait".
Changing back to "new".
Comment 6 Manuel López-Ibáñez 2008-07-22 09:46:43 UTC
Subject: Bug 28079

Author: manu
Date: Tue Jul 22 09:45:58 2008
New Revision: 138049

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=138049
Log:
2008-07-22  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR 28079
libcpp/
	* directives.c (strtolinenum): Handle overflow.
	(do_line): Give a warning if line number overflowed.
	(do_linemarker): Update call to strtolinenum.

gcc/testsuite/
	* gcc.dg/cpp/line6.c: New.

Added:
    trunk/gcc/testsuite/gcc.dg/cpp/line6.c
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/libcpp/ChangeLog
    trunk/libcpp/directives.c

Comment 7 Manuel López-Ibáñez 2008-07-22 09:48:13 UTC
Fixed in GCC 4.4