| Issue |
243136
|
| Summary |
clang -E output vs POSIX
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
Boobies
|
While clang supports the `-M` family of options, the portable mechanism for automatic dependency generation that POSIX prescribes is the use of the compiler option `-E`. The rationale for the `c17` utility in POSIX.1-2024 states:
```
This standard requires that, when -E is used, lines beginning with '#' are output identifying the files processed as a result of #include directives in order that c17 -E can be used to generate makefile dependencies. See make. Usually such lines are output each time the origin of the subsequent lines in the output changes, and the line number after the '#' is the line number in the named file of the line from which the next line in the output was derived.
```
The description of the `make` utility also gives an example of how to use regular expressions to parse the output.
The relevant wording of for `-E` in POSIX (with two accepted corrections applied) is as follows[1][2][3]:
```
If the -E option is specified, the standard output shall be a text file that represents the results of the preprocessing stage of the language; it may contain extra information appropriate for subsequent compilation passes and shall contain at least one line with the format:
"# %d \"%s\"\n", <line>, <pathname>
or
"# %d \"%s\" %s\n", <line>, <pathname>, <flags>
for each file processed as a result of a #include directive, where line is a line number, pathname is the pathname used to open the file, and flags is an implementation-defined string.
```
Given the following C program:
```c
int main()
{
}
```
clang's `-E` generates:
```
# 1 "test.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 416 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "test.c" 2
int main()
{
}
```
Although not spelled out in the standard, the intention here is that the first value (i.e., the line number) should be used differentiate between real header files (such as `<stdio.h>`) and the compiler's internal ones (such as `<built-in>`), as it is impossible for the fictitious headers to appear on line 0 of a preprpocessed file. Currently, clang does not do this; the example above shows the use of line numbers 1 and 416, making parsing the actual included headers difficult. Instead, it would be desirable for the line number to be 0 in all these cases. If there is some valuable information encoded in those values (e.g., I see line number 416), that could be instead moved to a flag at the end.
In contrast, here is GCC's output for the same program:
```
# 0 "test.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3
# 0 "<command-line>" 2
# 1 "test.c"
int main()
{
}
```
[1] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/c17.html
[2] https://www.austingroupbugs.net/view.php?id=1925
[3] https://www.austingroupbugs.net/view.php?id=2001
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs