Skip to content

Commit 618af82

Browse files
committed
Do not create locations with a set-but-empty function
The C front-end created symbols that had the function set to an empty string. This was not accurately represented in the JSON representation, but also shouldn't be used at all. Thus, changing the parser rather than the JSON serialisation.
1 parent 06a88d6 commit 618af82

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

src/ansi-c/c_preprocess.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static void error_parse_line(
127127
if(state==2)
128128
{
129129
saved_error_location.set_file(file);
130-
saved_error_location.set_function(irep_idt());
130+
saved_error_location.clear_function();
131131
saved_error_location.set_line(line_no);
132132
saved_error_location.set_column(irep_idt());
133133
}

src/ansi-c/parser.y

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,7 +3026,7 @@ function_definition:
30263026
PARSER.pop_scope();
30273027

30283028
// We are no longer in any function.
3029-
PARSER.set_function(irep_idt());
3029+
PARSER.clear_function();
30303030
}
30313031
;
30323032

@@ -3589,7 +3589,7 @@ parameter_postfixing_abstract_declarator:
35893589
// Clear function name in source location after parsing if
35903590
// at global scope.
35913591
if (PARSER.current_scope().prefix.empty()) {
3592-
PARSER.set_function(irep_idt());
3592+
PARSER.clear_function();
35933593
}
35943594

35953595
$$ = merge($4, $1);
@@ -3621,7 +3621,7 @@ parameter_postfixing_abstract_declarator:
36213621
// Clear function name in source location after parsing if
36223622
// at global scope.
36233623
if (PARSER.current_scope().prefix.empty()) {
3624-
PARSER.set_function(irep_idt());
3624+
PARSER.clear_function();
36253625
}
36263626

36273627
if(parser_stack($5).is_not_nil())

src/util/parser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ class parsert
135135
_source_location.set_function(function);
136136
}
137137

138+
void clear_function()
139+
{
140+
_source_location.clear_function();
141+
}
142+
138143
void advance_column(unsigned token_width)
139144
{
140145
column+=token_width;

src/util/source_location.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,15 @@ class source_locationt:public irept
134134
DEPRECATED(SINCE(2022, 10, 13, "use identifier of containing function"))
135135
void set_function(const irep_idt &function)
136136
{
137+
PRECONDITION(!function.empty());
137138
set(ID_function, function);
138139
}
139140

141+
void clear_function()
142+
{
143+
remove(ID_function);
144+
}
145+
140146
void set_property_id(const irep_idt &property_id)
141147
{
142148
set(ID_property_id, property_id);

0 commit comments

Comments
 (0)