Skip to content

Commit 2718a72

Browse files
committed
Fix incorrect line number reporting for long assertions in error messages
Removes incorrect line number decrement after processing preprocessor line directives in `scanner.l`. The `preprocessor_line()` function already sets the correct line number, and the subsequent decrement was causing off-by-one errors in line reporting for long expressions. Fixes: #8257
1 parent 4fe3ade commit 2718a72

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#define __CBMC_assert(cond) \
2+
__CPROVER_assert((cond), "assertion"); \
3+
__CPROVER_assume(cond)
4+
extern int __VERIFIER_nondet_int();
5+
int main()
6+
{
7+
int A[1];
8+
A[0] = __VERIFIER_nondet_int();
9+
/* clang-format off */
10+
__CBMC_assert((A[0] < (-1) && A[0] < ~(4294967294U) && A[0] < 0LL && (A[0] > -214748647LL && ((((A[0] < 20158765) && A[0] > 2147483648U && A[0] > 1929301145 && (A[0] > 1944729020 && A[0] < 0 && A[0] < -1LL && A[0] > 4294967294ULL && A[0] != ~(2147483647U)) && A[0] > ~(4294967294U) && A[0] < ~(4294967295U))) && (A[0] > ~(2147483646U) && (A[0] < 1L && A[0] > 1ULL && A[0] > 1LL && A[0] < ~(-1) && A[0] < 2147483647ULL) && (A[0] < 0U) && (A[0] < 2147483647L && (A[0] < 0U && (A[0] < 1UL)) && (((A[0] > ~(0U) || A[0] < ~(1U)) || A[0] > 1321734560)) && A[0] < 4294967294ULL) && (A[0] < 1UL && ((A[0] > 2147483646U && A[0] <= 1U) && A[0] < 1U) && A[0] > 1U) && A[0] > 1ULL) && A[0] > 1L && (A[0] < 4294967295UL && A[0] < 4294967294UL && A[0] < 1L && (A[0] > ~(2147483647) && A[0] < 2147483647UL && A[0] < 2147483647L && A[0] < 0U) && ((A[0] > ~(1) && (A[0] > 1UL) && (A[0] > 2147483648U) && A[0] <= 2147483647) && A[0] > 1L)) && (A[0] < 4294967294UL && A[0] < ~(4294967294U) && A[0] > -1453357121 && A[0] < 1U) && A[0] < 2147483646U && (A[0] > 1L && (((A[0] < 1UL)) && A[0] < ~(0) && A[0] != ~(-1)) && A[0] < 4294967294ULL) && (A[0] < ~(4294967295U)) && A[0] <= 2147483647LL) && ((A[0] < 0U && ((A[0] > ~(2147483646U) && ((A[0] < ~(-2147483647)) && A[0] > ~(0) && A[0] > -1 && A[0] < -1L && (A[0] < 2147483646LL && (A[0] < -1) && ((A[0] < 2))) && (A[0] < 2147483647L && (A[0] < 2147483646LL && A[0] < 4294967295U) && A[0] > ~(4294967294U))) && ((A[0] > ~(1U)) && ((A[0] < 1U && (A[0] < 0 && A[0] < 2147483647U && (A[0] > 4294967294ULL)) && (A[0] < 2147483647ULL || A[0] < ~(1)))) && A[0] < -1LL && (((A[0] > 4294967295ULL && (((A[0] > 2147483648ULL)) && A[0] >= 4294967295U)) && A[0] < 2147483646ULL && A[0] <= 0L))) && A[0] > 0U && ((A[0] > 552237804 && A[0] > 4294967294UL) && (((A[0] < 0L && (A[0] > -2147483648) && ((((((((A[0] > -2147483647))))) && A[0] >= -2147483648) || (A[0] <= ~(1) && (A[0] >= 4294967295UL))) && A[0] <= 2147483646LL)) && A[0] != 100000) || (A[0] < -1L)) && A[0] != 4294967294U))) && A[0] < 0 && A[0] > ~(1U) && A[0] > -62844098 && A[0] < ~(-2147483647) && A[0] > 0UL && A[0] < 1U && A[0] > 0) && (A[0] < ~(0) && (A[0] > 4294967295UL) && (A[0] < 0UL) && (A[0] > 1ULL && (A[0] > 1UL) && (A[0] > 2056281653) && A[0] < 4294967294UL) && A[0] > 4294967294U && A[0] > 4294967294U && (A[0] > -1) && A[0] <= ~(1U)) && A[0] < 2147483646L && (A[0] > ~(0U) && A[0] > -1LL && (A[0] > ~(2147483647)) && A[0] > -2147483647L && ((A[0] < -2147483648 && (A[0] >= ~(2147483646))))) && A[0] > 4294967295ULL && (A[0] > -2147483648L && (A[0] < ~(1) && A[0] < 2147483646LL) && A[0] > ~(-1)) && ((A[0] < 4294967295UL) || (((A[0] > 4294967295UL && (((A[0] < 0 && ((A[0] < 2147483646ULL) && ((A[0] < 1)))))) && A[0] > ~(0U) && (((A[0] >= -1)) && A[0] > -2147483648)) && A[0] < 2147483646ULL && A[0] != 0L))) && A[0] > 1UL) && A[0] > 4294967294ULL && (A[0] < 2147483646U && A[0] < -2147483647L && A[0] > -1485823147 && A[0] < 1U && A[0] > 1L && (((A[0] < 2147483647ULL && A[0] > 2147483646ULL)))) && A[0] < 4294967294UL && ((A[0] != 2147483647ULL || A[0] > 0))) && (A[0] < ~(1U) && (A[0] < 1ULL && (A[0] > ~(4294967295U) && A[0] > 1U && (A[0] > 2147483646U && A[0] > -1LL && A[0] > ~(1) && A[0] < 2147483646L && A[0] > 1UL && A[0] < 0 && A[0] < -1L && A[0] != ~(1)) && (((((A[0] > -2147483647LL) && A[0] < 1L && (A[0] > -2147483648L) && A[0] < 4294967294ULL && A[0] > -2147483648L)) && A[0] > -82984055 && A[0] > -1 && ((A[0] < 2147483646LL) && A[0] < 2147483646LL) && A[0] < 2147483646UL) && (((A[0] > -2147483647L))) && A[0] < 2147483646 && A[0] < 100000) && A[0] < 1LL && A[0] < ~(2147483648U) && (A[0] >= 1U || A[0] != 2147483647ULL)) && A[0] < 2147483646U && A[0] < 2147483647L) && (A[0] < 4294967294UL && A[0] < 2147483646U && ((A[0] < ~(4294967295U))) && A[0] <= ~(0)) && ((((A[0] < 2147483646ULL && A[0] > -1 && A[0] < ~(2147483648U) && A[0] < 0UL) && A[0] > -2147483647L && A[0] > ~(-1)) && A[0] < 1U && A[0] <= ~(4294967294U)) && A[0] > ~(4294967295U)) && A[0] < 0) && (((A[0] > -390958390)) && (A[0] < 0UL) && (A[0] < ~(2147483648U)) && A[0] <= 4294967294UL) && A[0] >= 0ULL));
11+
/* clang-format on */
12+
return 0;
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
4+
^\[main.assertion.1\] line 10 assertion: FAILURE$
5+
^VERIFICATION FAILED$
6+
^EXIT=10$
7+
^SIGNAL=0$
8+
--
9+
^warning: ignoring
10+
--
11+
This test verifies that CBMC correctly reports line numbers for assertions in
12+
very long expressions.

src/ansi-c/scanner.l

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ enable_or_disable ("enable"|"disable")
333333
<STRING_LITERAL>{whitespace} { /* ignore */ }
334334
<STRING_LITERAL>{cpplineno} {
335335
preprocessor_line(yytext, PARSER);
336-
PARSER.set_line_no(PARSER.get_line_no()-1);
336+
// Line number already set by preprocessor_line
337337
}
338338
<STRING_LITERAL>{cppstart}.* { /* ignore */ }
339339
<STRING_LITERAL>"/*" { yy_push_state(STRING_LITERAL_COMMENT); /* C comment, ignore */ }
@@ -352,7 +352,7 @@ enable_or_disable ("enable"|"disable")
352352

353353
<GRAMMAR>{cpplineno} {
354354
preprocessor_line(yytext, PARSER);
355-
PARSER.set_line_no(PARSER.get_line_no()-1);
355+
// Line number already set by preprocessor_line
356356
}
357357

358358
<GRAMMAR>{cppstart}"pragma"{ws}"pack"{ws}"("{ws}"push"{ws}")"{ws}{newline} {
@@ -1620,7 +1620,7 @@ enable_or_disable ("enable"|"disable")
16201620
<GCC_ASM>{
16211621
{cpplineno} {
16221622
preprocessor_line(yytext, PARSER);
1623-
PARSER.set_line_no(PARSER.get_line_no()-1);
1623+
// Line number already set by preprocessor_line
16241624
}
16251625
{ws} { /* ignore */ }
16261626
{newline} { /* ignore */ }
@@ -1639,7 +1639,7 @@ enable_or_disable ("enable"|"disable")
16391639
<GCC_ATTRIBUTE1>{
16401640
{cpplineno} {
16411641
preprocessor_line(yytext, PARSER);
1642-
PARSER.set_line_no(PARSER.get_line_no()-1);
1642+
// Line number already set by preprocessor_line
16431643
}
16441644
{ws} { /* ignore */ }
16451645
{newline} { /* ignore */ }
@@ -1650,7 +1650,7 @@ enable_or_disable ("enable"|"disable")
16501650
<GCC_ATTRIBUTE1a>{
16511651
{cpplineno} {
16521652
preprocessor_line(yytext, PARSER);
1653-
PARSER.set_line_no(PARSER.get_line_no()-1);
1653+
// Line number already set by preprocessor_line
16541654
}
16551655
"(" { BEGIN(GCC_ATTRIBUTE2); PARSER.parenthesis_counter=0; return yytext[0]; }
16561656
{ws} { /* ignore */ }
@@ -1711,7 +1711,7 @@ enable_or_disable ("enable"|"disable")
17111711
<GCC_ATTRIBUTE3>{ // an attribute we do process
17121712
{cpplineno} {
17131713
preprocessor_line(yytext, PARSER);
1714-
PARSER.set_line_no(PARSER.get_line_no()-1);
1714+
// Line number already set by preprocessor_line
17151715
}
17161716
"(" { PARSER.parenthesis_counter++; loc(); return '('; }
17171717
")" { if(PARSER.parenthesis_counter==0)
@@ -1774,7 +1774,7 @@ enable_or_disable ("enable"|"disable")
17741774
<GCC_ATTRIBUTE5>{ // end bit: the closing parenthesis
17751775
{cpplineno} {
17761776
preprocessor_line(yytext, PARSER);
1777-
PARSER.set_line_no(PARSER.get_line_no()-1);
1777+
// Line number already set by preprocessor_line
17781778
}
17791779
")" { BEGIN(GRAMMAR); loc(); return yytext[0]; }
17801780
{ws} { /* Throw away */ }

0 commit comments

Comments
 (0)